Small extended typeof
.
Very often we find ourselves adding the same set of checks in addition to
typeof
so we set them as a module.
Classical NodeJS way:
const mkd_typeof = require('mkd_typeof');
New EcmasScript syntax available to NodeJS or browsers with, say, Babel:
import mkd_typeof from 'mkd_typeof';
For browsers it will be loaded as with any other module.
console.log(mkd_typeof(null));
console.log(mkd_typeof({}));
console.log(mkd_typeof([]));
Sample:
> mkd_typeof([]);
'array'
> mkd_typeof(null)
'null'
> mkd_typeof({});
'object'
> mkd_typeof(undefined);
'undefined'
> mkd_typeof(-Infinity);
'infinity'
> mkd_typeof(NaN);
'nan'
> mkd_typeof(1);
'number'
> mkd_typeof(1.0);
'number'
> mkd_typeof('1');
'string'
NodeJS:
$ npm install --save mkd_typeof
Browser:
<script src="/path/to/mkd_typeof.js"></script>
Numbers created with new Number(...)
are detected as numbers but we're not
sure it wouldn't be better to let them seen as objects.