@ganuz/is-instance-of
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

@ganuz/is-instance-of

Source Code Version MIT License Bundle Size TypeScript

Is Instance Of is package from Ganuz library

Install

$ yarn add @ganuz/is-instance-of

Or

$ npm install --save @ganuz/is-instance-of

Use

Module

import {
  default as isInstanceOf
} from '@ganuz/is-instance-of';

Browser

<script src="https://unpkg.com/@ganuz/is-instance-of/bundle.umd.min.js"></script>
let {
  isInstanceOf
} = G;

Examples

 isInstanceOf('foo', null); // throw TypeError
 isInstanceOf('foo', {}); // throw TypeError
 isInstanceOf('foo', class { static [Symbol.hasInstance] = 'foo'; }}); // throw TypeError
 isInstanceOf(NaN, Number); // => false
 isInstanceOf({}, Object); // => true
 isInstanceOf(Object.create(null), Object); // => false
 isInstanceOf('some', {[Symbol.hasInstance]: (v) => v === 'some'}); // => true
 let iframe = document.createElement('iframe');
 document.body.appendChild(iframe);
 let {Array: IFrameArray, Object: IFrameObject, Symbol: IFrameSymbol} = iframe.contentWindow;

 isInstanceOf([], IFrameArray); // => false

 // Note: In native `Symbol` ({Symbol.hasInstance]: 'S'})[IFrameSymbol.hasInstance] === 'S', but in most es6 `Symbol` polyfill ({Symbol.hasInstance]: 'S'})[IFrameSymbol.hasInstance] !== 'S' (in that case it will be `false`).
 isInstanceOf('some', Object.create(IFrameObject.prototype, {[IFrameSymbol.hasInstance]: {value: (v) => v === 'some'}})); // => true

@ganuz/is-instance-of/assert

Module

import {
  default as assertInstanceOf
} from '@ganuz/is-instance-of/assert';

Browser

<script src="https://unpkg.com/@ganuz/is-instance-of/assert/bundle.umd.min.js"></script>
let {
  assertInstanceOf
} = G;

Examples

 assertInstanceOf(null, Object); // throw TypeError
 assertInstanceOf([], Function); // throw TypeError
 assertInstanceOf({}, String); // throw TypeError
 assertInstanceOf(['a', 'b', 'c'], Array); // => ['a', 'b', 'c']
 assertInstanceOf(/^[a-z]+$/i, RegExp); // => /^[a-z]+$/i

License

Copyright © Yisrael Eliev, Licensed under the MIT license.

/@ganuz/is-instance-of/

    Package Sidebar

    Install

    npm i @ganuz/is-instance-of

    Weekly Downloads

    2

    Version

    0.1.1

    License

    MIT

    Unpacked Size

    60.5 kB

    Total Files

    27

    Last publish

    Collaborators

    • yisraelx