0.1.1 • Published 6 years ago
@ganuz/construct v0.1.1
@ganuz/construct
Construct is package from Ganuz library
Install
$ yarn add @ganuz/construct
Or
$ npm install --save @ganuz/construct
Use
Module
import {
default as construct
} from '@ganuz/construct';
Browser
<script src="https://unpkg.com/@ganuz/construct/bundle.umd.min.js"></script>
let {
construct
} = G;
Examples
class A{
public color: string;
constructor(public a: string){}
}
A.prototype.color = 'blue';
class B{
public color: string;
constructor(public b: string){}
}
B.prototype.color = 'red';
construct(v => v, []); // throw TypeError('target...')
construct(A, void 0, B); // throw TypeError('args...')
construct(A, [], v => v); // throw TypeError('newTarget...')
construct(function C(...args){this.args = args;}, [1, 2, 3]); // => A{args: [1, 2, 3]}
construct(function D(){ return 'foo'; }, [], function E(){}); // => E{}
construct(function F(){ return Object('foo'); }, [], function G(){}); // => String('foo')
construct(function H(){ this.h = this instanceof H;}, [], function I(){}); // => I{h: false}
construct(A, {0: 1, length: '1'}); // => A{color: 'blue', a: 1}
construct(A, [2], B); // => B{color: 'red', a: 2}
let logInstanceOf = construct(Function, ['instance, Constructor', 'console.log(instance instanceof Constructor);'], A);
logInstanceOf.length; // => 2
logInstanceOf(logInstanceOf, A); // => true
logInstanceOf(logInstanceOf, Function); // => false
typeof logInstanceOf === 'function'; // => true
let b = construct(Array, [5], B);
b instanceof A; // => true
b instanceof B; // => true
b instanceof Array; // => false
Array.isArray(b); // => true
String(b); // => '[object Array]';
b.color; // => 'red'
b.length; // => 5
b[9] = 6;
b.length; // => 10
@ganuz/construct/polyfill
Module
import '@ganuz/construct/polyfill';
Browser
<script src="https://unpkg.com/@ganuz/construct/polyfill/bundle.umd.min.js"></script>
License
Copyright © Yisrael Eliev, Licensed under the MIT license.