0.1.2-EOL • Published 7 years ago

what-is v0.1.2-EOL

Weekly downloads
4
License
ISC
Repository
github
Last release
7 years ago

NOTE: The package what-is was renamed to wots. Please, consider installing the renamed version.

why?

The library was written as a simple coding exercise, but then appeared useful to share :wink:

how?

npm install --save what-is

and then

var whatis = require('what-is');

// ...

if (whatis(myNotAlwaysNumericVariable) === 'NaN') {
    // do some stuff
}

what?

whatis() function returns reasonable type names for tested values:

descriptioninputresult
nullnull'null'
undefinedundefined'undefined'
strings'foo''string'
'''string'
['Hello', 'world!'].join(' ')'string'
new String()'string'
numbers5'number'
parseInt(42)'number'
new Number('3')'number'
NaN'NaN'
Infinity'Infinity'
1 / -0'Infinity'
boolean valuesfalse'boolean'
!!nonEmptyVariable'boolean'
new Boolean('0')'boolean'
regular expressions/^test$/g'regexp'
new RegExp('needle', 'i')'regexp'
arrays['foo', 'bar', 'baz']'array'
new Array(10)'array'
objects{ foo: 'bar'}'object'
{}'object'
new Object()'object'
Object.create(null)throws error (to be fixed)
functionsfunction () {}'function'
new Function('return null')'function'
date objectsnew Date()'date'
errorsnew Error('error!')'error'
new TypeError('type error!')'error'
arguments objects(function(){return arguments;})()'arguments'
class constructorsnew MyClass()'myclass'
new Buffer()'buffer'
new XMLHttpRequest()'xmlhttprequest'
promisesnew Promise(function() {})'promise'
Promise.resolve('data')'promise'
Promise.reject(new Error('Oop!'))'promise'

Note: for more examples see test file