Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Isomorphic, functional type-checking for Javascript.
Example
import t from 'typical'
const allDefined = array.every(t.isDefined)
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
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
> t.isNumber(0)
true
> t.isNumber(1)
true
> t.isNumber(1.1)
true
> t.isNumber(0xff)
true
> t.isNumber(0644)
true
> t.isNumber(6.2e5)
true
> t.isNumber(NaN)
false
> t.isNumber(Infinity)
true
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
> t.isFiniteNumber(0)
true
> t.isFiniteNumber(1)
true
> t.isFiniteNumber(1.1)
true
> t.isFiniteNumber(0xff)
true
> t.isFiniteNumber(0644)
true
> t.isFiniteNumber(6.2e5)
true
> t.isFiniteNumber(NaN)
false
> t.isFiniteNumber(Infinity)
false
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
> t.isPlainObject({ something: 'one' })
true
> t.isPlainObject(new Date())
false
> t.isPlainObject([ 0, 1 ])
false
> t.isPlainObject(/test/)
false
> t.isPlainObject(1)
false
> t.isPlainObject('one')
false
> t.isPlainObject(null)
false
> t.isPlainObject((function * () {})())
false
> t.isPlainObject(function * () {})
false
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
function sum(x, y){
console.log(t.isArrayLike(arguments))
// prints `true`
}
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 |
boolean
Returns true if the input value is defined.
Kind: static method of typical
Param | Type | Description |
---|---|---|
input | * | The input to test |
boolean
Returns true if the input value is undefined.
Kind: static method of typical
Param | Type | Description |
---|---|---|
input | * | The input to test |
boolean
Returns true if the input value is null.
Kind: static method of typical
Param | Type | Description |
---|---|---|
input | * | The input to test |
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 |
boolean
Returns true if the input value is an ES2015 class
.
Kind: static method of typical
Param | Type | Description |
---|---|---|
input | * | The input to test |
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 |
boolean
Returns true if the input is a Promise.
Kind: static method of typical
Param | Type | Description |
---|---|---|
input | * | The input to test |
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
> t.isIterable('string')
true
> t.isIterable(new Map())
true
> t.isIterable([])
true
> t.isIterable((function * () {})())
true
> t.isIterable(Promise.resolve())
false
> t.isIterable(Promise)
false
> t.isIterable(true)
false
> t.isIterable({})
false
> t.isIterable(0)
false
> t.isIterable(1.1)
false
> t.isIterable(NaN)
false
> t.isIterable(Infinity)
false
> t.isIterable(function () {})
false
> t.isIterable(Date)
false
> t.isIterable()
false
> t.isIterable({ then: function () {} })
false
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 |
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 |
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
> t.isAsyncFunction(function () {})
false
> t.isAsyncFunction(new Function())
false
> t.isAsyncFunction(() => {})
false
> t.isAsyncFunction(async function () {})
true
> const AsyncFunction = async function () {}.constructor
> t.isAsyncFunction(new AsyncFunction())
true
> t.isAsyncFunction(async () => {})
true
> class Command { async execute () {} }
> t.isAsyncFunction(new Command().execute)
true
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:
import t from 'typical'
import { isNumber } from 'typical'
CommonJS:
const t = require('typical')
const { isNumber } = require('typical')
Within a modern browser ECMAScript Module:
import t from './node_modules/typical/index.js'
© 2014-25 Lloyd Brookes <opensource@75lb.com>.
Test suite by test-runner. Documented by jsdoc-to-markdown.
FAQs
Isomorphic, functional type-checking for Javascript
The npm package typical receives a total of 4,240,921 weekly downloads. As such, typical popularity was classified as popular.
We found that typical demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.