https://github.com/writetome51/get-object-modified
Function merges one object into another and returns new, modified object
https://github.com/writetome51/get-object-modified
clone copy javascript modify object typescript
Last synced: 12 months ago
JSON representation
Function merges one object into another and returns new, modified object
- Host: GitHub
- URL: https://github.com/writetome51/get-object-modified
- Owner: writetome51
- License: mit
- Created: 2019-08-05T18:11:16.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-02-28T02:37:16.000Z (almost 5 years ago)
- Last Synced: 2025-02-15T03:45:48.562Z (12 months ago)
- Topics: clone, copy, javascript, modify, object, typescript
- Language: TypeScript
- Size: 9.77 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# getObjectModified(
object,
changes: object
): object
Returns a new copy of `object` with `changes` merged into it.
Neither of the two arguments get modified. Prototype chain stays intact.
## Examples
```js
let obj = {prop1: 10, prop2: 20, prop3: 30};
let changes = {prop1: 100, prop2: 200, prop4: 1000};
getObjectModified(obj, changes);
// --> {prop1: 100, prop2: 200, prop3: 30, prop4: 1000}
obj = {prop1: 10, prop2: 20};
changes = {
prop1: 100,
prop3: function () {
return this.prop1 + this.prop2;
}
};
let newObj = getObjectModified(obj, changes);
console.log(newObj.prop3());
// console: '120'
```
## Installation
```bash
npm i @writetome51/get-object-modified
```
## Loading
```js
import {getObjectModified} from '@writetome51/get-object-modified';
```