JSPM

js-util-type

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

A utility function to fix and extend the built-in ''typeof'' operator of JavaScript.

Package Exports

  • js-util-type

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 (js-util-type) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

js-util-type

A utility function to fix and extend the built-in ''typeof'' operator of JavaScript.

Installation

npm install js-util-type

Example

var types = require('js-util-type')

types.isEmpty([]) // true
types.isEmpty({}) // true
types.isEmpty(' ') // true
types.isEmpty(null) // true
types.isEmpty(undefined) // true
types.isEmpty(0) // false
types.isEmpty(false) // false


types.isNull(null) // true
types.isNull(' ') // false
types.isNull(undefined) // false


types.isUndefined(undefined) // true
types.isUndefined(' ') // false
types.isUndefined(null) // false


types.isNumber(1) // true
types.isNumber('1') // true
types.isNumber(NaN) // false
types.isNumber(Infinity) // false


types.isString('1') // true
types.isString(1) // false
types.isString(false) // false
types.isString(NaN) // false
types.isString(null) // false
types.isString([]) // false
types.isString({}) // false


types.isBoolean(false) // true
types.isBoolean(1) // false
types.isBoolean(null) // false
types.isBoolean([]) // false


types.isObject([]) // true
types.isObject({}) // true
types.isObject(false) // false
types.isObject(1) // false
types.isObject(null) // false


types.isArray([]) // true
types.isArray({}) // false
types.isArray(false) // false
types.isArray(1) // false
types.isArray(null) // false


types.isPlainObject({}) // true
types.isPlainObject([]) // false
types.isPlainObject(false) // false
types.isPlainObject(1) // false
types.isPlainObject(null) // false


types.isNaN(NaN) // true
types.isNaN(Infinity) // false
types.isNaN(1) // false
types.isNaN({}) // false
types.isNaN(false) // false
types.isNaN(null) // false


var foo = function() {}
var promise = new Promise(resolve => resolve())

types.isFunction(foo) // true
types.isFunction(promise) // false
types.isFunction({}) // false


types.isPromise(promise) // true
types.isPromise(foo) // false
types.isPromise({}) // false

License

MIT