javascript-types
v1.0.7
Published
A fixed version of the native javascript typeof function.
Downloads
29
Maintainers
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,