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 🙏

© 2024 – Pkg Stats / Ryan Hefner

what-type-is

v1.2.0

Published

A simple type checking library for Node.js

Downloads

8

Readme

Table of Contents

Example

const { getType, isPlainObject, isArray } = require('what-type-is')

getType([]) // array
isPlainObject([]) // false
isArray(['array']) // true

Installation

npm i --save what-type-is

Tests

npm test

Usage

You can import all functions or import it on-demand using destructuring assignment

Importing all functions

const it = require('what-type-is')
const message = 'Hello'

console.log(
  it.isString(message)
) // true

Importing on-demand

This is a great way to import only what you need to use. You can import any functions available using destructuring assignment. Just take a look at API section to know all functions you can use and import it on-demand.

const { isArray, isObject, isPlainObject isFunction } = require('what-type-is')
const messages = ['Hello', 'World', 'How are you?']

console.log(
  isArray(messages)
) // true

console.log(
  isObject(messages)
) // true

console.log(
  isPlainObject(messages)
) // false

console.log(
  isFunction(messages)
) // false

API

getType( any )

Returns a string containing the type of the given argument.

Example

getType(['array']) // array
getType(new Date) // date
getType({}) // object

isArray( any )

Check if a given argument is an array and returns a boolean.

Example

isArray(['array']) // true
isArray('string') // false 

isString( any )

Check if a given argument is a string and returns a boolean.

Example

isString('string') // true
isString(['array']) // false 

isNumber( any )

Check if a given argument is a number and returns a boolean.

Example

isNumber(10) // true
isNumber(['array']) // false 

isBoolean( any )

Check if a given argument is a boolean and returns a boolean.

Example

isBoolean(true) // true
isBoolean(20) // false 

isObject( any )

Check if a given argument is an object according with ECMA spec and returns a boolean.

Example

isObject({}) // true
isObject(['array']) // true

isPlainObject( any )

Check if a given argument is a plain object and returns a boolean.

Example

isPlainObject({}) // true
isPlainObject(['array']) // false

isFunction( any )

Check if a given argument is a function and returns a boolean.

Example

isFunction(() => {}) // true
isFunction(undefined) // false

isDate( any )

Check if a given argument is a date object and returns a boolean.

Example

isDate(new Date) // true
isDate('27/10/2017') // false

isRegExp( any )

Check if a given argument is a regular expression and returns a boolean.

Example

isRegExp(new RegExp) // true
isRegExp(/regularexpression/i) // true

isNull( any )

Check if a given argument is a null and returns a boolean.

Example

isNull(null) // true
isNull(0) // false

isUndefined( any )

Check if a given argument is an undefined and returns a boolean.

Example

isUndefined(undefined) // true
isUndefined(null) // false

Go Back to The Top