Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@fabiospampinato/is

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fabiospampinato/is

The definitive collection of is* functions for runtime type checking. Lodash-compatible, tree-shakable, with types.

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-80%
Maintainers
1
Weekly downloads
 
Created
Source

Is

The definitive collection of is* functions for runtime type checking. Lodash-compatible, tree-shakable, with types.

Features

  • Lodash-compatible: The provided functions are compatible with lodash's, so they can be used as drop-in replacements. This includes non-obvious things like being able to work with polyfilled builtins, not throwing in old environments where things like Map aren't available, working with objects from other realms, working with weird things like Boolean ( true ) and Object ( true ), and being isomorphic.
  • Types: Good TypeScript types ship with the library rather than being an afterthought. Also more subtlety this means that some extra functions like isFalsy and isTruthy are provided because their return type is useful for type checking, for lodash it doesn't make much sense to provide these functions because all their value is in the type system, and lodash doesn't care about that.
  • Modern: Some functions have been updated to account for bigints and some addititional ones have been added, the library is tree-shakable so you only pay for what you use.
  • Focused: Every function provided accepts a single argument of unknown type and returns a boolean, almost always as a TypeScript type guard.

Install

npm install --save is@npm:@fabiospampinato/is

Usage

isArguments

Checks if a value is an arguments object.

import {isArguments} from 'is';

const args = (function () { return arguments; })();

isArguments ( args ); // => true
isArguments ( [] ); // => false
isArrayBuffer

Checks if a value is an ArrayBuffer object.

import {isArrayBuffer} from 'is';

isArrayBuffer ( new ArrayBuffer ( 8 ) ); // => true
isArrayBuffer ( [] ); // => false
isArrayLikeObject

Checks if a value is an Array-like object, meaning a non-string and non-function with an integer length property.

import {isArrayLikeObject} from 'is';

isArrayLikeObject ( [] ); // => true
isArrayLikeObject ( { length: 1 } ); // => true
isArrayLikeObject ( 'foo' ); // => false
isArrayLikeObject ( isArrayLikeObject ); // => false
isArrayLike

Checks if a value is an Array-like object, meaning a non-function with an integer length property.

import {isArrayLike} from 'is';

isArrayLike ( [] ); // => true
isArrayLike ( { length: 1 } ); // => true
isArrayLike ( 'foo' ); // => true
isArrayLike ( isArrayLike ); // => false
isArray

Checks if a value is an Array.

import {isArray} from 'is';

isArray ( [] ); // => true
isArray ( {} ); // => false
isBigInt 🆕

Checks if a value is a BigInt.

import {isBigInt} from 'is';

isBigInt ( 0n ); // => true
isBigInt ( 0 ); // => false
isBigInt64Array 🆕

Checks if a value is a BigInt64Array.

import {isBigInt64Array} from 'is';

isBigInt64Array ( new BigInt64Array () ); // => true
isBigInt64Array ( [] ); // => false
isBigUint64Array 🆕

Checks if a value is a BigUint64Array.

import {isBigUint64Array} from 'is';

isBigUint64Array ( new BigUint64Array () ); // => true
isBigUint64Array ( [] ); // => false
isBoolean

Checks if a value is a boolean.

import {isBoolean} from 'is';

isBoolean ( true ); // => true
isBoolean ( false ); // => true
isBoolean ( 0 ); // => false;
isBuffer

Checks if a value is a Buffer.

import {isBuffer} from 'is';

isBuffer ( Buffer.from ( '' ) ); // => true
isBuffer ( [] ); // => false
isDate

Checks if a value is a Date.

import {isDate} from 'is';

isDate ( new Date () ); // => true
isDate ( 0 ); // => false
isElement

Checks if a value is likely a DOM element.

import {isElement} from 'is';

isElement ( body ); // => true
isElement ( window ); // => false
isEmpty

Checks if a value is an empty array, string, buffer, typed array, arguments object, map, set, prototype or regular object.

import {isEmpty} from 'is';

isEmpty ( [] ); // => true
isEmpty ( {} ); // => true
isEmpty ( 123 ); // => true
isEmpty ( [123] ); // => false
isError

