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,

Package Sidebar

Install

npm i javascript-types

Weekly Downloads

4

Version

1.0.7

License

MIT

Unpacked Size

175 kB

Total Files

11

Last publish

Collaborators

  • angsin