Gathering detailed insights and metrics for istypes
Gathering detailed insights and metrics for istypes
npm install istypes
Typescript
Module System
Node Version
NPM Version
70.4
Supply Chain
99.3
Quality
75.7
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
7,063
Last Day
1
Last Week
4
Last Month
48
Last Year
218
MIT License
27 Commits
2 Watchers
1 Branches
1 Contributors
Updated on Aug 02, 2018
Minified
Minified + Gzipped
Latest Version
1.4.0
Package Id
istypes@1.4.0
Unpacked Size
88.61 kB
Size
22.58 kB
File Count
6
NPM Version
6.1.0
Node Version
10.5.0
Cumulative downloads
Total Downloads
Last Day
0%
1
Compared to previous day
Last Week
-55.6%
4
Compared to previous week
Last Month
500%
48
Compared to previous month
Last Year
-19.6%
218
Compared to previous year
istypes
is a library that allows type-checking of javascript instances and also a way to group a list of items by type.
1$ npm install --save istypes
or
1$ yarn add istypes
All samples are included in tests to guarantee their validity
1 2import { check } from 'istypes'; 3 4// positives 5check.isUndefined(undefined) // true 6check.isNull(null) // true 7check.isBoolean(true) // true 8check.isNumber(0) // true 9check.isNumber(parseInt('x')) // true (NaN is a number) 10check.isNumber(1 / 0) // true (+Infinity is a number) 11check.isString('') // true 12check.isArray([]) // true 13check.isObject({}) // true 14check.isFunction(() => {}) // true 15(function () { 16 check.isArguments(arguments) // true 17})() 18check.isRegExp(/.*/) // true 19check.isDate(new Date()) // true 20 21// negatives 22check.isNotUndefined(undefined) // false 23check.isNotNull(null) // false 24check.isNotBoolean(true) // false 25check.isNotNumber(0) // false 26check.isNotNumber(parseInt('x')) // false (NaN is a number) 27check.isNotNumber(1 / 0) // false (+Infinity is a number) 28check.isNotString('') // false 29check.isNotArray([]) // false 30check.isNotObject({}) // false 31check.isNotFunction(() => {}) // false 32(function () { 33 check.isNotArguments(arguments) // false 34})() 35check.isNotRegExp(/.*/) // false 36check.isNotDate(new Date()) // false 37
isPrimitive(test)
A test for primitive-ness as found on stackoverflow:
1 2console.log([ 3 // promitives : 4 undefined, 5 null, 6 true, 7 false, 8 0, 9 parseInt('x'), 10 1 / 0, 11 -1 / 0, 12 '', 13 Symbol.iterator, 14 15 // complex: 16 [], 17 {}, 18 function () { 19 }, 20 arguments, 21 /$/, 22 new Date(), 23 new Error('') 24].map(check.isPrimitive)); 25
Outputs:
1[ true, // undefined, 2 true, // null, 3 true, // true, 4 true, // false, 5 true, // 0, 6 true, // parseInt('x'), 7 true, // 1 / 0, 8 true, // -1 / 0, 9 true, // '', 10 true, // Symbol.iterator, 11 false, 12 false, 13 false, 14 false, 15 false, 16 false, 17 false ]
isNotPrimitive(test)
Returns exactly opposite of isPrimitive(test)
TODO: add explanation
isIterable(test)
and isNotIterable(test)
TODO: add sample code
TODO: add explanation
isArrayLike(test)
and isNotArrayLike(test)
TODO: add sample code
1console.log([ 2 undefined, 3 null, 4 false, 5 0, 6 '', 7 [], 8 {}, 9 function () { 10 }, 11 arguments, 12 /$/, 13 new Date() 14].map(check.getType))
Outputs:
1[ 'undefined', 2 'null', 3 'boolean', 4 'number', 5 'string', 6 'array', 7 'object', 8 'function', 9 'arguments', 10 'regexp', 11 'date' ]
Checks are available even for types not included in the library:
1 2import { check as checkGen } from 'istypes'; 3 4const check = checkGen(new Map(), new Set(), new Error(), Symbol.iterator, Buffer.from('')); 5 6check.isUndefined(undefined) // true 7check.isMap(new Map()) // true 8check.getType(new Set()) // 'set' 9check.isError(new Error()) // true 10check.isSymbol(Symbol.species) // true 11// here is a small catch with Buffer: 12check.isUint8Array(Buffer.from('123')) // true, after all, Buffer is a type 'Uint8Array' 13check.getType(Buffer.from('456')) // 'uint8array' 14
Methods getType(input)
, isPrimitive(test)
, and isNotPrimitive(test)
are not affected by extensibility.
A convenience method to stack values of an array-like object (e.g. arguments
) under the keys named after items' types in a simple object.
1import { groupByType } from 'istypes'; 2 3function (/* variable signature, name? : string, options? : object, callback? : function */) { 4 const grouped = groupByType(argusments); 5 6 if (grouped.string) { 7 // name provided 8 } 9 10 if (grouped.object) { 11 // options provided 12 } 13 14 if (grouped['function']) { 15 // callback provided 16 } 17 18 // ... 19} 20
Please use the issues page to report a bug or request a feature.
Andrew Revinsky
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 0/27 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
39 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-02-10
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More