JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 7
  • Score
    100M100P100Q47285F
  • License MIT

A fixed version of the native javascript typeof function.

Package Exports

  • javascript-types

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (javascript-types) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

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,