SkillAgentSearch skills...

Is.js

Minimalistic predicate library.

Install / Use

/learn @mov37/Is.js
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

is.js

version build status

saucelabs matrix

Minimalistic predicate library.

This is a general purpose check library, you may found tagOf useful if all you want is just check types.

Install

Node:

$ npm install --save @pwn/is

Browser:

<script src="path/to/is.min.js"></script>

Features

  • Zero dependencies.
  • Un-opinionated — includes only the bare minimum predicates you're likely to use.
  • Works with Node, AMD and all browsers, including IE6.
  • Extensible.

Usage

A code sample is worth a thousand words:

let is = require( '@pwn/is' )

is.array( [] ) // true
is.not.integer( 0 ) // false
is.propertyDefined( { foo : { bar : 0 } } , 'foo.bar' ) // true
is.equal( [ 1 , [ 2 , 3 ] ] , [ 1 , [ 2 , 3 ] ] ) // false
is.deepEqual( [ 1 , [ 2 , 3 ] ] , [ 1 , [ 2 , 3 ] ] ) // true

// use a third-party bundle
is.use( require( 'path/to/some/math/bundle' ) )
is.prime( 7 ) // true

All checks, or predicates in is.js terminology, takes two general forms:

  • POSITIVE CHECK: is.predicate( ...args ) - Checks whether certain condition met.
  • NEGATIVE CHECK: is.not.predicate( ...args ) - The inverse of its corresponding positive check.

That's it! What's next?

Cheatsheet

TL;DR

A bundle is simply a way of organizing related predicates.

bundle:nil

bundle:number

bundle:string

bundle:boolean

bundle:object

bundle:array

bundle:type

bundle:equality

API reference

is.null( value )

Checks whether given value is null.

is.null( null ) // true
is.null( undefined ) // false

is.undefined( value )

Checks whether given value is undefined.

is.undefined( null ) // false
is.undefined( undefined ) // true

is.exist( value )

Checks whether given value exists, i.e, not null nor undefined.

is.exist( null ) // false
is.exist( undefined ) // false

is.nil( value )

Checks whether given value is either null or undefined.

is.nil( null ) // true
is.nil( undefined ) // true

is.number( value )

Checks whether given value is a number.

is.number( 0 ) // true
is.number( Number.NaN ) // true
is.number( Number.POSITIVE_INFINITY ) // true
is.number( Number.NEGATIVE_INFINITY ) // true
is.number( '0' ) // false
is.number( new Number( 0 ) ) // false

is.numeral( value )

Checks whether given value is a numeral, i.e:

  • a genuine finite number
  • or a string that represents a finite number
is.numeral( null ) // false
is.numeral( undefined ) // false
is.numeral( true ) // false
is.numeral( false ) // false
is.numeral( Symbol( 0 ) ) // false
is.numeral( Symbol.for( 0 ) ) // false
is.numeral( { valueOf() { return 0 } } ) // false
is.numeral( [ 0 ] ) // false
is.numeral( () => 0 ) // false

is.numeral( '' ) // false
is.numeral( 'one' ) // false
is.numeral( '1px' ) // false
is.numeral( '  0xFF  ' ) // true
is.numeral( '1e1' ) // true
is.numeral( '1.1E-1' ) // true
is.numeral( '-1' ) // true
is.numeral( '1.1' ) // true
is.numeral( new Number( 1 ) ) // true
is.numeral( new String( '-1.1' ) ) // true

is.numeral( Number.NaN ) // false
is.numeral( Number.POSITIVE_INFINITY ) // false
is.numeral( Number.NEGATIVE_INFINITY ) // false

is.nan( value )

Checks whether given value is NaN.

is.nan( 0 ) // false
is.nan( Number.NaN ) // true
is.nan( new Number( Number.NaN ) ) // false
is.nan( Number.POSITIVE_INFINITY ) // false
is.nan( Number.NEGATIVE_INFINITY ) // false
is.nan( 'one' ) // false

is.odd( number )

Checks whether given value is an odd number.

is.odd( 1 ) // true
is.odd( 2 ) // false
is.odd( '1' ) // false
is.odd( '2' ) // false
is.odd( new Number( 1 ) ) // false
is.odd( new Number( 2 ) ) // false
is.odd( Number.NaN ) // false
is.odd( Number.POSITIVE_INFINITY ) // false
is.odd( Number.NEGATIVE_INFINITY ) // false

is.even( number )

Checks whether given value is an even number.

