Isomorphic, functional type-checking for Javascript
Installations
npm install typical
Developer Guide
Typescript
No
Module System
ESM
Min. Node Version
>=12.17
Node Version
23.1.0
NPM Version
10.9.0
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
75lb
Download Statistics
Total Downloads
700,389,071
Last Day
923,649
Last Week
4,031,904
Last Month
18,445,710
Last Year
225,288,161
GitHub Statistics
22 Stars
108 Commits
4 Forks
2 Watching
2 Branches
4 Contributors
Bundle Size
2.09 kB
Minified
727.00 B
Minified + Gzipped
Package Meta Information
Latest Version
7.3.0
Package Id
typical@7.3.0
Unpacked Size
28.97 kB
Size
4.61 kB
File Count
6
NPM Version
10.9.0
Node Version
23.1.0
Publised On
12 Nov 2024
Total Downloads
Cumulative downloads
Total Downloads
700,389,071
Last day
-0.8%
923,649
Compared to previous day
Last week
-13%
4,031,904
Compared to previous week
Last month
7.7%
18,445,710
Compared to previous month
Last year
26.8%
225,288,161
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
typical
Isomorphic, functional type-checking for Javascript.
Example
1import t from 'typical' 2const allDefined = array.every(t.isDefined)
- typical
- .isNumber(n) ⇒
boolean
- .isFiniteNumber(n) ⇒
boolean
- .isPlainObject(input) ⇒
boolean
- .isArrayLike(input) ⇒
boolean
- .isObject(input) ⇒
boolean
- .isDefined(input) ⇒
boolean
- .isUndefined(input) ⇒
boolean
- .isNull(input) ⇒
boolean
- .isDefinedValue(input) ⇒
boolean
- .isClass(input) ⇒
boolean
- .isPrimitive(input) ⇒
boolean
- .isPromise(input) ⇒
boolean
- .isIterable(input) ⇒
boolean
- .isString(input) ⇒
boolean
- .isFunction(input) ⇒
boolean
- .isAsyncFunction(input) ⇒
boolean
- .isNumber(n) ⇒
t.isNumber(n) ⇒ boolean
Returns true if input is a number (including infinity). It is a more reasonable alternative to typeof n
which returns number
for NaN
.
Kind: static method of typical
Returns: boolean
- true
if input is a number
Param | Type | Description |
---|---|---|
n | * | The input to test |
Example
1> t.isNumber(0) 2true 3> t.isNumber(1) 4true 5> t.isNumber(1.1) 6true 7> t.isNumber(0xff) 8true 9> t.isNumber(0644) 10true 11> t.isNumber(6.2e5) 12true 13> t.isNumber(NaN) 14false 15> t.isNumber(Infinity) 16true
t.isFiniteNumber(n) ⇒ boolean
Returns true if input is a finite number. Identical to isNumber
beside excluding infinity.
Kind: static method of typical
Param | Type | Description |
---|---|---|
n | * | The input to test |
Example
1> t.isFiniteNumber(0) 2true 3> t.isFiniteNumber(1) 4true 5> t.isFiniteNumber(1.1) 6true 7> t.isFiniteNumber(0xff) 8true 9> t.isFiniteNumber(0644) 10true 11> t.isFiniteNumber(6.2e5) 12true 13> t.isFiniteNumber(NaN) 14false 15> t.isFiniteNumber(Infinity) 16false
t.isPlainObject(input) ⇒ boolean
A plain object is a simple object literal, it is not an instance of a class. Returns true if the input typeof
is object
and directly decends from Object
.
Kind: static method of typical
Param | Type | Description |
---|---|---|
input | * | The input to test |
Example
1> t.isPlainObject({ something: 'one' }) 2true 3> t.isPlainObject(new Date()) 4false 5> t.isPlainObject([ 0, 1 ]) 6false 7> t.isPlainObject(/test/) 8false 9> t.isPlainObject(1) 10false 11> t.isPlainObject('one') 12false 13> t.isPlainObject(null) 14false 15> t.isPlainObject((function * () {})()) 16false 17> t.isPlainObject(function * () {}) 18false
t.isArrayLike(input) ⇒ boolean
An array-like value has all the properties of an array yet is not an array instance. An example is the arguments
object. Returns true`` if the input value is an object, not
null`` and has a length
property set with a numeric value.
Kind: static method of typical
Param | Type | Description |
---|---|---|
input | * | The input to test |
Example
1function sum(x, y){
2 console.log(t.isArrayLike(arguments))
3 // prints `true`
4}
t.isObject(input) ⇒ boolean
Returns true if the typeof input is 'object'
but not null.
Kind: static method of typical
Param | Type | Description |
---|---|---|
input | * | The input to test |
t.isDefined(input) ⇒ boolean
Returns true if the input value is defined.
Kind: static method of typical
Param | Type | Description |
---|---|---|
input | * | The input to test |
t.isUndefined(input) ⇒ boolean
Returns true if the input value is undefined.
Kind: static method of typical
Param | Type | Description |
---|---|---|
input | * | The input to test |
t.isNull(input) ⇒ boolean
Returns true if the input value is null.
Kind: static method of typical
Param | Type | Description |
---|---|---|
input | * | The input to test |
t.isDefinedValue(input) ⇒ boolean
Returns true if the input value is not one of undefined
, null
, or NaN
.
Kind: static method of typical
Param | Type | Description |
---|---|---|
input | * | The input to test |
t.isClass(input) ⇒ boolean
Returns true if the input value is an ES2015 class
.
Kind: static method of typical
Param | Type | Description |
---|---|---|
input | * | The input to test |
t.isPrimitive(input) ⇒ boolean
Returns true if the input is a string, number, symbol, boolean, null or undefined value.
Kind: static method of typical
Param | Type | Description |
---|---|---|
input | * | The input to test |
t.isPromise(input) ⇒ boolean
Returns true if the input is a Promise.
Kind: static method of typical
Param | Type | Description |
---|---|---|
input | * | The input to test |
t.isIterable(input) ⇒ boolean
Returns true if the input is an iterable (Map
, Set
, Array
, Generator etc.).
Kind: static method of typical
Param | Type | Description |
---|---|---|
input | * | The input to test |
Example
1> t.isIterable('string') 2true 3> t.isIterable(new Map()) 4true 5> t.isIterable([]) 6true 7> t.isIterable((function * () {})()) 8true 9> t.isIterable(Promise.resolve()) 10false 11> t.isIterable(Promise) 12false 13> t.isIterable(true) 14false 15> t.isIterable({}) 16false 17> t.isIterable(0) 18false 19> t.isIterable(1.1) 20false 21> t.isIterable(NaN) 22false 23> t.isIterable(Infinity) 24false 25> t.isIterable(function () {}) 26false 27> t.isIterable(Date) 28false 29> t.isIterable() 30false 31> t.isIterable({ then: function () {} }) 32false
t.isString(input) ⇒ boolean
Returns true if the input value is a string. The equivalent of typeof input === 'string'
for use in funcitonal contexts.
Kind: static method of typical
Param | Type | Description |
---|---|---|
input | * | The input to test |
t.isFunction(input) ⇒ boolean
Returns true if the input value is a function. The equivalent of typeof input === 'function'
for use in funcitonal contexts.
Kind: static method of typical
Param | Type | Description |
---|---|---|
input | * | The input to test |
t.isAsyncFunction(input) ⇒ boolean
Returns true if the input value is an async function or method.
Kind: static method of typical
Param | Type | Description |
---|---|---|
input | * | The input to test |
Example
1> t.isAsyncFunction(function () {}) 2false 3> t.isAsyncFunction(new Function()) 4false 5> t.isAsyncFunction(() => {}) 6false 7> t.isAsyncFunction(async function () {}) 8true 9> const AsyncFunction = async function () {}.constructor 10> t.isAsyncFunction(new AsyncFunction()) 11true 12> t.isAsyncFunction(async () => {}) 13true 14> class Command { async execute () {} } 15> t.isAsyncFunction(new Command().execute) 16true
Load anywhere
This library is compatible with Node.js, the Web and any style of module loader. It can be loaded anywhere, natively without transpilation.
Within a Node.js ECMAScript Module:
1import t from 'typical' 2import { isNumber } from 'typical'
CommonJS:
1const t = require('typical') 2const { isNumber } = require('typical')
Within a modern browser ECMAScript Module:
1import t from './node_modules/typical/index.js'
© 2014-25 Lloyd Brookes <opensource@75lb.com>.
Test suite by test-runner. Documented by jsdoc-to-markdown.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
3 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 2
Reason
Found 1/25 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/node.js.yml:1
- Info: no jobLevel write permissions found
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/node.js.yml:22: update your workflow using https://app.stepsecurity.io/secureworkflow/75lb/typical/node.js.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/node.js.yml:24: update your workflow using https://app.stepsecurity.io/secureworkflow/75lb/typical/node.js.yml/master?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/node.js.yml:29
- Warn: npmCommand not pinned by hash: .github/workflows/node.js.yml:30
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 2 npmCommand dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
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
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
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 6 are checked with a SAST tool
Score
3.6
/10
Last Scanned on 2025-01-27
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 MoreOther packages similar to typical
@camwiegert/typical
Animated typing in ~400 bytes
vue-typical
Vue Animated typing in ~400 bytes 🐡 of JavaScript.
react-typical
React Animated typing in ~400 bytes 🐡 of JavaScript.
@rickosborne/typical
Rick Osborne's collection of type definitions which I've found helpful across many projects.