Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aneldev/dyna-object-assign
Assign objects like `Object.assign` but it doesn't override undefined values. It doesn't mutate the object it returns a new one.
https://github.com/aneldev/dyna-object-assign
Last synced: 1 day ago
JSON representation
Assign objects like `Object.assign` but it doesn't override undefined values. It doesn't mutate the object it returns a new one.
- Host: GitHub
- URL: https://github.com/aneldev/dyna-object-assign
- Owner: aneldev
- License: mit
- Created: 2018-10-16T08:18:20.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-09T05:22:30.000Z (almost 2 years ago)
- Last Synced: 2024-10-05T21:15:58.173Z (about 1 month ago)
- Language: JavaScript
- Size: 3.67 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 21
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# About
Assign objects like `Object.assign` but
- it doesn't override with undefined values
- it doesn't mutate the object it returns a new one.Written in TypeScript.
# With `Object.assign` we have
```
> objA = { name: "John", age: 32, address: undefined, city: null }
{ name: 'John', age: 32, address: undefined, city: null }> objB = { address: "Lungerstrasse 12" }
{ address: 'Lungerstrasse 12' }> Object.assign({}, objA, objB) // or
> { ...objA, ...objB }
{ name: 'John', age: 32, address: 'Lungerstrasse 12', city: null }
// perfect// now let's try the objB with an undefined value
> objB = { age: undefined, address: "Lungerstrasse 12" }
{ age: undefined, address: 'Lungerstrasse 12' }> { ...objA, ...objB }
{ name: 'John',
age: undefined,
address: 'Lungerstrasse 12',
city: null }
// the age here in overriden, this is correct... but in some cases not what we want```
# With `dynaObjectAssign`
```
> objA = { name: "John", age: 32, address: undefined, city: null }
{ name: 'John', age: 32, address: undefined, city: null }> objB = { age: undefined, address: "Lungerstrasse 12" }
{ age: undefined, address: 'Lungerstrasse 12' }> dynaObjectAssign(objA. objB)
{ name: 'John',
age: 32, // it is still 32 and overriden with undefined
address: 'Lungerstrasse 12',
city: null }
```# Equivalents syntax of `dynaObjectAssign`
```
dynaObjectAssign(objA, objB) --> Object.assign({}, objA, objB)
dynaObjectAssign(objA, objB) --> {...objA, ...objB}```
# dynaObjectAssign signature
`dynaObjectAssign = (...objs: Partial[]) => T`