Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

javascript-types

angsin84MIT1.0.7

A fixed version of the native javascript typeof function.

typeof, fixed typeof, fixed, typeof bugfix, javascript types, getTypeOf, type-checker, isString, isNull, isBoolean, isNumber, isString, isDate, isObject, isArray, isRegexp, isUndefined, isJSON

readme

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,