Checks if a value is an Error.

import {isError} from 'is';

isError ( new Error () ); // => true
isError ( { message: 'asd' } ); // => false
isFalsy 🆕

Checks if a value is falsy.

import {isFalsy} from 'is';

isFalsy ( 0 ); // => true
isFalsy ( '' ); // => true
isFalsy ( [] ); // => false
isFinite

Checks if a value is a finite number.

import {isFinite} from 'is';

isFinite ( 0 ); // => true
isFinite ( Infinity ); // => false
isFinite ( -Infinity ); // => false
isFinite ( NaN ); // => false
isFloat 🆕

Checks if a value is a float.

import {isFloat} from 'is';

isFloat ( 1.2 ); // => true
isFloat ( 0 ); // => false
isFloat ( -1 ); // => false
isFloat32Array 🆕

Checks if a value is a Float32Array.

import {isFloat32Array} from 'is';

isFloat32Array ( new Float32Array () ); // => true
isFloat32Array ( [] ); // => false
isFloat64Array 🆕

Checks if a value is a Float64Array.

import {isFloat64Array} from 'is';

isFloat64Array ( new Float64Array () ); // => true
isFloat64Array ( [] ); // => false
isFunction

Checks if a value is a function.

import {isFunction} from 'is';

isFunction ( isFunction ); // => true
isFunction ( { call: () => {} } ); // => false
isInt8Array 🆕

Checks if a value is a Int8Array.

import {isInt8Array} from 'is';

isInt8Array ( new Int8Array () ); // => true
isInt8Array ( [] ); // => false
isInt16Array 🆕

Checks if a value is a Int16Array.

import {isInt16Array} from 'is';

isInt16Array ( new Int16Array () ); // => true
isInt16Array ( [] ); // => false
isInt32Array 🆕

Checks if a value is a Int32Array.

import {isInt32Array} from 'is';

isInt32Array ( new Int32Array () ); // => true
isInt32Array ( [] ); // => false
isInteger

Checks if a value is an integer.

import {isInteger} from 'is';

isInteger ( 0 ); // => true
isInteger ( -1 ); // => true
isInteger ( 1.2 ); // => false
isLength

Checks if a value could be a valid length index.

import {isLength} from 'is';

isLength ( 0 ); // => true
isLength ( -1 ); // => false
isLength ( 1.2 ); // => false
isLength ( Infinity ); // => false
isMap

Checks if a value is a Map.

import {isMap} from 'is';

isMap ( new Map () ); // => true
isMap ( {} ); // => false
isNaN

Checks if a value is exactly NaN.

import {isNaN} from 'is';

isNaN ( NaN ); // => true
isNaN ( undefined ); // => false
isNative

Checks if a value is likely a native function.

import {isNative} from 'is';

isNative ( [].push ); // => true
isNative ( isNative ); // => false
isNil

Checks if a value is null or undefined.

import {isNil} from 'is';

isNil ( null ); // => true
isNil ( undefined ); // => true
isNil ( {} ); // => false
isNull

Checks if a value is null.

import {isNull} from 'is';

isNull ( null ); // => true
isNull ( undefined ); // => false
isNumber

Checks if a value is a number.

import {isNumber} from 'is';

isNumber ( 0 ); // => true
isNumber ( Infinity ); // => true
isNumber ( -Infinity ); // => true
isNumber ( NaN ); // => true
isNumber ( '0' ); // => false
isObjectLike

Checks if a value is an object (not necessarily a plain object).

import {isObjectLike} from 'is';

isObjectLike ( {} ); // => true
isObjectLike ( [] ); // => true
isObjectLike ( isObjectLike ); // => false
isObject

Checks if a value is not a primitive. This is the opposite of isPrimitive.

import {isObject} from 'is';

isObject ( {} ); // => true
isObject ( [] ); // => true
isObject ( isObject ); // => true
isObject ( 123 ); // => false
isPlainObject

Checks if a value is a plain object.

import {isPlainObject} from 'is';

isPlainObject ( {} ); // => true
isPlainObject ( [] ); // => false
isPlainObject ( isPlainObject ); // => false
isPrimitive 🆕

