A collection of user-defined type guards to handle some of Javascript's less-than-ideal behavior.
$ npm install is-js
$ yarn add is-js▸ array(arg): arg is any[]
Determines if the argument is an array.
remarks
Defaults to the native Array.isArray method, if present.
| Name | Type |
|---|---|
arg |
any |
arg is any[]
true if the given argument is an array
▸ bigint(value): boolean
Determines if the argument is a BigInt
remarks
This method does not support polyfilled BigInt implementations; please defer
to the library in use to determine the type of an unknown argument.
| Name | Type | Description |
|---|---|---|
value |
unknown |
Value in question |
boolean
true if the given argument is a native BigInt
▸ bool(value): value is boolean
Determines if the argument is a boolean
| Name | Type | Description |
|---|---|---|
value |
unknown |
Value in question |
value is boolean
true if the given argument is a boolean
▸ date(value): value is Date
Determines if the argument is a date.
| Name | Type | Description |
|---|---|---|
value |
unknown |
Value in question |
value is Date
true if the given argument is a date
▸ error(value): value is Error
Determines if the argument is an error.
| Name | Type | Description |
|---|---|---|
value |
unknown |
Value in question |
value is Error
true if the given argument is an error
▸ func(value): value is Function
Determines if the argument is a function.
| Name | Type | Description |
|---|---|---|
value |
unknown |
Value in question |
value is Function
true if the given argument is a function
▸ nil(value): value is null
Determines if the argument is null
| Name | Type | Description |
|---|---|---|
value |
unknown |
Value in question |
value is null
true if the given argument is null
▸ number(value): value is number
Determines if the argument is a number
| Name | Type | Description |
|---|---|---|
value |
unknown |
Value in question |
value is number
true if the given argument is a number
▸ object(value): value is Object
Determines if the argument is an object.
remarks
Nearly everything in Javascript is an object; this method discerns between
native primitives (e.g. true, 3, some text) and their object-wrapped
variants (Boolean, Number, String)
| Name | Type | Description |
|---|---|---|
value |
unknown |
Value in question |
value is Object
true if the given argument is an object
▸ promise(value): value is Promise<unknown>
Determines if the argument is a native promise.
remarks
Some libraries and frameworks still include their own polyfilled Promises,
in which case this method is unreliable. If you are using such a library,
please defer to the provided Promise implementation or use promiseLike
| Name | Type | Description |
|---|---|---|
value |
unknown |
Value in question |
value is Promise<unknown>
true if the given argument is a string
▸ promiseLike(value): value is Object
Determines if the argument conforms to the minimal interface of a Promise;
that is, it has a method named then.
| Name | Type | Description |
|---|---|---|
value |
unknown |
Value in question |
value is Object
true if the given argument conforms to the Promise interface
▸ regex(value): value is RegExp
Determines if the argument is a regular expression.
| Name | Type | Description |
|---|---|---|
value |
unknown |
Value in question |
value is RegExp
true if the given argument is a regular expression
▸ string(value): value is string
Determines if the argument is a string.
| Name | Type | Description |
|---|---|---|
value |
unknown |
Value in question |
value is string
true if the given argument is a string
▸ symbol(value): value is Symbol
Determines if the argument is a symbol
| Name | Type | Description |
|---|---|---|
value |
unknown |
Value in question |
value is Symbol
true if the given argument is a symbol
▸ undef(value): value is undefined
Determines if the argument is undefined
| Name | Type | Description |
|---|---|---|
value |
unknown |
Value in question |
value is undefined
true if the given argument is undefined