@ganuz/copy-property
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

@ganuz/copy-property

Source Code Version MIT License Bundle Size TypeScript

Copy Property is package from Ganuz library

Install

$ yarn add @ganuz/copy-property

Or

$ npm install --save @ganuz/copy-property

Use

Module

import {
  default as copyProperty
} from '@ganuz/copy-property';

Browser

<script src="https://unpkg.com/@ganuz/copy-property/bundle.umd.min.js"></script>
let {
  copyProperty
} = G;

Examples

 copyProperty(null, 'foo', {}); // throw TypeError
 copyProperty({}, 'foo', {}); // => false
 copyProperty({}, Symbol.for('foo'), {[Symbol.for('foo')]: 'bar'}); // => true
 copyProperty({}, 'a', ['A'], 1); // => true
 copyProperty({color: 'red'}, 'color', class {static color = 'blue'; }); // => true
 copyProperty(Object.seal({name: 'bob'}), 'name', {color: 'alice'}); // => false
 copyProperty(Object.create({}, {num: {value: -1}}), 'num', {num: 17}); // => false
 let colorSym = Symbol('color');
 let target = {};
 let source = Object.create({}, {
    color: { set(color){ this[colorSym] = color; }, enumerable: true},
    [colorSym]: {value: 'black', writable: true}
 });

 copyProperty(target, '_color', source, 'color'); // => true
 copyProperty(target, colorSym, source); // => true

 target._color = 'pink';
 source.color = 'blue';

 console.log(source[colorSym]); // => 'blue'

 Object.getOwnPropertyDescriptors(target);
 // => {_color: {
 //      get: undefined, set(color){ this[colorSym] = color; }, enumerable: true, configurable: false
 // }, [colorSym]: {
 //      value: 'pink', writable: true, enumerable: false, configurable: false
 // }}

License

Copyright © Yisrael Eliev, Licensed under the MIT license.

Package Sidebar

Install

npm i @ganuz/copy-property

Weekly Downloads

3

Version

0.1.1

License

MIT

Unpacked Size

97.9 kB

Total Files

15

Last publish

Collaborators

  • yisraelx