npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

istypes

v1.4.0

Published

type-checking utility library for testing type match/mismatch, testing for common type categories, getting types of tested instances, and a few extra

Readme

istypes

NPM

istypes is a library that allows type-checking of javascript instances and also a way to group a list of items by type.

Installation

$ npm install --save istypes

or

$ yarn add istypes

Usage

Type checking API:

All samples are included in tests to guarantee their validity


import { check } from 'istypes';

// positives
check.isUndefined(undefined) // true
check.isNull(null) // true
check.isBoolean(true)  // true
check.isNumber(0)  // true
check.isNumber(parseInt('x')) // true (NaN is a number)
check.isNumber(1 / 0)  // true (+Infinity is a number)
check.isString('') // true
check.isArray([])  // true
check.isObject({}) // true
check.isFunction(() => {}) // true
(function () {
    check.isArguments(arguments) // true
})()
check.isRegExp(/.*/)     // true
check.isDate(new Date()) // true

// negatives
check.isNotUndefined(undefined) // false
check.isNotNull(null) // false
check.isNotBoolean(true)  // false
check.isNotNumber(0)  // false
check.isNotNumber(parseInt('x')) // false (NaN is a number)
check.isNotNumber(1 / 0)  // false (+Infinity is a number)
check.isNotString('') // false
check.isNotArray([])  // false
check.isNotObject({}) // false
check.isNotFunction(() => {}) // false
(function () {
    check.isNotArguments(arguments) // false
})()
check.isNotRegExp(/.*/)     // false
check.isNotDate(new Date()) // false

Checks for primitives:

isPrimitive(test)

A test for primitive-ness as found on stackoverflow:


console.log([
  // promitives :
  undefined,
  null,
  true,
  false,
  0,
  parseInt('x'),
  1 / 0,
  -1 / 0,
  '',
  Symbol.iterator,

  // complex:
  [],
  {},
  function () {
  },
  arguments,
  /$/,
  new Date(),
  new Error('')
].map(check.isPrimitive));

Outputs:

[ true, // undefined,
  true, // null,
  true, // true,
  true, // false,
  true, // 0,
  true, // parseInt('x'),
  true, // 1 / 0,
  true, // -1 / 0,
  true, // '',
  true, // Symbol.iterator,
  false,
  false,
  false,
  false,
  false,
  false,
  false ]

isNotPrimitive(test)

Returns exactly opposite of isPrimitive(test)

Checks for iterables:

TODO: add explanation

isIterable(test) and isNotIterable(test)

TODO: add sample code

Checks for array-like objects:

TODO: add explanation

isArrayLike(test) and isNotArrayLike(test)

TODO: add sample code

Type extraction

console.log([
    undefined,
    null,
    false,
    0,
    '',
    [],
    {},
    function () {
    },
    arguments,
    /$/,
    new Date()
].map(check.getType))

Outputs:

[ 'undefined',
  'null',
  'boolean',
  'number',
  'string',
  'array',
  'object',
  'function',
  'arguments',
  'regexp',
  'date' ]

Extensibility

Checks are available even for types not included in the library:


import { check as checkGen } from 'istypes';

const check = checkGen(new Map(), new Set(), new Error(), Symbol.iterator, Buffer.from(''));

check.isUndefined(undefined) // true
check.isMap(new Map()) // true
check.getType(new Set()) // 'set'
check.isError(new Error()) // true
check.isSymbol(Symbol.species) // true
// here is a small catch with Buffer:
check.isUint8Array(Buffer.from('123')) // true, after all, Buffer is a type 'Uint8Array'
check.getType(Buffer.from('456')) // 'uint8array'

Methods getType(input), isPrimitive(test), and isNotPrimitive(test) are not affected by extensibility.

Grouping by type:

A convenience method to stack values of an array-like object (e.g. arguments) under the keys named after items' types in a simple object.

import { groupByType } from 'istypes';

function (/* variable signature, name? : string, options? : object, callback? : function */) {
  const grouped = groupByType(argusments);
  
  if (grouped.string) {
    // name provided
  }
  
  if (grouped.object) {
    // options provided
  }
  
  if (grouped['function']) {
    // callback provided
  }
  
  // ...
}

Contributing

Please use the issues page to report a bug or request a feature.

Stay in Touch

License

MIT

Author

Andrew Revinsky