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

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

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

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

## Use
**Module**
```typescript
import {
  IDefinePropertyWithCallback,
  default as definePropertyWith
} from '@ganuz/define-property-with';
```

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

**Examples**
```typescript
 definePropertyWith(null, 'prop', {}, v => v); // throw TypeError
 definePropertyWith({}, 'prop', {}, () => {}); // => false
 definePropertyWith({}, 'prop', 'data', () => {}); // => false
 definePropertyWith({}, 'num', 77, (o, n) => n); // => false
 definePropertyWith({}, 'cup', {value: 'tea'}, o => o); // => false
 definePropertyWith(Object.freeze({}), 'num', {value: 55}, (o, n) => n); // => false
 definePropertyWith(Object.create({}, {str: {value: 'cool'}}), 'str', {value: 'fun'}, (o, n) => n); // => false

 let object = {};
 definePropertyWith(object, 'prop', {}, (old, n) => n); // => true
 console.log(object); // => {prop: undefined}

 let object2 = {};
 definePropertyWith(object2, 'foo', {value: 'bar'}, (old, n) => n); // => true
 console.log(object2); // => {foo: 'bar'}

 let object3 = {};
 definePropertyWith(object3, 'foo', 'bar', (old, value) => ({value})); // => true
 console.log(object3); // => {foo: 'bar'}

 let object4 = {color: 'pink'};
 definePropertyWith(object4, 'color', {value: 'green'}, old => old); // => true
 console.log(object4); // => {color: 'pink'}

 let object5 = {color: 'red'};
 definePropertyWith(object5, 'color', {value: 'blue'}, () => {}); // => true
 console.log(object5); // => {color: 'blue'}

 let object6 = {color: 'yellow', _default: 'black'};
 definePropertyWith(object6, 'color', 'pink', (o, n, p, t) => {value: n === 'pink' ? t['_default']: n}); // => true
 console.log(object6); // => {color: 'black'}

 let object7 = {numbers: [0, 2]};
 definePropertyWith(object7, 'numbers', {value: [4, 6]}, ({value: o}, {value: n}) => Array.isArray(n) && o.push(...n)); // => true
 console.log(object7); // => {numbers: [0, 2, 4, 6]}
```


## License
Copyright © [Yisrael Eliev](https://github.com/yisraelx),
Licensed under the [MIT license](https://github.com/yisraelx/ganuz/blob/master/LICENSE).