get-internal-type ![Twitter](https://img.shields.io/twitter/url?url=https%3A%2F%2Fwww.npmjs.com%2Fpackage%2F%40lopatnov%2Fget-internal-type)
![Build Status](https://travis-ci.org/lopatnov/get-internal-type.png?branch=master)
![LinkedIn](https://img.shields.io/badge/LinkedIn-lopatnov-informational?style=social&logo=linkedin)
Determine the JavaScript [[Class]] of an object, where:
Object Value | [[Class]] | Version |
---|
undefined | undefined | 1.0.0 |
null | null | 1.0.0 |
false | boolean | 1.0.0 |
Symbol("123") | symbol | 1.0.0 |
123 | number | 1.0.0 |
BigInt(9007199254740991) | bigint | 1.0.0 |
"hello" | string | 1.0.0 |
/s+/gi | regexp | 1.0.0 |
new Date() | date | 1.0.0 |
new Error("A mistake") | error | 1.0.0 |
{} | object | 1.0.0 |
new (class SomeCustomClass {}) | object | 1.0.0 |
() => {} | function | 1.0.0 |
function(){} | function | 1.0.0 |
class Simple {} | function | 1.0.0 |
[1,2,3] | array | 1.0.0 |
new Set() | set | 1.2.0 |
new WeakSet() | set | 1.3.1 |
new Map() | map | 1.2.0 |
new WeakMap() | map | 1.3.1 |
new Int8Array(8) | typedarray | 1.3.0 |
new Uint8Array() | typedarray | 1.3.0 |
new Uint8ClampedArray() | typedarray | 1.3.0 |
new Int16Array() | typedarray | 1.3.0 |
new Uint16Array() | typedarray | 1.3.0 |
new Int32Array() | typedarray | 1.3.0 |
new Uint32Array() | typedarray | 1.3.0 |
new Float32Array() | typedarray | 1.3.0 |
new Float64Array() | typedarray | 1.3.0 |
new BigInt64Array() | typedarray | 1.3.0 |
new BigUint64Array() | typedarray | 1.3.0 |
Promise.resolve('any') | promise | 1.4.0 |
function* () {} | generatorfunction | 1.4.1 |
(function* () {})() | generator | 1.4.1 |
new ArrayBuffer(8) | arraybuffer | 1.5.0 |
new DataView(buffer) | dataview | 1.5.0 |
Install
![https://nodei.co/npm/@lopatnov/get-internal-type.png?downloads=true&downloadRank=true&stars=true](https://nodei.co/npm/@lopatnov/get-internal-type.png?downloads=true&downloadRank=true&stars=true)
npm install @lopatnov/get-internal-type
Browser
<script src="//lopatnov.github.io/get-internal-type/dist/polyfills/array.forEach.min.js"></script>
<script src="//lopatnov.github.io/get-internal-type/dist/get-internal-type.min.js"></script>
Browser support: Cross-browser
Import package to the project
TypeScript
import getInternalType from 'get-internal-type';
JavaScript
var getInternalType = require("get-internal-type");
Gets object type
getInternalType(obj: any) => string
console.log(getInternalType(undefined))
console.log(getInternalType(null))
console.log(getInternalType(false))
console.log(getInternalType(Symbol("123")))
console.log(getInternalType(123))
console.log(getInternalType(BigInt(9007199254740991)))
console.log(getInternalType("hello"))
console.log(getInternalType(/s+/gi))
console.log(getInternalType(new Date()))
console.log(getInternalType(new Error("A mistake")))
console.log(getInternalType({}))
console.log(getInternalType(new (class SomeCustomClass {})))
console.log(getInternalType(() => {}))
console.log(getInternalType(function(){}))
console.log(getInternalType(class Simple {}))
console.log(getInternalType([1,2,3]))
console.log(getInternalType(new Set()))
console.log(getInternalType(new WeakSet()))
console.log(getInternalType(new Map()))
console.log(getInternalType(new WeakMap()))
console.log(getInternalType(new Int8Array(8)))
console.log(getInternalType(new Uint8Array()))
console.log(getInternalType(new Uint8ClampedArray()))
console.log(getInternalType(new Int16Array()))
console.log(getInternalType(new Uint16Array()))
console.log(getInternalType(new Int32Array()))
console.log(getInternalType(new Uint32Array()))
console.log(getInternalType(new Float32Array()))
console.log(getInternalType(new Float64Array()))
console.log(getInternalType(new BigInt64Array()))
console.log(getInternalType(new BigUint64Array()))
console.log(getInternalType(Promise.resolve('any')))
console.log(getInternalType(function* () {}))
console.log(getInternalType((function* () {})()))
console.log(getInternalType(new ArrayBuffer(16)))
console.log(getInternalType(new DataView(new ArrayBuffer(16))))
Demo
See, how it's working: https://runkit.com/lopatnov/get-internal-type-demo
Test it with a runkit: https://npm.runkit.com/%40lopatnov%2Fget-internal-type
Rights and Agreements
License Apache-2.0
Copyright 2019-2021 Oleksandr Lopatnov