Skip to content

Instantly share code, notes, and snippets.

@develohpanda
Created June 7, 2023 00:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save develohpanda/6dbc4d22a932536a06d15d56e6ccfeaf to your computer and use it in GitHub Desktop.
Save develohpanda/6dbc4d22a932536a06d15d56e6ccfeaf to your computer and use it in GitHub Desktop.
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