is.even( 1 ) // false
is.even( 2 ) // true
is.even( '1' ) // false
is.even( '2' ) // false
is.even( new Number( 1 ) ) // false
is.even( new Number( 2 ) ) // false
is.even( Number.NaN ) // false
is.even( Number.POSITIVE_INFINITY ) // false
is.even( Number.NEGATIVE_INFINITY ) // false

is.finite( number )

Checks whether given value is a finite number.

is.finite( 0 ) // true
is.finite( '0' ) // false
is.finite( Number.NaN ) // false
is.finite( Number.POSITIVE_INFINITY ) // false
is.finite( Number.NEGATIVE_INFINITY ) // false

is.infinite( number )

Checks whether given value is an infinite number, i.e, Number.POSITIVE_INFINITY or Number.NEGATIVE_INFINITY.

is.infinite( 0 ) // false
is.infinite( '0' ) // false
is.infinite( Number.NaN ) // false
is.infinite( Number.POSITIVE_INFINITY ) // true
is.infinite( Number.NEGATIVE_INFINITY ) // true

is.integer( number )

Checks whether given value is an integer.

is.integer( 0 ) // true
is.integer( '0' ) // false
is.integer( new Number( 0 ) ) // false
is.integer( 0.1 ) // false
is.integer( Number.NaN ) // false
is.integer( Number.POSITIVE_INFINITY ) // false
is.integer( Number.NEGATIVE_INFINITY ) // false
is.integer( Number.MAX_SAFE_INTEGER ) // true
is.integer( Number.MIN_SAFE_INTEGER ) // true
is.integer( Number.MAX_SAFE_INTEGER + 1 ) // true
is.integer( Number.MIN_SAFE_INTEGER - 1 ) // true

is.safeInteger( number )

Checks whether given value is a safe integer.

is.safeInteger( 0 ) // true
is.safeInteger( '0' ) // false
is.safeInteger( new Number( 0 ) ) // false
is.safeInteger( 0.1 ) // false
is.safeInteger( Number.NaN ) // false
is.safeInteger( Number.POSITIVE_INFINITY ) // false
is.safeInteger( Number.NEGATIVE_INFINITY ) // false
is.safeInteger( Number.MAX_SAFE_INTEGER ) // true
is.safeInteger( Number.MIN_SAFE_INTEGER ) // true
is.safeInteger( Number.MAX_SAFE_INTEGER + 1 ) // false
is.safeInteger( Number.MIN_SAFE_INTEGER - 1 ) // false

is.string( value )

Checks whether given value is a string.

is.string( 'lipsum' ) // true
is.string( new String( 'lipsum' ) ) // false

is.emptyString( string )

Checks whether given value is an empty string, i.e, a string with whitespace characters only.

is.emptyString( '' ) // true
is.emptyString( ' ' ) // true
is.emptyString( '\f\n\r\t' ) // true
is.emptyString( '\u0009\u000A\u000B\u000C\u000D\u0020' ) // true
is.emptyString( 'lipsum' ) // false

is.substring( substring , string , [offset=0] )

Checks whether one string may be found within another string.

is.substring( 'ps' , 'lipsum' ) // true
is.substring( 'sp' , 'lipsum' ) // false
is.substring( [ 'ps' ] , 'lipsum' ) // true; `substring` will be converted to a string as needed
is.substring( 'ps' , [ 'lipsum' ] ) // false; `string` must be a string
is.substring( 'ps' , 'lipsum' , 2 ) // true
is.substring( 'ps' , 'lipsum' , 3 ) // false
is.substring( 'ps' , 'lipsum' , 3.14 ) // true; non-integer offset will be omitted and defaults to 0
is.substring( 'ps' , 'lipsum' , -4 ) // true; supports negative offset
is.substring( 'ps' , 'lipsum' , 6 ) // false; offset out of range
is.substring( 'ps' , 'lipsum' , -7 ) // false; offset out of range

is.prefix( prefix , string )

Checks whether string starts with prefix.

is.prefix( 'lip' , 'lipsum' ) // true
is.prefix( 'sum' , 'lipsum' ) // false
is.prefix( 'lip' , [ 'lipsum' ] ) // false; `string` must be a string
is.prefix( [ 'lip' ] , 'lipsum' ) // true - `prefix` will be converted to a string as needed

is.suffix( su

View on GitHub
GitHub Stars970
CategoryDevelopment
Updated21h ago
Forks29

Languages

JavaScript

Security Score

85/100

Audited on Mar 30, 2026

No findings