Comparing version 0.3.0 to 0.3.1
@@ -7,3 +7,3 @@ 'use strict'; | ||
const arr = value => { | ||
return !!value && typeof value === 'object' && value.constructor === Array; | ||
return typeof value === 'object' && value.constructor === Array; | ||
}; // bad | ||
@@ -13,3 +13,3 @@ | ||
const bad = value => { | ||
return !!value && (nil(value) || undef(value) || nullish(value) || empty(value) || err(value)); | ||
return nil(value) || undef(value) || nullish(value) || empty(value) || err(value); | ||
}; // boolean | ||
@@ -19,3 +19,3 @@ | ||
const bool = value => { | ||
return !!value && typeof value === 'boolean'; | ||
return typeof value === 'boolean'; | ||
}; // empty | ||
@@ -25,3 +25,3 @@ | ||
const empty = value => { | ||
return !!value && (str(value) && value.length > 0 || arr(value) && value.length === 0 || obj(value) && Object.keys(value).length === 0); | ||
return str(value) && value.length === 0 || arr(value) && value.length === 0 || obj(value) && Object.keys(value).length === 0; | ||
}; // date | ||
@@ -31,3 +31,3 @@ | ||
const date = value => { | ||
return !!value && value instanceof Date; | ||
return value instanceof Date; | ||
}; // error | ||
@@ -37,3 +37,3 @@ | ||
const err = value => { | ||
return !!value && value instanceof Error; | ||
return value instanceof Error; | ||
}; // json | ||
@@ -67,3 +67,3 @@ | ||
const fn = value => { | ||
return !!value && typeof value === 'function'; | ||
return typeof value === 'function'; | ||
}; // integer | ||
@@ -73,3 +73,3 @@ | ||
const int = value => { | ||
return !!value && typeof value === 'number' && isFinite(value) && Number.isInteger(value); | ||
return typeof value === 'number' && isFinite(value) && Number.isInteger(value); | ||
}; // null | ||
@@ -89,3 +89,3 @@ | ||
const num = value => { | ||
return !!value && typeof value === 'number' && isFinite(value); | ||
return typeof value === 'number' && isFinite(value); | ||
}; // object | ||
@@ -95,3 +95,3 @@ | ||
const obj = value => { | ||
return !!value && typeof value === 'object' && value.constructor === Object; | ||
return typeof value === 'object' && value.constructor === Object; | ||
}; // promise | ||
@@ -101,3 +101,3 @@ | ||
const prom = value => { | ||
return !!value && (typeof value === 'object' || typeof value === 'function') && value.then && typeof value.then === 'function'; | ||
return value instanceof Promise; | ||
}; // regex | ||
@@ -107,3 +107,3 @@ | ||
const regex = value => { | ||
return !!value && typeof value === 'object' && value.constructor === RegExp; | ||
return typeof value === 'object' && value.constructor === RegExp; | ||
}; // string | ||
@@ -113,3 +113,3 @@ | ||
const str = value => { | ||
return !!value && (typeof value === 'string' || value instanceof String); | ||
return typeof value === 'string' || value instanceof String; | ||
}; // symbol | ||
@@ -119,3 +119,3 @@ | ||
const sym = value => { | ||
return !!value && typeof value === 'symbol'; | ||
return typeof value === 'symbol'; | ||
}; // undefined | ||
@@ -129,9 +129,6 @@ | ||
function typa(check, value, fn1, fn2) { | ||
if (!!check && !!value && !!fn1 && !!fn2) { | ||
return is[check](value) ? fn1 : fn2; | ||
} else { | ||
throw new Error('Invalid parameters.'); | ||
} | ||
} // return type(s) of $value | ||
const typa = (check, value, fn1, fn2) => { | ||
if (!!check && value && !!fn1 && !!fn2) return is[check](value) ? fn1() : fn2(); | ||
throw new Error('typa(): Invalid input'); | ||
}; // return type(s) of $value | ||
@@ -141,2 +138,9 @@ | ||
let what = []; | ||
const nullChecks = [{ | ||
fn: 'undef', | ||
name: 'undefined' | ||
}, { | ||
fn: 'nil', | ||
name: 'null' | ||
}]; | ||
const checks = [{ | ||
@@ -164,5 +168,2 @@ fn: 'arr', | ||
}, { | ||
fn: 'nil', | ||
name: 'null' | ||
}, { | ||
fn: 'num', | ||
@@ -185,14 +186,17 @@ name: 'number' | ||
name: 'symbol' | ||
}, { | ||
fn: 'undef', | ||
name: 'undefined' | ||
}]; | ||
checks.forEach(check => { | ||
nullChecks.forEach(check => { | ||
if (is[check.fn](value)) what.push(check.name); | ||
}); | ||
if (!value) throw new Error('Missing value to test.'); | ||
if (!what.length) { | ||
checks.forEach(check => { | ||
if (is[check.fn](value)) what.push(check.name); | ||
}); | ||
} | ||
return what.length === 1 ? what[0] : what; | ||
}; | ||
var index = { | ||
const is = { | ||
arr, | ||
@@ -220,3 +224,3 @@ bad, | ||
exports.default = index; | ||
exports.default = is; | ||
//# sourceMappingURL=index.js.map |
// array | ||
const arr = value => { | ||
return !!value && typeof value === 'object' && value.constructor === Array; | ||
return typeof value === 'object' && value.constructor === Array; | ||
}; // bad | ||
@@ -8,3 +8,3 @@ | ||
const bad = value => { | ||
return !!value && (nil(value) || undef(value) || nullish(value) || empty(value) || err(value)); | ||
return nil(value) || undef(value) || nullish(value) || empty(value) || err(value); | ||
}; // boolean | ||
@@ -14,3 +14,3 @@ | ||
const bool = value => { | ||
return !!value && typeof value === 'boolean'; | ||
return typeof value === 'boolean'; | ||
}; // empty | ||
@@ -20,3 +20,3 @@ | ||
const empty = value => { | ||
return !!value && (str(value) && value.length > 0 || arr(value) && value.length === 0 || obj(value) && Object.keys(value).length === 0); | ||
return str(value) && value.length === 0 || arr(value) && value.length === 0 || obj(value) && Object.keys(value).length === 0; | ||
}; // date | ||
@@ -26,3 +26,3 @@ | ||
const date = value => { | ||
return !!value && value instanceof Date; | ||
return value instanceof Date; | ||
}; // error | ||
@@ -32,3 +32,3 @@ | ||
const err = value => { | ||
return !!value && value instanceof Error; | ||
return value instanceof Error; | ||
}; // json | ||
@@ -62,3 +62,3 @@ | ||
const fn = value => { | ||
return !!value && typeof value === 'function'; | ||
return typeof value === 'function'; | ||
}; // integer | ||
@@ -68,3 +68,3 @@ | ||
const int = value => { | ||
return !!value && typeof value === 'number' && isFinite(value) && Number.isInteger(value); | ||
return typeof value === 'number' && isFinite(value) && Number.isInteger(value); | ||
}; // null | ||
@@ -84,3 +84,3 @@ | ||
const num = value => { | ||
return !!value && typeof value === 'number' && isFinite(value); | ||
return typeof value === 'number' && isFinite(value); | ||
}; // object | ||
@@ -90,3 +90,3 @@ | ||
const obj = value => { | ||
return !!value && typeof value === 'object' && value.constructor === Object; | ||
return typeof value === 'object' && value.constructor === Object; | ||
}; // promise | ||
@@ -96,3 +96,3 @@ | ||
const prom = value => { | ||
return !!value && (typeof value === 'object' || typeof value === 'function') && value.then && typeof value.then === 'function'; | ||
return value instanceof Promise; | ||
}; // regex | ||
@@ -102,3 +102,3 @@ | ||
const regex = value => { | ||
return !!value && typeof value === 'object' && value.constructor === RegExp; | ||
return typeof value === 'object' && value.constructor === RegExp; | ||
}; // string | ||
@@ -108,3 +108,3 @@ | ||
const str = value => { | ||
return !!value && (typeof value === 'string' || value instanceof String); | ||
return typeof value === 'string' || value instanceof String; | ||
}; // symbol | ||
@@ -114,3 +114,3 @@ | ||
const sym = value => { | ||
return !!value && typeof value === 'symbol'; | ||
return typeof value === 'symbol'; | ||
}; // undefined | ||
@@ -124,9 +124,6 @@ | ||
function typa(check, value, fn1, fn2) { | ||
if (!!check && !!value && !!fn1 && !!fn2) { | ||
return is[check](value) ? fn1 : fn2; | ||
} else { | ||
throw new Error('Invalid parameters.'); | ||
} | ||
} // return type(s) of $value | ||
const typa = (check, value, fn1, fn2) => { | ||
if (!!check && value && !!fn1 && !!fn2) return is[check](value) ? fn1() : fn2(); | ||
throw new Error('typa(): Invalid input'); | ||
}; // return type(s) of $value | ||
@@ -136,2 +133,9 @@ | ||
let what = []; | ||
const nullChecks = [{ | ||
fn: 'undef', | ||
name: 'undefined' | ||
}, { | ||
fn: 'nil', | ||
name: 'null' | ||
}]; | ||
const checks = [{ | ||
@@ -159,5 +163,2 @@ fn: 'arr', | ||
}, { | ||
fn: 'nil', | ||
name: 'null' | ||
}, { | ||
fn: 'num', | ||
@@ -180,14 +181,17 @@ name: 'number' | ||
name: 'symbol' | ||
}, { | ||
fn: 'undef', | ||
name: 'undefined' | ||
}]; | ||
checks.forEach(check => { | ||
nullChecks.forEach(check => { | ||
if (is[check.fn](value)) what.push(check.name); | ||
}); | ||
if (!value) throw new Error('Missing value to test.'); | ||
if (!what.length) { | ||
checks.forEach(check => { | ||
if (is[check.fn](value)) what.push(check.name); | ||
}); | ||
} | ||
return what.length === 1 ? what[0] : what; | ||
}; | ||
export default { | ||
const is = { | ||
arr, | ||
@@ -213,2 +217,3 @@ bad, | ||
what | ||
}; | ||
}; | ||
export default is; |
@@ -1,2 +0,3 @@ | ||
declare namespace _default { | ||
export default is; | ||
declare namespace is { | ||
export { arr }; | ||
@@ -23,3 +24,2 @@ export { bad }; | ||
} | ||
export default _default; | ||
declare function arr(value: any): boolean; | ||
@@ -26,0 +26,0 @@ declare function bad(value: any): boolean; |
// array | ||
const arr = value => { | ||
return !!value && typeof value === 'object' && value.constructor === Array; | ||
return typeof value === 'object' && value.constructor === Array; | ||
}; // bad | ||
@@ -8,3 +8,3 @@ | ||
const bad = value => { | ||
return !!value && (nil(value) || undef(value) || nullish(value) || empty(value) || err(value)); | ||
return nil(value) || undef(value) || nullish(value) || empty(value) || err(value); | ||
}; // boolean | ||
@@ -14,3 +14,3 @@ | ||
const bool = value => { | ||
return !!value && typeof value === 'boolean'; | ||
return typeof value === 'boolean'; | ||
}; // empty | ||
@@ -20,3 +20,3 @@ | ||
const empty = value => { | ||
return !!value && (str(value) && value.length > 0 || arr(value) && value.length === 0 || obj(value) && Object.keys(value).length === 0); | ||
return str(value) && value.length === 0 || arr(value) && value.length === 0 || obj(value) && Object.keys(value).length === 0; | ||
}; // date | ||
@@ -26,3 +26,3 @@ | ||
const date = value => { | ||
return !!value && value instanceof Date; | ||
return value instanceof Date; | ||
}; // error | ||
@@ -32,3 +32,3 @@ | ||
const err = value => { | ||
return !!value && value instanceof Error; | ||
return value instanceof Error; | ||
}; // json | ||
@@ -62,3 +62,3 @@ | ||
const fn = value => { | ||
return !!value && typeof value === 'function'; | ||
return typeof value === 'function'; | ||
}; // integer | ||
@@ -68,3 +68,3 @@ | ||
const int = value => { | ||
return !!value && typeof value === 'number' && isFinite(value) && Number.isInteger(value); | ||
return typeof value === 'number' && isFinite(value) && Number.isInteger(value); | ||
}; // null | ||
@@ -84,3 +84,3 @@ | ||
const num = value => { | ||
return !!value && typeof value === 'number' && isFinite(value); | ||
return typeof value === 'number' && isFinite(value); | ||
}; // object | ||
@@ -90,3 +90,3 @@ | ||
const obj = value => { | ||
return !!value && typeof value === 'object' && value.constructor === Object; | ||
return typeof value === 'object' && value.constructor === Object; | ||
}; // promise | ||
@@ -96,3 +96,3 @@ | ||
const prom = value => { | ||
return !!value && (typeof value === 'object' || typeof value === 'function') && value.then && typeof value.then === 'function'; | ||
return value instanceof Promise; | ||
}; // regex | ||
@@ -102,3 +102,3 @@ | ||
const regex = value => { | ||
return !!value && typeof value === 'object' && value.constructor === RegExp; | ||
return typeof value === 'object' && value.constructor === RegExp; | ||
}; // string | ||
@@ -108,3 +108,3 @@ | ||
const str = value => { | ||
return !!value && (typeof value === 'string' || value instanceof String); | ||
return typeof value === 'string' || value instanceof String; | ||
}; // symbol | ||
@@ -114,3 +114,3 @@ | ||
const sym = value => { | ||
return !!value && typeof value === 'symbol'; | ||
return typeof value === 'symbol'; | ||
}; // undefined | ||
@@ -124,9 +124,6 @@ | ||
function typa(check, value, fn1, fn2) { | ||
if (!!check && !!value && !!fn1 && !!fn2) { | ||
return is[check](value) ? fn1 : fn2; | ||
} else { | ||
throw new Error('Invalid parameters.'); | ||
} | ||
} // return type(s) of $value | ||
const typa = (check, value, fn1, fn2) => { | ||
if (!!check && value && !!fn1 && !!fn2) return is[check](value) ? fn1() : fn2(); | ||
throw new Error('typa(): Invalid input'); | ||
}; // return type(s) of $value | ||
@@ -136,2 +133,9 @@ | ||
let what = []; | ||
const nullChecks = [{ | ||
fn: 'undef', | ||
name: 'undefined' | ||
}, { | ||
fn: 'nil', | ||
name: 'null' | ||
}]; | ||
const checks = [{ | ||
@@ -159,5 +163,2 @@ fn: 'arr', | ||
}, { | ||
fn: 'nil', | ||
name: 'null' | ||
}, { | ||
fn: 'num', | ||
@@ -180,14 +181,17 @@ name: 'number' | ||
name: 'symbol' | ||
}, { | ||
fn: 'undef', | ||
name: 'undefined' | ||
}]; | ||
checks.forEach(check => { | ||
nullChecks.forEach(check => { | ||
if (is[check.fn](value)) what.push(check.name); | ||
}); | ||
if (!value) throw new Error('Missing value to test.'); | ||
if (!what.length) { | ||
checks.forEach(check => { | ||
if (is[check.fn](value)) what.push(check.name); | ||
}); | ||
} | ||
return what.length === 1 ? what[0] : what; | ||
}; | ||
var index = { | ||
const is = { | ||
arr, | ||
@@ -215,3 +219,3 @@ bad, | ||
export default index; | ||
export default is; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "typa", | ||
"description": "Super-simple, zero-dependency JavaScript type checker utility.", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"license": "MIT", | ||
@@ -30,2 +30,4 @@ "files": [ | ||
"devDependencies": { | ||
"@babel/core": "^7.9.6", | ||
"@babel/preset-env": "^7.9.6", | ||
"@pika/plugin-build-node": "^0.9.2", | ||
@@ -37,2 +39,5 @@ "@pika/plugin-build-types": "^0.9.2", | ||
"@pika/plugin-standard-pkg": "^0.9.2", | ||
"babel-eslint": "^10.1.0", | ||
"babel-jest": "^25.5.1", | ||
"babel-loader": "^8.1.0", | ||
"eslint": "^6.8.0", | ||
@@ -39,0 +44,0 @@ "eslint-plugin-import": "^2.17.2", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
520
0
37213
21