typeof2

1.0.5 • Public • Published

Typeof2

Very small and fast Javascript type acquisition method.

Use

# install
npm install typeof2 --save
const typeof2 = require("typeof2");

let print = obj=>{
        let o = typeof2(obj);
        console.log("type:",o.type,"name:",o.name);
    };

print(1);
// type: number name: Number

print("1");
// type: string name: String

print([]);
// type: array name: Array

print(new Date());
// type: date name: Date

print({});
// type: object name: Object

class Test{};
print(new Test());
// type: object name: Test

print(true);
// type: boolean name: Boolean

print(/ /);
// type: regexp name: RegExp

print(()=>{})
// type: function name:

print(function(){})
// type: function name:

print(function fun(){})
// type: function name: fun

let fun2 = ()=>{}
print(fun2)
// type: function name: fun2

print(undefined);
// type: undefined name: undefined

print(new Error("err"));
// type: error name: Error

print(new Buffer(0));
// type: uint8array name: Buffer

print(new Uint8Array(0));
// type: uint8array name: Uint8Array

print(new ArrayBuffer(0));
// type: arraybuffer name: ArrayBuffer

// ...

License

MIT

Package Sidebar

Install

npm i typeof2

Weekly Downloads

2

Version

1.0.5

License

MIT

Unpacked Size

2.12 kB

Total Files

4

Last publish

Collaborators

  • sbfkcel