get-data-type

1.0.2 • Public • Published

get-data-type

Get data's type

how to use get-data-type

npm install --save data-type
const dataType = require('get-data-type');

dataType('test'); // return 'string'

test

const assert = require('assert');
const m = require('./');

assert(m(null) === 'null', 'should return null');
assert(m(undefined) === 'undefined', 'should return undefined');
assert(m(true) === 'boolean', 'should return boolean');
assert(m(false) === 'boolean', 'should return boolean');
assert(m(1) === 'number', 'should return number');
assert(m('test') === 'string', 'should return string');
assert(m(Symbol()) === 'symbol', 'should return symbol');
assert(m({}) === 'object', 'should return object');
assert(m([]) === 'array', 'should return array');
assert(m(()=>{}) === 'function', 'should return function');
assert(m(new Date()) === 'date', 'should return date');
assert(m(new RegExp()) === 'regexp', 'should return regexp');

Readme

Keywords

Package Sidebar

Install

npm i get-data-type

Weekly Downloads

0

Version

1.0.2

License

MIT

Unpacked Size

2.48 kB

Total Files

4

Last publish

Collaborators

  • xuyunfei