UNPKG

foxts

Version:

Opinionated collection of common TypeScript utils by @SukkaW

1 lines 930 B
const n=n=>null!==n,r=n=>void 0!==n,e=n=>!1!==n,u=n=>null!=n,t=n=>!!n;function l(l){switch(l){case null:return n;case void 0:return r;case!1:return e;case"nullish":return u;case"falsy":return t;default:x(l,"argument")}}const s=n=>null===n,i=n=>void 0===n,o=n=>!1===n,a=n=>null==n,c=n=>!n,f=n=>!!n;function d(n){switch(n){case null:return s;case void 0:return i;case!1:return o;case"nullish":return a;case"falsy":return c;case"truthy":return f;default:x(n,"argument")}}const h=f,v=c,y=n,p=u;function w(n,r='[foxts/invariant] "value" is null or undefined'){if(null==n)throw TypeError(r);return n}function N(n,r='[foxts/invariant] "value" is null or undefined'){if(null==n)throw TypeError(r)}function x(n,r="value"){throw TypeError(`Unexpected ${r}: ${n} as ${JSON.stringify(typeof n)}, should be "never"`)}export{N as invariant,d as is,v as isFalsy,y as isNonNull,p as isNonNullish,h as isTruthy,x as never,l as not,w as nullthrow};