Created
June 7, 2023 00:42
-
-
Save develohpanda/6dbc4d22a932536a06d15d56e6ccfeaf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isNotNullOrUndefined<ValueType>( | |
value: ValueType | null | undefined | |
): value is ValueType { | |
if (value === null || value === undefined) { | |
return false; | |
} | |
return true; | |
} | |
const triStateBooleanAnd = (...params: (boolean | undefined)[]) => { | |
const filtered = params.filter(isNotNullOrUndefined); | |
if (filtered.length) { | |
return filtered.every(Boolean); | |
} else { | |
return undefined; | |
} | |
}; | |
const triStateBooleanOr = (...params: (boolean | undefined)[]) => { | |
const filtered = params.filter(isNotNullOrUndefined); | |
if (filtered.length) { | |
return filtered.some(Boolean); | |
} else { | |
return undefined; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment