1.0.3 • Published 1 year ago

get-dtype-of v1.0.3

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

get-dtype-of

NPM version NPM downloads Known Vulnerabilities

Description

This package returns the type of input. By default, the returned data type can be a string | number | boolean | array | object | null | undefined | function. Setting refineObject to true returns the refined type of object (e.g., Date, Map, Set, Buffer, EventEmitter).

Installation

  npm i get-dtype-of

Usage

getTypeOf(input, refineObject)

  • input | any
  • refineObject | boolean | default: false

Examples

  const getTypeOf = require('get-dtype-of');
Without OptionReturnsWith Option (refineObject: true)Returns
getTypeOf("Hello")stringgetTypeOf("Hello", true)string
getTypeOf(412)numbergetTypeOf(412, true)number
getTypeOf(true)booleangetTypeOf(true, true)boolean
getTypeOf(undefined)undefinedgetTypeOf(undefined, true)undefined
getTypeOf(["a", "b"])arraygetTypeOf(["a", "b"], true)array
getTypeOf(null)nullgetTypeOf(null, true)null
getTypeOf(stream)functiongetTypeOf(stream, true)function
getTypeOf({ name: "John" })objectgetTypeOf({ name: "John" }, true)object
getTypeOf(/[a-z]/)objectgetTypeOf(/[a-z]/, true)RegExp
getTypeOf(new Date())objectgetTypeOf(new Date(), true)Date
getTypeOf(new Set())objectgetTypeOf(new Set(), true)Set