0.2.1 • Published 5 years ago

@pakal/kind-of v0.2.1

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

@pakal/kind-of

Source Code Version MIT License Bundle Size TypeScript

Kind Of is package from Pakal library

Install

$ yarn add @pakal/kind-of

Or

$ npm install --save @pakal/kind-of

Use

Module

import {
  default as kindOf
} from '@pakal/kind-of';

Browser

<script src="https://unpkg.com/@pakal/kind-of/bundle.umd.min.js"></script>
let {
  kindOf
} = _;

Examples

 kindOf(null); // => 'null'
 kindOf(class {}); // => 'function'
 kindOf(NaN); // => 'number'
 kindOf(Object('foo')); // => 'string'
 kindOf(String.prototype); // => 'object'
 kindOf(Object.create(v => v)); // => 'object'
 kindOf(Object.freeze({[Symbol.toStringTag]: 'Number'})); // => 'object'

 // In env that not have native support.
 let fooSym = Symbol('foo');
 typeof fooSym; // => 'object'
 kindOf(fooSym); // => 'symbol'
 let bigNum = BigInt(1);
 typeof bigNum; // => 'object'
 kindOf(bigNum); // => 'bigint'
 let iframe = document.createElement('iframe');
 document.body.appendChild(iframe);
 let {String: IFrameString} = iframe.contentWindow;
 kindOf(new IFrameString('foo')); // => 'string'

Note: if Symbol or BigInt is not native (polyfill), the kind will base on Symbol.toStringTag property, if value not has Symbol.toStringTag property it's will be returns that the kind is 'object'.

License

Copyright © Yisrael Eliev, Licensed under the MIT license.