@gyumeijie/get-type-of

1.0.1 • Public • Published

getTypeOf

get the type of a javascript value

Install

$ npm install @gyumeijie/get-type-of

API

getTypeOf(obj: any, detail?: boolean, typeCase?: string): string

obj:

object to get type of

detail:

get the more detailed information about the type, mainly for customized types, the default value is false

typeCase:

set the case of the output type string, the default value is lower

Usage

const getTypeOf = require('@gyumeijie/get-type-of');

// get the type of built-in types

getTypeOf(undefined)   //'undefined'
getTypeOf(null)   //'null'
getTypeOf(1)   //'number'
getTypeOf('this is a string')   //'string'
getTypeOf(true)   //'boolean'
getTypeOf(Symbol())   //'symbol'
getTypeOf({})   //'object'
getTypeOf([1, 2, 3])   //'array'
getTypeOf(() => {})   //'function'
getTypeOf(Object.create(null))   //'object'
getTypeOf(Object.create(null), true)   //'object'
getTypeOf(new Date())   //'date'
getTypeOf(/regexp/)   //'regexp'

// get the type of the customized types
class Custom {
  constructor() {
    this.name = 'custom';
  }
}
getTypeOf(new Custom()); //'object';
getTypeOf(new Custom(), true); //'custom';

function Foo() {
  this.name = 'foo';
}
getTypeOf(new Foo()); //'object';
getTypeOf(new Foo(), true); //'foo';

License

MIT © Gyumeijie

Package Sidebar

Install

npm i @gyumeijie/get-type-of

Weekly Downloads

6

Version

1.0.1

License

MIT

Unpacked Size

10.1 kB

Total Files

10

Last publish

Collaborators

  • gyumeijie