Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Gyumeijie/getTypeOf

Repository files navigation

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

About

get the type of a javascript value

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

AltStyle によって変換されたページ (->オリジナル) /