flatten-unflatten

1.0.0 • Public • Published

flatten-unflatten

package version package downloads standard-readme compliant package license make a pull request

Flatten or unflatten a object

Table of Contents

Install

This project uses node and npm.

$ npm install flatten-unflatten
# OR 
$ yarn add flatten-unflatten

Usage

import {flatten, unflatten} from 'flatten-unflatten'
 
const foo = {
  bar: 5,
  baz: {
    bar: 1,
    foo: {
      ping: 'pong',
      arr: [1, 3, 4, 5]
    }
  }
}
 
const flatFoo = flatten(foo)
console.log(flatFoo) // {bar: 5, baz.bar: 1, baz.foo.ping: "pong", baz.foo.arr: Array[4]}
 
const starryFlatFoo = flatten(foo, { delimiter: '*' })
console.log(starryFlatFoo) // {bar: 5, baz*bar: 1, baz*foo*ping: "pong", baz*foo*arr: Array[4]}
console.log(flatten(foo, { arrays: true })) // {bar: 5, baz.bar: 1, baz.foo.ping: "pong", baz.foo.arr.0: 1, baz.foo.arr.1: 3…}
 
console.log(unflatten(flatFoo)) // {bar: 5, baz: Object}
console.log(unflatten(starryFlatFoo, { delimiter: '*' })) // {bar: 5, baz: Object}
 

Contribute

  1. Fork it and create your feature branch: git checkout -b my-new-feature
  2. Commit your changes: git commit -am 'Add some feature'
  3. Push to the branch: git push origin my-new-feature
  4. Submit a pull request

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i flatten-unflatten

Weekly Downloads

117

Version

1.0.0

License

MIT

Unpacked Size

17.2 kB

Total Files

11

Last publish

Collaborators

  • tiaanduplessis