1.0.4 • Published 4 years ago

@bemoje/type-of v1.0.4

Weekly downloads
6
License
MIT
Repository
github
Last release
4 years ago

@bemoje/type-of

Returns a string representing a value's constructor's name property, except for 'NaN', infinite values, 'Infinity', 'Null' and 'Undefined'.

Version

Travis CI

Dependencies

Stats

Donate

Installation

npm install @bemoje/type-of
npm install --save @bemoje/type-of
npm install --save-dev @bemoje/type-of

Usage

import typeOf from '@bemoje/type-of'

typeOf(NaN)
//=> NaN

typeOf(Infinity)
//=> Infinity

typeOf(Number.POSITIVE_INFINITY)
//=> Infinity

typeOf(Number.NEGATIVE_INFINITY)
//=> Infinity

typeOf('asdf')
//=> 'String'

typeOf(new String('asdf'))
//=> 'String'

typeOf(1)
//=> 'Number'

typeOf(Number(1))
//=> 'Number'

typeOf(new Number(1))
//=> 'Number'

typeOf(new Object())
//=> 'Object'

typeOf({})
//=> 'Object'

typeOf([])
//=> 'Array'

class Custom {}

typeOf(new Custom())
//=> 'Custom'

typeOf(undefined)
//=> 'Undefined'

typeOf(null)
//=> 'Null'

Tests

Uses Jest to test module functionality. Run tests to get coverage details.

npm run test

API

typeOf

Returns

a string representing a value's constructor's name property, except for 'NaN', infinite values, 'Infinity', 'Null' and 'Undefined'.

Parameters
  • value any The value to evaluate
Returns

string