Comparing version 0.3.3 to 0.3.4
@@ -116,3 +116,3 @@ 'use strict'; | ||
const typa = (check, value, fn1, fn2) => { | ||
if (!!check && value && !!fn1 && !!fn2) return is[check](value) ? fn1() : fn2(); | ||
if (!!check && value && !!fn1 && !!fn2) return is[check](value) ? fn(fn1) ? fn1() : fn1 : fn(fn2) ? fn2() : fn2; | ||
throw new Error('typa(): Invalid input'); | ||
@@ -119,0 +119,0 @@ }; // return type(s) of $value |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const arr=n=>"object"==typeof n&&n.constructor===Array,bad=n=>nil(n)||undef(n)||nullish(n)||empty(n)||err(n),bool=n=>"boolean"==typeof n,empty=n=>str(n)&&0===n.length||arr(n)&&0===n.length||obj(n)&&0===Object.keys(n).length,date=n=>n instanceof Date,err=n=>n instanceof Error,json=(n,e)=>{if(!n)return!1;try{switch(e){case"obj":JSON.stringify(n);break;case"str":default:JSON.parse(n)}return!0}catch(n){return!1}},fn=n=>"function"==typeof n,int=n=>"number"==typeof n&&isFinite(n)&&Number.isInteger(n),nil=n=>null===n,nullish=n=>null==n||null==n,num=n=>"number"==typeof n&&isFinite(n),obj=n=>"object"==typeof n&&n.constructor===Object,prom=n=>n instanceof Promise,regex=n=>"object"==typeof n&&n.constructor===RegExp,str=n=>"string"==typeof n||n instanceof String,sym=n=>"symbol"==typeof n,undef=n=>void 0===n||void 0===n,typa=(n,e,t,r)=>{if(n&&e&&t&&r)return is[n](e)?t():r();throw new Error("typa(): Invalid input")},what=n=>{let e=[];const t=[{fn:"arr",name:"array"},{fn:"bool",name:"boolean"},{fn:"date",name:"date"},{fn:"err",name:"error"},{fn:"fn",name:"function"},{fn:"int",name:"integer"},{fn:"json",name:"json"},{fn:"num",name:"number"},{fn:"obj",name:"object"},{fn:"prom",name:"promise"},{fn:"regex",name:"regexp"},{fn:"str",name:"string"},{fn:"sym",name:"symbol"}];return[{fn:"undef",name:"undefined"},{fn:"nil",name:"null"}].forEach(t=>{is[t.fn](n)&&e.push(t.name)}),e.length||t.forEach(t=>{is[t.fn](n)&&e.push(t.name)}),1===e.length?e[0]:e},is={arr:arr,bad:bad,bool:bool,date:date,empty:empty,err:err,fn:fn,int:int,json:json,nil:nil,nullish:nullish,num:num,obj:obj,prom:prom,regex:regex,str:str,sym:sym,typa:typa,undef:undef,what:what};exports.default=is; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const arr=n=>"object"==typeof n&&n.constructor===Array,bad=n=>nil(n)||undef(n)||nullish(n)||empty(n)||err(n),bool=n=>"boolean"==typeof n,empty=n=>str(n)&&0===n.length||arr(n)&&0===n.length||obj(n)&&0===Object.keys(n).length,date=n=>n instanceof Date,err=n=>n instanceof Error,json=(n,e)=>{if(!n)return!1;try{switch(e){case"obj":JSON.stringify(n);break;case"str":default:JSON.parse(n)}return!0}catch(n){return!1}},fn=n=>"function"==typeof n,int=n=>"number"==typeof n&&isFinite(n)&&Number.isInteger(n),nil=n=>null===n,nullish=n=>null==n||null==n,num=n=>"number"==typeof n&&isFinite(n),obj=n=>"object"==typeof n&&n.constructor===Object,prom=n=>n instanceof Promise,regex=n=>"object"==typeof n&&n.constructor===RegExp,str=n=>"string"==typeof n||n instanceof String,sym=n=>"symbol"==typeof n,undef=n=>void 0===n||void 0===n,typa=(n,e,t,r)=>{if(n&&e&&t&&r)return is[n](e)?fn(t)?t():t:fn(r)?r():r;throw new Error("typa(): Invalid input")},what=n=>{let e=[];const t=[{fn:"arr",name:"array"},{fn:"bool",name:"boolean"},{fn:"date",name:"date"},{fn:"err",name:"error"},{fn:"fn",name:"function"},{fn:"int",name:"integer"},{fn:"json",name:"json"},{fn:"num",name:"number"},{fn:"obj",name:"object"},{fn:"prom",name:"promise"},{fn:"regex",name:"regexp"},{fn:"str",name:"string"},{fn:"sym",name:"symbol"}];return[{fn:"undef",name:"undefined"},{fn:"nil",name:"null"}].forEach(t=>{is[t.fn](n)&&e.push(t.name)}),e.length||t.forEach(t=>{is[t.fn](n)&&e.push(t.name)}),1===e.length?e[0]:e},is={arr:arr,bad:bad,bool:bool,date:date,empty:empty,err:err,fn:fn,int:int,json:json,nil:nil,nullish:nullish,num:num,obj:obj,prom:prom,regex:regex,str:str,sym:sym,typa:typa,undef:undef,what:what};exports.default=is; | ||
//# sourceMappingURL=index.min.js.map |
@@ -112,3 +112,3 @@ // array | ||
const typa = (check, value, fn1, fn2) => { | ||
if (!!check && value && !!fn1 && !!fn2) return is[check](value) ? fn1() : fn2(); | ||
if (!!check && value && !!fn1 && !!fn2) return is[check](value) ? fn(fn1) ? fn1() : fn1 : fn(fn2) ? fn2() : fn2; | ||
throw new Error('typa(): Invalid input'); | ||
@@ -115,0 +115,0 @@ }; // return type(s) of $value |
@@ -1,2 +0,2 @@ | ||
const arr=n=>"object"==typeof n&&n.constructor===Array,bad=n=>nil(n)||undef(n)||nullish(n)||empty(n)||err(n),bool=n=>"boolean"==typeof n,empty=n=>str(n)&&0===n.length||arr(n)&&0===n.length||obj(n)&&0===Object.keys(n).length,date=n=>n instanceof Date,err=n=>n instanceof Error,json=(n,e)=>{if(!n)return!1;try{switch(e){case"obj":JSON.stringify(n);break;case"str":default:JSON.parse(n)}return!0}catch(n){return!1}},fn=n=>"function"==typeof n,int=n=>"number"==typeof n&&isFinite(n)&&Number.isInteger(n),nil=n=>null===n,nullish=n=>null==n||null==n,num=n=>"number"==typeof n&&isFinite(n),obj=n=>"object"==typeof n&&n.constructor===Object,prom=n=>n instanceof Promise,regex=n=>"object"==typeof n&&n.constructor===RegExp,str=n=>"string"==typeof n||n instanceof String,sym=n=>"symbol"==typeof n,undef=n=>void 0===n||void 0===n,typa=(n,e,r,t)=>{if(n&&e&&r&&t)return is[n](e)?r():t();throw new Error("typa(): Invalid input")},what=n=>{let e=[];const r=[{fn:"arr",name:"array"},{fn:"bool",name:"boolean"},{fn:"date",name:"date"},{fn:"err",name:"error"},{fn:"fn",name:"function"},{fn:"int",name:"integer"},{fn:"json",name:"json"},{fn:"num",name:"number"},{fn:"obj",name:"object"},{fn:"prom",name:"promise"},{fn:"regex",name:"regexp"},{fn:"str",name:"string"},{fn:"sym",name:"symbol"}];return[{fn:"undef",name:"undefined"},{fn:"nil",name:"null"}].forEach(r=>{is[r.fn](n)&&e.push(r.name)}),e.length||r.forEach(r=>{is[r.fn](n)&&e.push(r.name)}),1===e.length?e[0]:e},is={arr:arr,bad:bad,bool:bool,date:date,empty:empty,err:err,fn:fn,int:int,json:json,nil:nil,nullish:nullish,num:num,obj:obj,prom:prom,regex:regex,str:str,sym:sym,typa:typa,undef:undef,what:what};export default is; | ||
const arr=n=>"object"==typeof n&&n.constructor===Array,bad=n=>nil(n)||undef(n)||nullish(n)||empty(n)||err(n),bool=n=>"boolean"==typeof n,empty=n=>str(n)&&0===n.length||arr(n)&&0===n.length||obj(n)&&0===Object.keys(n).length,date=n=>n instanceof Date,err=n=>n instanceof Error,json=(n,e)=>{if(!n)return!1;try{switch(e){case"obj":JSON.stringify(n);break;case"str":default:JSON.parse(n)}return!0}catch(n){return!1}},fn=n=>"function"==typeof n,int=n=>"number"==typeof n&&isFinite(n)&&Number.isInteger(n),nil=n=>null===n,nullish=n=>null==n||null==n,num=n=>"number"==typeof n&&isFinite(n),obj=n=>"object"==typeof n&&n.constructor===Object,prom=n=>n instanceof Promise,regex=n=>"object"==typeof n&&n.constructor===RegExp,str=n=>"string"==typeof n||n instanceof String,sym=n=>"symbol"==typeof n,undef=n=>void 0===n||void 0===n,typa=(n,e,r,t)=>{if(n&&e&&r&&t)return is[n](e)?fn(r)?r():r:fn(t)?t():t;throw new Error("typa(): Invalid input")},what=n=>{let e=[];const r=[{fn:"arr",name:"array"},{fn:"bool",name:"boolean"},{fn:"date",name:"date"},{fn:"err",name:"error"},{fn:"fn",name:"function"},{fn:"int",name:"integer"},{fn:"json",name:"json"},{fn:"num",name:"number"},{fn:"obj",name:"object"},{fn:"prom",name:"promise"},{fn:"regex",name:"regexp"},{fn:"str",name:"string"},{fn:"sym",name:"symbol"}];return[{fn:"undef",name:"undefined"},{fn:"nil",name:"null"}].forEach(r=>{is[r.fn](n)&&e.push(r.name)}),e.length||r.forEach(r=>{is[r.fn](n)&&e.push(r.name)}),1===e.length?e[0]:e},is={arr:arr,bad:bad,bool:bool,date:date,empty:empty,err:err,fn:fn,int:int,json:json,nil:nil,nullish:nullish,num:num,obj:obj,prom:prom,regex:regex,str:str,sym:sym,typa:typa,undef:undef,what:what};export default is; | ||
//# sourceMappingURL=index.min.js.map |
@@ -112,3 +112,3 @@ // array | ||
const typa = (check, value, fn1, fn2) => { | ||
if (!!check && value && !!fn1 && !!fn2) return is[check](value) ? fn1() : fn2(); | ||
if (!!check && value && !!fn1 && !!fn2) return is[check](value) ? fn(fn1) ? fn1() : fn1 : fn(fn2) ? fn2() : fn2; | ||
throw new Error('typa(): Invalid input'); | ||
@@ -115,0 +115,0 @@ }; // return type(s) of $value |
@@ -1,2 +0,2 @@ | ||
const arr=n=>"object"==typeof n&&n.constructor===Array,bad=n=>nil(n)||undef(n)||nullish(n)||empty(n)||err(n),bool=n=>"boolean"==typeof n,empty=n=>str(n)&&0===n.length||arr(n)&&0===n.length||obj(n)&&0===Object.keys(n).length,date=n=>n instanceof Date,err=n=>n instanceof Error,json=(n,e)=>{if(!n)return!1;try{switch(e){case"obj":JSON.stringify(n);break;case"str":default:JSON.parse(n)}return!0}catch(n){return!1}},fn=n=>"function"==typeof n,int=n=>"number"==typeof n&&isFinite(n)&&Number.isInteger(n),nil=n=>null===n,nullish=n=>null==n||null==n,num=n=>"number"==typeof n&&isFinite(n),obj=n=>"object"==typeof n&&n.constructor===Object,prom=n=>n instanceof Promise,regex=n=>"object"==typeof n&&n.constructor===RegExp,str=n=>"string"==typeof n||n instanceof String,sym=n=>"symbol"==typeof n,undef=n=>void 0===n||void 0===n,typa=(n,e,r,t)=>{if(n&&e&&r&&t)return is[n](e)?r():t();throw new Error("typa(): Invalid input")},what=n=>{let e=[];const r=[{fn:"arr",name:"array"},{fn:"bool",name:"boolean"},{fn:"date",name:"date"},{fn:"err",name:"error"},{fn:"fn",name:"function"},{fn:"int",name:"integer"},{fn:"json",name:"json"},{fn:"num",name:"number"},{fn:"obj",name:"object"},{fn:"prom",name:"promise"},{fn:"regex",name:"regexp"},{fn:"str",name:"string"},{fn:"sym",name:"symbol"}];return[{fn:"undef",name:"undefined"},{fn:"nil",name:"null"}].forEach(r=>{is[r.fn](n)&&e.push(r.name)}),e.length||r.forEach(r=>{is[r.fn](n)&&e.push(r.name)}),1===e.length?e[0]:e},is={arr:arr,bad:bad,bool:bool,date:date,empty:empty,err:err,fn:fn,int:int,json:json,nil:nil,nullish:nullish,num:num,obj:obj,prom:prom,regex:regex,str:str,sym:sym,typa:typa,undef:undef,what:what};export default is; | ||
const arr=n=>"object"==typeof n&&n.constructor===Array,bad=n=>nil(n)||undef(n)||nullish(n)||empty(n)||err(n),bool=n=>"boolean"==typeof n,empty=n=>str(n)&&0===n.length||arr(n)&&0===n.length||obj(n)&&0===Object.keys(n).length,date=n=>n instanceof Date,err=n=>n instanceof Error,json=(n,e)=>{if(!n)return!1;try{switch(e){case"obj":JSON.stringify(n);break;case"str":default:JSON.parse(n)}return!0}catch(n){return!1}},fn=n=>"function"==typeof n,int=n=>"number"==typeof n&&isFinite(n)&&Number.isInteger(n),nil=n=>null===n,nullish=n=>null==n||null==n,num=n=>"number"==typeof n&&isFinite(n),obj=n=>"object"==typeof n&&n.constructor===Object,prom=n=>n instanceof Promise,regex=n=>"object"==typeof n&&n.constructor===RegExp,str=n=>"string"==typeof n||n instanceof String,sym=n=>"symbol"==typeof n,undef=n=>void 0===n||void 0===n,typa=(n,e,r,t)=>{if(n&&e&&r&&t)return is[n](e)?fn(r)?r():r:fn(t)?t():t;throw new Error("typa(): Invalid input")},what=n=>{let e=[];const r=[{fn:"arr",name:"array"},{fn:"bool",name:"boolean"},{fn:"date",name:"date"},{fn:"err",name:"error"},{fn:"fn",name:"function"},{fn:"int",name:"integer"},{fn:"json",name:"json"},{fn:"num",name:"number"},{fn:"obj",name:"object"},{fn:"prom",name:"promise"},{fn:"regex",name:"regexp"},{fn:"str",name:"string"},{fn:"sym",name:"symbol"}];return[{fn:"undef",name:"undefined"},{fn:"nil",name:"null"}].forEach(r=>{is[r.fn](n)&&e.push(r.name)}),e.length||r.forEach(r=>{is[r.fn](n)&&e.push(r.name)}),1===e.length?e[0]:e},is={arr:arr,bad:bad,bool:bool,date:date,empty:empty,err:err,fn:fn,int:int,json:json,nil:nil,nullish:nullish,num:num,obj:obj,prom:prom,regex:regex,str:str,sym:sym,typa:typa,undef:undef,what:what};export default is; | ||
//# sourceMappingURL=index.min.js.map |
{ | ||
"name": "typa", | ||
"description": "Super-simple, zero-dependency JavaScript type checker utility.", | ||
"version": "0.3.3", | ||
"version": "0.3.4", | ||
"license": "MIT", | ||
@@ -6,0 +6,0 @@ "files": [ |
@@ -46,3 +46,3 @@ # Typa: Zero-dep JS type checker 🧐 | ||
- <a href="#integer">_int_</a> → Integer | ||
- <a href="#json">_json_</a> → Serialized JSON object | ||
- <a href="#json">_json_</a> → JSON string or object | ||
- <a href="#nil">_nil_</a> → Null | ||
@@ -60,3 +60,3 @@ - <a href="#nullish">_nullish_</a> → Null or undefined | ||
Ternary operator that checks if the supplied value matches the specified type, then returns the first callback function (or value) if true or the second callback function (or value) if false. | ||
Ternary operator that checks if the supplied value matches the specified type, then returns the first callback function or value if true or the second callback function or value if false. | ||
@@ -168,6 +168,8 @@ **.typa**($type, $value, $fn1, $fn2) | ||
<a name="json"></a>**.json**(\$value, \$type ['str'|'obj']) — Serialized JSON object | ||
<a name="json"></a>**.json**(\$value, \$type ['str'|'obj']) — JSON string (default) or object | ||
```js | ||
const isJson = is.json('{"key": "value"}') | ||
// => true | ||
const isJson = is.json({ key: 'value' }, 'obj') | ||
@@ -174,0 +176,0 @@ // => true |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
50411
270