1.2.0 • Published 3 years ago

realtypeof v1.2.0

Weekly downloads
4
License
MIT
Repository
github
Last release
3 years ago

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