Checks if a value is a primitive. This is the opposite of isObject.

import {isPrimitive} from 'is';

isPrimitive ( null ); // => true
isPrimitive ( undefined ); // => true
isPrimitive ( '' ); // => true
isPrimitive ( 0 ); // => true
isPrimitive ( 0n ); // => true
isPrimitive ( true ); // => true
isPrimitive ( Symbol () ); // => true
isPrimitive ( {} ); // => false
isPrimitive ( isPrimitive ); // => false
isPromise 🆕

Checks if a value is a Promise.

import {isPromise} from 'is';

isPromise ( Promise.resolve () ); // => true
isPromise ( Promise.reject () ); // => true
isPromise ( { then: () => {} } ); // => false
isPrototype 🆕

Checks if a value is likely a prototype.

import {isPrototype} from 'is';

isPrototype ( Array.prototype ); // => true
isPrototype ( isPrototype ); // => false
isRegExp

Checks if a value is likely a regex.

import {isRegExp} from 'is';

isRegExp ( /x/ ); // => true
isRegExp ( new RegExp ( 'x' ) ); // => true
isRegExp ( 'x' ); // => false
isSafeInteger

Checks if a value is an integer that can be represented faithfully in JavaScript.

import {isSafeInteger} from 'is';

isSafeInteger ( 0 ); // => true
isSafeInteger ( Number.MAX_SAFE_INTEGER ); // => true
isSafeInteger ( -Number.MAX_SAFE_INTEGER ); // => true
isSafeInteger ( Number.MAX_SAFE_INTEGER + 1 ); // => false
isSet

Checks if a value is a Set.

import {isSet} from 'is';

isSet ( new Set () ); // => true
isSet ( [] ); // => false
isString

Checks if a value is a string.

import {isString} from 'is';

isString ( 'foo' ); // => true
isString ( ['f', 'o', 'o'] ); // => false
isSymbol

Checks if a value is a symbol.

import {isSymbol} from 'is';

isSymbol ( Symbol () ); // => true
isSymbol ( {} ); // => false
isTruthy

Checks if a value is truthy.

import {isTruthy} from 'is';

isTruthy ( [] ); // => true
isTruthy ( 0 ); // => false
isTruthy ( '' ); // => false
isTypedArray

Checks if a value is a TypedArray.

import {isTypedArray} from 'is';

isTypedArray ( new Int8Array ( 8 ) ); // => true
isTypedArray ( [] ); // => false
isUint8Array 🆕

Checks if a value is a Uint8Array.

import {isUint8Array} from 'is';

isUint8Array ( new Uint8Array () ); // => true
isUint8Array ( [] ); // => false
isUint8ClampedArray 🆕

Checks if a value is a Uint8ClampedArray.

import {isUint8ClampedArray} from 'is';

isUint8ClampedArray ( new Uint8ClampedArray () ); // => true
isUint8ClampedArray ( [] ); // => false
isUint16Array 🆕

Checks if a value is a Uint16Array.

import {isUint16Array} from 'is';

isUint16Array ( new Uint16Array () ); // => true
isUint16Array ( [] ); // => false
isUint32Array 🆕

Checks if a value is a Uint32Array.

import {isUint32Array} from 'is';

isUint32Array ( new Uint32Array () ); // => true
isUint32Array ( [] ); // => false
isUndefined

Checks if a value is undefined.

import {isUndefined} from 'is';

isUndefined ( undefined ); // => true
isUndefined ( null ); // => false
isWeakMap

Checks if a value is a WeakMap.

import {isWeakMap} from 'is';

isWeakMap ( new WeakMap () ); // => true
isWeakMap ( new Map () ); // => false
isWeakSet

Checks if a value is a WeakSet.

import {isWeakSet} from 'is';

isWeakSet ( new WeakSet () ); // => true
isWeakSet ( new Set () ); // => false

License

  • Parts: MIT © Fabio Spampinato.
  • Parts: MIT © lodash.

Keywords

FAQs

Package last updated on 23 Nov 2021

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc