@nbsh/to-type
Fixes JavaScript typeof operator using Symbol.toStringTag
Last updated 5 years ago by rannn505 .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install @nbsh/to-type 
SYNC missed versions from official npm registry.

to-type

Fixes JavaScript typeof operator using Symbol.toStringTag

Installation

$ npm i -S @nbsh/to-type
$ yarn add @nbsh/to-type

Usage

import { strictEqual } from 'assert';
import { toType, Types } from '@nbsh/to-type';

toType(4); // "number"
toType('abc'); // "string"
toType(true); // "boolean"
toType({ a: 4 }); // "object"
toType([1, 2, 3]); // "array"
toType(new Date()); // "date"
toType(/a-z/); // "regexp"
toType(undefined); // "undefined"
toType(null); // "null"
toType(new TypeError()); // "error"
toType(() => {}); // "function"

strictEqual(toType(4), Types.Number); // true
strictEqual(toType('abc'), Types.String); // true

API

toType(object: unknown): string

The toType() method return the default string description of the object it receive as argument. toType() do not affect the object itself. See Symbol.toStringTag.

Types: enum

The Types enum represent the well-known string descriptions that toType() method return. Note, implementing a class that overrides the toStringTab symbol will not make its value available within this enum.

Current Tags

  • 5.0.0-next.1                                ...           latest (5 years ago)
  • 5.0.0-next.1                                ...           next (5 years ago)

1 Versions

  • 5.0.0-next.1                                ...           5 years ago
Maintainers (1)
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (0)
None
Dependents (2)

© 2010 - cnpmjs.org x YWFE | Home | YWFE