Collection of guard functions to pass TypeScript checks.
import { :util } from 'mauss/guards';
A guard for exhaustive checks with if
/else
/switch
statements, this will help branching logic in consuming enumeration and union types.
import { bulwark } from 'mauss/guards';
let key = 'a' as 'a' | 'z';
switch (key) {
case 'a':
return key.charCodeAt();
default:
// Argument of type 'string' is not assignable to parameter of type 'never'.
return bulwark(key);
}
A guard that returns true
if the input is not nullish or an empty string.
A guard that returns true
if the input is null
or undefined
.
A guard that returns true
if the input is truthy in general.
A number guard that returns true
if the input exists or is a number greater than 0.
A number guard that returns true
if the input exists or is a number greater than or equal to 0.
A utility guard that takes in any guards above and negates the result. For example,
not(exists)
will returntrue
if the input is nullish or an empty stringnot(natural)
will returntrue
if the input exists or is a number less than or equal to 0.
A string guard that returns true
if the input is a string with all lowercase characters.
A string guard that returns true
if the input is a string with all uppercase characters.