JSPM

realtypeof

1.2.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q32888F
  • License MIT

You can get the real type of values (i.e. array, null, object, map, set, etc.)

Package Exports

  • realtypeof

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (realtypeof) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

realtypeof

This is a very simple and light package to get the real type of values.

Installation

$ npm install realtypeof

Usage

const realTypeOf = require('realtypeof');

realTypeOf(45);             // 'number'
realTypeOf('hello');        // 'string'
realTypeOf(true);           // 'boolean'
realTypeOf(null);           // 'null'
realTypeOf(undefined);      // 'undefined'
realTypeOf(Symbol());       // 'symbol'
realTypeOf([]);             // 'array'
realTypeOf(() => {});       // 'function'
realTypeOf({});             // 'object'
realTypeOf(new Map());      // 'map'
realTypeOf(new Set());      // 'set'
realTypeOf(new WeakMap());  // 'weakmap'
realTypeOf(new WeakSet());  // 'weakset'

The type of returned value is always string

You can also check the type of value whether it is a particular type:

realTypeOf.isNumber(45);              // true
realTypeOf.isString('hello');         // true
realTypeOf.isBoolean(true);           // true
realTypeOf.isNull(null);              // true
realTypeOf.isUndefined(undefined);    // true
realTypeOf.isSymbol(Symbol());        // true
realTypeOf.isArray([]);               // true
realTypeOf.isFunction(() => {});      // true
realTypeOf.isObject({});              // true
realTypeOf.isMap(new Map());          // true
realTypeOf.isSet(new Set());          // true
realTypeOf.isWeakMap(new WeakMap());  // true
realTypeOf.isWeakSet(new WeakSet());  // true

The type of returned value of these methods is always boolean