npm

npm’s 2019 JavaScript ecosystem survey analysis is now available! Get your copy here »

javascript-types

1.0.7 • Public • Published

Javascript Types

typeof null === 'object' ? WTF : sanity.

This small package fixes that. Simply:

npm install javascript-types

in your project.

Then:

    import { getTypeOf, isJSON, isBoolean, isHtmlElement } from 'javascript-types';
    
    const domNode = document.getElementById('x');

    typeof domNode; // 'object'
    getTypeOf(domNode); // 'htmldivelement'
    
    typeof null; // 'object'
    getTypeOf(null); // 'null'

    typeof new Date(); // 'object'
    getTypeOf(new Date()); // 'date'

    typeof [1,2,3]; 'object'
    getTypeOf([1,2,3]); // 'array'
    
    const body = JSON.stringify({
      offset: 0,
      limit: 10
    });

    isJSON(body); // true
    isBoolean(false); // true
    isHtmlElement(domNode); // true
    ...

Methods available:

    getTypeOf,
    isRegexp,
    isHtmlElement,
    isArray,
    isBoolean,
    isDate,
    isJSON,
    isNull,
    isNumber,
    isObject,
    isString,
    isUndefined,

install

npm i javascript-types

Downloadsweekly downloads

1

version

1.0.7

license

MIT

last publish

collaborators

  • avatar
Report a vulnerability