Comparing version 0.3.4 to 0.3.5
@@ -38,14 +38,9 @@ 'use strict'; | ||
if (!!value) { | ||
if (state === 'obj') { | ||
if (str(value)) return false; | ||
if (obj(value)) return true; | ||
} | ||
try { | ||
switch (state) { | ||
case 'obj': | ||
JSON.stringify(value); | ||
break; | ||
case 'str': | ||
default: | ||
JSON.parse(value); | ||
break; | ||
} | ||
JSON.parse(value); | ||
return true; | ||
@@ -52,0 +47,0 @@ } catch (e) { |
@@ -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)?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; | ||
"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;if("obj"===e){if(str(n))return!1;if(obj(n))return!0}try{return JSON.parse(n),!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};exports.default=is; | ||
//# sourceMappingURL=index.min.js.map |
@@ -34,14 +34,9 @@ // array | ||
if (!!value) { | ||
if (state === 'obj') { | ||
if (str(value)) return false; | ||
if (obj(value)) return true; | ||
} | ||
try { | ||
switch (state) { | ||
case 'obj': | ||
JSON.stringify(value); | ||
break; | ||
case 'str': | ||
default: | ||
JSON.parse(value); | ||
break; | ||
} | ||
JSON.parse(value); | ||
return true; | ||
@@ -48,0 +43,0 @@ } catch (e) { |
@@ -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)?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; | ||
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;if("obj"===e){if(str(n))return!1;if(obj(n))return!0}try{return JSON.parse(n),!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 |
@@ -34,14 +34,9 @@ // array | ||
if (!!value) { | ||
if (state === 'obj') { | ||
if (str(value)) return false; | ||
if (obj(value)) return true; | ||
} | ||
try { | ||
switch (state) { | ||
case 'obj': | ||
JSON.stringify(value); | ||
break; | ||
case 'str': | ||
default: | ||
JSON.parse(value); | ||
break; | ||
} | ||
JSON.parse(value); | ||
return true; | ||
@@ -48,0 +43,0 @@ } catch (e) { |
@@ -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)?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; | ||
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;if("obj"===e){if(str(n))return!1;if(obj(n))return!0}try{return JSON.parse(n),!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.4", | ||
"version": "0.3.5", | ||
"license": "MIT", | ||
@@ -6,0 +6,0 @@ "files": [ |
@@ -169,6 +169,6 @@ # Typa: Zero-dep JS type checker 🧐 | ||
```js | ||
const isJson = is.json('{"key": "value"}') | ||
let isJson = is.json('{"key": "value"}') | ||
// => true | ||
const isJson = is.json({ key: 'value' }, 'obj') | ||
isJson = is.json({ key: 'value' }, 'obj') | ||
// => true | ||
@@ -175,0 +175,0 @@ ``` |
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
50100
529