New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

what-is

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

what-is

A very simple "typeof" detection

latest
Source
npmnpm
Version
0.1.2-EOL
Version published
Maintainers
1
Created
Source

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

Keywords

isArray

FAQs

Package last updated on 04 Jul 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts