Installations
npm install istypes
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
10.5.0
NPM Version
6.1.0
Score
70.4
Supply Chain
99.3
Quality
75.7
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
andrevinsky
Download Statistics
Total Downloads
7,063
Last Day
1
Last Week
4
Last Month
48
Last Year
218
GitHub Statistics
MIT License
27 Commits
2 Watchers
1 Branches
1 Contributors
Updated on Aug 02, 2018
Bundle Size
1.62 kB
Minified
715.00 B
Minified + Gzipped
Package Meta Information
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
Total Downloads
Cumulative downloads
Total Downloads
7,063
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
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
istypes
istypes
is a library that allows type-checking of javascript instances and also a way to group a list of items by type.
Installation
1$ npm install --save istypes
or
1$ yarn add istypes
Usage
Type checking API:
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
Checks for primitives:
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)
Checks for iterables:
TODO: add explanation
isIterable(test)
and isNotIterable(test)
TODO: add sample code
Checks for array-like objects:
TODO: add explanation
isArrayLike(test)
and isNotArrayLike(test)
TODO: add sample code
Type extraction
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' ]
Extensibility
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.
Grouping by type:
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
Contributing
Please use the issues page to report a bug or request a feature.
Stay in Touch
License
Author
Andrew Revinsky

No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
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
- Warn: no pull requests merged into dev branch
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
39 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-c6rq-rjc2-86v2
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-8r6j-v8pm-fqw3
- Warn: Project is vulnerable to: MAL-2023-462
- Warn: Project is vulnerable to: GHSA-4q6p-r6v2-jvc5
- Warn: Project is vulnerable to: GHSA-qqgx-2p2h-9c37
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-6c8f-qphg-qjgp
- Warn: Project is vulnerable to: GHSA-4xc9-xhrj-v574
- Warn: Project is vulnerable to: GHSA-x5rq-j2xg-h7qm
- Warn: Project is vulnerable to: GHSA-jf85-cpcp-j695
- Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m
- Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-fhjf-83wg-r2j9
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-g6ww-v8xp-vmwg
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-4g88-fppr-53pp
- Warn: Project is vulnerable to: GHSA-4jqc-8m5r-9rpr
- Warn: Project is vulnerable to: GHSA-j44m-qm6p-hp7m
- Warn: Project is vulnerable to: GHSA-3jfq-g458-7qm9
- Warn: Project is vulnerable to: GHSA-r628-mhmh-qjhw
- Warn: Project is vulnerable to: GHSA-9r2w-394v-53qc
- Warn: Project is vulnerable to: GHSA-5955-9wpr-37jh
- Warn: Project is vulnerable to: GHSA-qq89-hq3f-393p
- Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36
- Warn: Project is vulnerable to: GHSA-832h-xg76-4gv6
- Warn: Project is vulnerable to: GHSA-9vvw-cc9w-f27h
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-h6ch-v84p-w6p9
- Warn: Project is vulnerable to: GHSA-qh2h-chj9-jffq
- Warn: Project is vulnerable to: GHSA-w9mr-4mfr-499f
Score
1.7
/10
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