@tool-belt/type-predicates
Version:
A comprehensive collection of performant type guards and assertions with excellent TypeScript support
3 lines (2 loc) • 13.6 kB
JavaScript
;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=r=>Object.prototype.toString.call(r);function t(r,e){return e?s=>r(s,e):s=>r(s)}function g(...r){return function(e){for(const s of r)if(s(e))return!0;return!1}}const n=t(r=>typeof r=="object"&&r!==null),u=t(r=>n(r)&&(o(r)==="[object ArrayBuffer]"||r instanceof ArrayBuffer)),w=t(r=>n(r)&&(o(r)==="[object SharedArrayBuffer]"||r instanceof SharedArrayBuffer)),j=g(u,w);function jr(r,e){if(!j(r))throw new TypeError(e?.message)}const S=t(r=>typeof r=="object"&&r!==null&&Object.prototype.toString.call(r)==="[object Arguments]");function Sr(r,e){if(!S(r))throw new TypeError(e?.message)}function dr(r,e){if(!Array.isArray(r))throw new TypeError(e?.message);if(e?.valueValidator&&!r.every(e.valueValidator))throw new TypeError(e.message)}function Or(r,e){if(!u(r))throw new TypeError(e?.message)}const i=t(r=>r instanceof Object.getPrototypeOf(Int8Array)||r instanceof Object.getPrototypeOf(Uint8Array)),d=r=>t(e=>i(e)&&e[Symbol.toStringTag]==="Int8Array")(r),O=r=>t(e=>i(e)&&e[Symbol.toStringTag]==="Uint8Array")(r),N=r=>t(e=>i(e)&&e[Symbol.toStringTag]==="Uint8ClampedArray")(r),B=r=>t(e=>i(e)&&e[Symbol.toStringTag]==="Int16Array")(r),F=r=>t(e=>i(e)&&e[Symbol.toStringTag]==="Uint16Array")(r),V=r=>t(e=>i(e)&&e[Symbol.toStringTag]==="Int32Array")(r),U=r=>t(e=>i(e)&&e[Symbol.toStringTag]==="Uint32Array")(r),k=r=>t(e=>i(e)&&e[Symbol.toStringTag]==="Float32Array")(r),G=r=>t(e=>i(e)&&e[Symbol.toStringTag]==="Float64Array")(r),P=r=>t(e=>i(e)&&e[Symbol.toStringTag]==="BigInt64Array")(r),M=r=>t(e=>i(e)&&e[Symbol.toStringTag]==="BigUint64Array")(r),m=t(r=>n(r)&&(o(r)==="[object DataView]"||r instanceof DataView)),R=t(r=>i(r)||m(r));function Nr(r,e){if(!R(r))throw new TypeError(e?.message)}function D(r){return t(e=>typeof e=="function"&&o(e)==="[object AsyncFunction]")(r)}function Br(r,e){if(!D(r))throw new TypeError(e?.message)}function x(r){return t(e=>n(e)&&o(e)==="[object AsyncGenerator]")(r)}function Fr(r,e){if(!x(r))throw new TypeError(e?.message)}function W(r){return t(e=>typeof e=="function"&&o(e)==="[object AsyncGeneratorFunction]")(r)}function Vr(r,e){if(!W(r))throw new TypeError(e?.message)}function C(r){return t(e=>n(e)&&typeof Reflect.get(e,Symbol.asyncIterator)=="function")(r)}function Ur(r,e){if(!C(r))throw new TypeError(e?.message)}const q=t(r=>typeof r=="bigint");function kr(r,e){if(!q(r))throw new TypeError(e?.message)}const p=t(r=>typeof r=="object"&&r!==null&&Object.prototype.toString.call(r)==="[object BigInt]");function Gr(r,e){if(!p(r))throw new TypeError(e?.message)}const z=t(r=>typeof r=="boolean");function Pr(r,e){if(!z(r))throw new TypeError(e?.message)}const b=t(r=>n(r)&&o(r)==="[object Boolean]"&&typeof r.valueOf()=="boolean");function Mr(r,e){if(!b(r))throw new TypeError(e?.message)}const A=t(r=>n(r)&&o(r)==="[object Number]"&&typeof r.valueOf()=="number"),E=t(r=>n(r)&&o(r)==="[object String]"&&typeof r.valueOf()=="string"),l=t(r=>typeof r=="object"&&r!==null&&Object.prototype.toString.call(r)==="[object Symbol]"),H=t(r=>b(r)||A(r)||E(r)||p(r)||l(r));function Rr(r,e){if(!H(r))throw new TypeError(e?.message)}const J=t(r=>typeof Buffer<"u"&&r instanceof Buffer);function Dr(r,e){if(!J(r))throw new TypeError(e?.message)}function xr(r,e){if(!m(r))throw new TypeError(e?.message)}const K=t(r=>n(r)&&(o(r)==="[object Date]"||r instanceof Date));function Wr(r,e){if(!K(r))throw new TypeError(e?.message)}const f=t(r=>r===void 0);function Cr(r,e){if(f(r))throw new TypeError(e?.message)}function h(r,e){return t(s=>Array.isArray(s)&&(!e?.valueValidator||s.every(e.valueValidator)))(r)}const L=t(r=>h(r)&&r.length===0);function qr(r,e){if(!L(r))throw new TypeError(e?.message)}const Q=t(r=>n(r)&&!Array.isArray(r)&&Object.keys(r).length===0);function zr(r,e){if(!Q(r))throw new TypeError(e?.message)}const c=t(r=>typeof r=="string"),X=t(r=>c(r)&&r.length===0);function Hr(r,e){if(!X(r))throw new TypeError(e?.message)}function Y(r){return t(e=>n(e)&&(o(e)==="[object Error]"||e instanceof Error))(r)}function Jr(r,e){if(!Y(r))throw new TypeError(e?.message)}const Z=t(r=>typeof r=="number"&&Number.isFinite(r));function Kr(r,e){if(!Z(r))throw new TypeError(e?.message)}function _(r){return t(e=>typeof e=="function"&&o(e)==="[object Function]")(r)}function Lr(r,e){if(!_(r))throw new TypeError(e?.message)}function $(r){return t(e=>n(e)&&o(e)==="[object Generator]")(r)}function Qr(r,e){if(!$(r))throw new TypeError(e?.message)}function v(r){return t(e=>typeof e=="function"&&o(e)==="[object GeneratorFunction]")(r)}function Xr(r,e){if(!v(r))throw new TypeError(e?.message)}const rr=t(r=>typeof r=="number"&&Number.isInteger(r));function Yr(r,e){if(!rr(r))throw new TypeError(e?.message)}function er(r){return t(e=>n(e)&&typeof Reflect.get(e,Symbol.iterator)=="function"||c(e))(r)}function Zr(r,e){if(!er(r))throw new TypeError(e?.message)}function tr(r){return t(e=>n(e)&&typeof Reflect.get(e,"next")=="function")(r)}function _r(r,e){if(!tr(r))throw new TypeError(e?.message)}function sr(r,e){return t(s=>{if(!(s instanceof Map)&&(!n(s)||o(s)!=="[object Map]"))return!1;const I=s;if(e?.valueValidator){for(const a of I.values())if(!e.valueValidator(a))return!1}if(e?.keyValidator){for(const a of I.keys())if(!e.keyValidator(a))return!1}return!0})(r)}function $r(r,e){if(!sr(r))throw new TypeError(e?.message);if(e?.keyValidator&&![...r.keys()].every(e.keyValidator))throw new TypeError(e.message);if(e?.valueValidator&&![...r.values()].every(e.valueValidator))throw new TypeError(e.message)}const nr=t(r=>typeof r=="object"&&r!==null&&Object.prototype.toString.call(r)==="[object Map Iterator]");function vr(r,e){if(!nr(r))throw new TypeError(e?.message)}const or=t(r=>typeof r=="number"&&Number.isNaN(r));function re(r,e){if(!or(r))throw new TypeError(e?.message)}const ir=t(r=>r instanceof Error||r instanceof EvalError||r instanceof RangeError||r instanceof ReferenceError||r instanceof SyntaxError||r instanceof TypeError||r instanceof URIError||typeof AggregateError<"u"&&r instanceof AggregateError);function ee(r,e){if(!ir(r))throw new TypeError(e?.message)}const ar=t(r=>h(r)&&r.length>0);function te(r,e){if(!ar(r))throw new TypeError(e?.message)}const fr=t(r=>c(r)&&r.length>0);function se(r,e){if(!fr(r))throw new TypeError(e?.message)}const y=t(r=>r===null);function ne(r,e){if(y(r))throw new TypeError(e?.message)}function oe(r,e){if(f(r)||y(r))throw new TypeError(e?.message)}function ie(r,e){if(!y(r))throw new TypeError(e?.message)}const cr=g(y,f);function ae(r,e){if(!cr(r))throw new TypeError(e?.message)}const yr=t(r=>typeof r=="number");function fe(r,e){if(!yr(r))throw new TypeError(e?.message)}function ce(r,e){if(!A(r))throw new TypeError(e?.message)}function ye(r,e){if(!n(r))throw new TypeError(e?.message)}function T(r){try{return Object.getPrototypeOf(r)}catch{return null}}const Ir=t(r=>{if(r===null||typeof r!="object")return!1;const e=T(r);return e===null||e===Object.prototype?!0:T(e)===null});function Ie(r,e){if(!Ir(r))throw new TypeError(e?.message)}function gr(r){return t(e=>e instanceof Promise||n(e)&&typeof Reflect.get(e,"then")=="function")(r)}function ge(r,e){if(!gr(r))throw new TypeError(e?.message)}function ur(r,e){return t(s=>n(s)&&o(s)==="[object Object]"&&(!e?.valueValidator||Object.values(s).every(e.valueValidator))&&(!e?.keyValidator||Object.keys(s).every(e.keyValidator)))(r)}function ue(r,e){if(!ur(r))throw new TypeError(e?.message);if(e?.keyValidator&&!Object.keys(r).every(e.keyValidator))throw new TypeError(e.message);if(e?.valueValidator&&!Object.values(r).every(e.valueValidator))throw new TypeError(e.message)}const wr=t(r=>n(r)&&(o(r)==="[object RegExp]"||r instanceof RegExp));function we(r,e){if(!wr(r))throw new TypeError(e?.message)}const mr=t(r=>typeof r=="number"&&Number.isSafeInteger(r));function me(r,e){if(!mr(r))throw new TypeError(e?.message)}function pr(r,e){return t(s=>{if(!n(s)||o(s)!=="[object Set]"&&!(s instanceof Set))return!1;const I=s;if(e?.valueValidator){for(const a of I)if(!e.valueValidator(a))return!1}return!0})(r)}function pe(r,e){if(!pr(r))throw new TypeError(e?.message);if(e?.valueValidator&&![...r].every(e.valueValidator))throw new TypeError(e.message)}const br=t(r=>typeof r=="object"&&r!==null&&Object.prototype.toString.call(r)==="[object Set Iterator]");function be(r,e){if(!br(r))throw new TypeError(e?.message)}function Ae(r,e){if(!w(r))throw new TypeError(e?.message)}function Ee(r,e){if(!c(r))throw new TypeError(e?.message)}function le(r,e){if(!E(r))throw new TypeError(e?.message)}const Ar=t(r=>typeof r=="symbol");function he(r,e){if(!Ar(r))throw new TypeError(e?.message)}function Te(r,e){if(!l(r))throw new TypeError(e?.message)}function je(r,e){if(!P(r))throw new TypeError(e?.message)}function Se(r,e){if(!M(r))throw new TypeError(e?.message)}function de(r,e){if(!k(r))throw new TypeError(e?.message)}function Oe(r,e){if(!G(r))throw new TypeError(e?.message)}function Ne(r,e){if(!B(r))throw new TypeError(e?.message)}function Be(r,e){if(!V(r))throw new TypeError(e?.message)}function Fe(r,e){if(!d(r))throw new TypeError(e?.message)}function Ve(r,e){if(!i(r))throw new TypeError(e?.message)}function Ue(r,e){if(!F(r))throw new TypeError(e?.message)}function ke(r,e){if(!U(r))throw new TypeError(e?.message)}function Ge(r,e){if(!O(r))throw new TypeError(e?.message)}function Pe(r,e){if(!N(r))throw new TypeError(e?.message)}function Me(r,e){if(!f(r))throw new TypeError(e?.message)}function Er(r){return t(e=>e instanceof WeakMap||n(e)&&o(e)==="[object WeakMap]")(r)}function Re(r,e){if(!Er(r))throw new TypeError(e?.message)}function lr(r){return t(e=>e instanceof WeakSet||n(e)&&o(e)==="[object WeakSet]")(r)}function De(r,e){if(!lr(r))throw new TypeError(e?.message)}function hr(r){return r!==void 0}function Tr(r){return r!==null}function xe(r){return hr(r)&&Tr(r)}exports.assertIsAnyArrayBuffer=jr;exports.assertIsArgumentsObject=Sr;exports.assertIsArray=dr;exports.assertIsArrayBuffer=Or;exports.assertIsArrayBufferView=Nr;exports.assertIsAsyncFunction=Br;exports.assertIsAsyncGenerator=Fr;exports.assertIsAsyncGeneratorFunction=Vr;exports.assertIsAsyncIterable=Ur;exports.assertIsBigInt=kr;exports.assertIsBigInt64Array=je;exports.assertIsBigIntObject=Gr;exports.assertIsBigUint64Array=Se;exports.assertIsBoolean=Pr;exports.assertIsBooleanObject=Mr;exports.assertIsBoxedPrimitive=Rr;exports.assertIsBuffer=Dr;exports.assertIsDataView=xr;exports.assertIsDate=Wr;exports.assertIsDefined=Cr;exports.assertIsEmptyArray=qr;exports.assertIsEmptyObject=zr;exports.assertIsEmptyString=Hr;exports.assertIsError=Jr;exports.assertIsFinite=Kr;exports.assertIsFloat32Array=de;exports.assertIsFloat64Array=Oe;exports.assertIsFunction=Lr;exports.assertIsGenerator=Qr;exports.assertIsGeneratorFunction=Xr;exports.assertIsInt16Array=Ne;exports.assertIsInt32Array=Be;exports.assertIsInt8Array=Fe;exports.assertIsInteger=Yr;exports.assertIsIterable=Zr;exports.assertIsIterator=_r;exports.assertIsMap=$r;exports.assertIsMapIterator=vr;exports.assertIsNaN=re;exports.assertIsNativeError=ee;exports.assertIsNonEmptyArray=te;exports.assertIsNonEmptyString=se;exports.assertIsNotNull=ne;exports.assertIsNotNullish=oe;exports.assertIsNull=ie;exports.assertIsNullish=ae;exports.assertIsNumber=fe;exports.assertIsNumberObject=ce;exports.assertIsObject=ye;exports.assertIsPlainObject=Ie;exports.assertIsPromise=ge;exports.assertIsRecord=ue;exports.assertIsRegExp=we;exports.assertIsSafeInteger=me;exports.assertIsSet=pe;exports.assertIsSetIterator=be;exports.assertIsSharedArrayBuffer=Ae;exports.assertIsString=Ee;exports.assertIsStringObject=le;exports.assertIsSymbol=he;exports.assertIsSymbolObject=Te;exports.assertIsTypedArray=Ve;exports.assertIsUint16Array=Ue;exports.assertIsUint32Array=ke;exports.assertIsUint8Array=Ge;exports.assertIsUint8ClampedArray=Pe;exports.assertIsUndefined=Me;exports.assertIsWeakMap=Re;exports.assertIsWeakSet=De;exports.createTypeGuard=t;exports.isAnyArrayBuffer=j;exports.isArgumentsObject=S;exports.isArray=h;exports.isArrayBuffer=u;exports.isArrayBufferView=R;exports.isAsyncFunction=D;exports.isAsyncGenerator=x;exports.isAsyncGeneratorFunction=W;exports.isAsyncIterable=C;exports.isBigInt=q;exports.isBigInt64Array=P;exports.isBigIntObject=p;exports.isBigUint64Array=M;exports.isBoolean=z;exports.isBooleanObject=b;exports.isBoxedPrimitive=H;exports.isBuffer=J;exports.isDataView=m;exports.isDate=K;exports.isDefined=hr;exports.isEmptyArray=L;exports.isEmptyObject=Q;exports.isEmptyString=X;exports.isError=Y;exports.isFinite=Z;exports.isFloat32Array=k;exports.isFloat64Array=G;exports.isFunction=_;exports.isGenerator=$;exports.isGeneratorFunction=v;exports.isInt16Array=B;exports.isInt32Array=V;exports.isInt8Array=d;exports.isInteger=rr;exports.isIterable=er;exports.isIterator=tr;exports.isMap=sr;exports.isMapIterator=nr;exports.isNaN=or;exports.isNativeError=ir;exports.isNonEmptyArray=ar;exports.isNonEmptyString=fr;exports.isNotNull=Tr;exports.isNotNullish=xe;exports.isNull=y;exports.isNullish=cr;exports.isNumber=yr;exports.isNumberObject=A;exports.isObject=n;exports.isPlainObject=Ir;exports.isPromise=gr;exports.isRecord=ur;exports.isRegExp=wr;exports.isSafeInteger=mr;exports.isSet=pr;exports.isSetIterator=br;exports.isSharedArrayBuffer=w;exports.isString=c;exports.isStringObject=E;exports.isSymbol=Ar;exports.isSymbolObject=l;exports.isTypedArray=i;exports.isUint16Array=F;exports.isUint32Array=U;exports.isUint8Array=O;exports.isUint8ClampedArray=N;exports.isUndefined=f;exports.isUnion=g;exports.isWeakMap=Er;exports.isWeakSet=lr;
//# sourceMappingURL=index.js.map