@ganuz/define-properties-with
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

@ganuz/define-properties-with

Source Code Version MIT License Bundle Size TypeScript

Define Properties With is package from Ganuz library

Install

$ yarn add @ganuz/define-properties-with

Or

$ npm install --save @ganuz/define-properties-with

Use

Module

import {
  default as definePropertiesWith
} from '@ganuz/define-properties-with';

Browser

<script src="https://unpkg.com/@ganuz/define-properties-with/bundle.umd.min.js"></script>
let {
  definePropertiesWith
} = G;

Examples

 definePropertiesWith(null, {}, () => {}); // throw TypeError
 definePropertiesWith({}, {foo: {value: 'bar', get: () => 'bar'}}, () => {}); // throw TypeError
 definePropertiesWith({foo: 'bar'}, {}, () => {}); // => {foo: 'bar'};
 definePropertiesWith({}, {foo: {value: 'bar'}}, (o, n) => ({...n, get: () => 'bar'})); // => {}
 definePropertiesWith({jeep: false, name: 'alice'}, {name: {value: 'moshe'}, str: 'cool', num: {value: 94}}, () => NaN); // => {jeep: false, name: 'moshe', num: 94}
 definePropertiesWith({color: 'red'}, {color: 'blue'}, (o, value) => ({value})); // => {color: 'blue'};
 definePropertiesWith(Object.seal({name: 'bob'}), {foo: 'bar', name: 'guy'}, (o, value) => ({value})); // => {name: 'guy'};
 definePropertiesWith({drink: 'tea'}, {drink: 'beer', car: true}, (o, n) => {value: o && o.value || n}); // => {drink: 'tea', car: true};
 definePropertiesWith(Object.freeze({car: true}), {foo: {value: 'bar', car: {value: false}}}, (o, n) => n); // => {car: true}
 let object = definePropertiesWith({}, {name: 'bob', color(){ return 'red'; }, (o, n) => ({[isFunction(n) ? 'get' : 'value']: n, configurable: true}));

 Object.getOwnPropertyDescriptor(object); // => {
 //   name: {value: 'bob', configurable: true, enumerable: false, writable: false},
 //   color: {get: color(){ return 'red'; }, set: undefined, configurable: true, enumerable: false}
 // }

 definePropertiesWith(object, {[Symbol('foo')]: 'bar', name(){ return 'alice' }, color: 'blue'}, (o, n) => ({[isFunction(n) ? 'get' : 'value']: n, enumerable: true}) === object; // => true

 Object.getOwnPropertyDescriptor(object); // => {
 //   name: {get: name(){ return 'alice'; }, set: undefined, configurable: true, enumerable: true},
 //   color: {value: 'blue', configurable: true, enumerable: true, writable: false},
 //   [Symbol('foo')]: {value: 'bar', configurable: false, enumerable: true, writable: false}
 // }

License

Copyright © Yisrael Eliev, Licensed under the MIT license.

Package Sidebar

Install

npm i @ganuz/define-properties-with

Weekly Downloads

3

Version

0.1.1

License

MIT

Unpacked Size

101 kB

Total Files

15

Last publish

Collaborators

  • yisraelx