npm package: @ganuz/define-properties-with
Description: Define Properties With is package from Ganuz library
Author: Yisrael Eliev
Latest version: 0.1.1

# @ganuz/define-properties-with
[![Source Code](https://img.shields.io/badge/%3C%2F%3E-source_code-blue.svg)](https://github.com/yisraelx/ganuz/blob/master/modules/define-properties-with)
[![Version](https://img.shields.io/npm/v/@ganuz/define-properties-with.svg)](https://www.npmjs.com/package/@ganuz/define-properties-with)
[![MIT License](https://img.shields.io/npm/l/@ganuz/define-properties-with.svg?color=yellow)](https://github.com/yisraelx/ganuz/blob/master/LICENSE)
[![Bundle Size](https://img.shields.io/bundlephobia/min/@ganuz/define-properties-with.svg?color=green)](https://bundlephobia.com/result?p=@ganuz/define-properties-with)
[![TypeScript](https://img.shields.io/badge/100%25-TypeScript-blue.svg)](https://www.typescriptlang.org)

**Define Properties With is package from Ganuz library**

## Install
```sh
$ yarn add @ganuz/define-properties-with
```
Or
```sh
$ npm install --save @ganuz/define-properties-with
```

## Use
**Module**
```typescript
import {
  default as definePropertiesWith
} from '@ganuz/define-properties-with';
```

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

**Examples**
```typescript
 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}
```
```typescript
 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](https://github.com/yisraelx),
Licensed under the [MIT license](https://github.com/yisraelx/ganuz/blob/master/LICENSE).