realtypeof

1.2.0 • Public • Published

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

/realtypeof/

    Package Sidebar

    Install

    npm i realtypeof

    Weekly Downloads

    2

    Version

    1.2.0

    License

    MIT

    Unpacked Size

    3.94 kB

    Total Files

    4

    Last publish

    Collaborators

    • babak.gh