https://github.com/ericadamski/dot-mutation
👷‍♀️Composition and Decomposition of JavaScript Objects using dot notation
https://github.com/ericadamski/dot-mutation
dot-notation object-manipulation
Last synced: 3 months ago
JSON representation
👷‍♀️Composition and Decomposition of JavaScript Objects using dot notation
- Host: GitHub
- URL: https://github.com/ericadamski/dot-mutation
- Owner: ericadamski
- License: mit
- Created: 2018-04-18T14:05:19.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-04-18T15:20:15.000Z (about 7 years ago)
- Last Synced: 2025-01-06T09:45:28.289Z (5 months ago)
- Topics: dot-notation, object-manipulation
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/dot-mutation
- Size: 35.2 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# dot-mutation
👷‍♀️Composition and Decomposition of JavaScript Objects using dot notation.
## Install
yarn
```
yarn add dot-mutation
```or npm
```
npm i dot-mutation
```## Usage
[](https://codesandbox.io/s/zn666qqwl?autoresize=1&module=%2Fsrc%2Findex.js)
**deconstruct**
```javascript
function deconstruct(o: Object): Object
```Returns a single level deep JavaScript Object where each key is a path, using dot notation, to the value of the input Object.
**construct**
```javascript
function construct(o: Object): Object
```Returns a JavaScript Object where each key from the input Object is a path description to the output object. (ie. for input Object `o` a key of `o['a.b.c']` results in a path of `o.a.b.c`)
```javascript
const { construct, deconstruct } = require('dot-mutation');const obj = {
a: {
b: {
c: 'value'
},
d: [
{
nested: 'values'
}
]
},
e: 'value'
};console.log(deconstruct(obj));
// Outputs
// ===================
// {
// 'a.b.c': 'value',
// 'a.d': [
// {
// nested: 'values'
// }
// ],
// 'e' : 'value'
// }const deconstructed = {
'a.b.c': 'value',
'a.d': [
{
nested: 'values'
}
],
e: 'value'
};console.log(construct(deconstructed));
// Outputs
// ===================
// {
// a: {
// b: {
// c: 'value'
// }
// d: [
// {
// nested: 'values'
// }
// ]
// },
// e: 'value'
// }
```