Skip to content
This repository has been archived by the owner on Sep 3, 2022. It is now read-only.
/ get-type Public archive

Get the type of a value. For Object this means Object, Array, Date, RegExp, Symbol, etc., instead of generic Object type.

License

Notifications You must be signed in to change notification settings

composi/get-type

Repository files navigation

@composi/get-type

This function creates an RFC4122 version 4 compliant uuid. The type is string. Each uuid will have 36 characters.

Install

npm install --save-dev @composi/get-type

Using

To get the type of primitive types:

import getType from '@composi/get-type'

const str = 'This is text'
getType(str) // returns 'String'

const num = 123
getType(num) // returns 'Number'

let maybe = true
getType(maybe) // returns 'Boolean'

let none = null
getType(none) // returns 'Null'

let missingValue
getType(missingValue) // returns 'Undefined'

let noNumber = 0/0
getType(noNumber) // returns 'NaN'

getType(NaN) // returns 'NaN'

Getting types of objects:

import getType from '@composi/get-type'

getType(String('text here')) // returns 'string'

getType(Number(123)) // returns 'number'

getType(new Object()) // returns 'object'

getType({}) // returns 'object'

getType(new Array()) // returns 'array'

getType([]) // returns 'Aarray'

getType (new Date()) // returns 'date'

getType(Symbol(123)) // returns 'symbol'

getType(new RegExp(/.*/)) // returns 'regEexp'

class Rectangle {
  constructor(height, width) {
    this.height = height;
    this.width = width;
  }
}
getType(Rectangle) // returns 'class

getType(new Rectangle(50,200)) // returns 'object'

About

Get the type of a value. For Object this means Object, Array, Date, RegExp, Symbol, etc., instead of generic Object type.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published