Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/rocktimsaikia/flatify-obj

Flatten nested javascript objects into a single-depth object.
https://github.com/rocktimsaikia/flatify-obj

flat-objects flattened-objects npm-package objects

Last synced: about 2 months ago
JSON representation

Flatten nested javascript objects into a single-depth object.

Awesome Lists containing this project

README

        

# flatify-obj ![build](https://travis-ci.com/RocktimSaikia/flatify-obj.svg?branch=master)
> Flatten nested javascript objects into a single-depth object.

## Install
```bash
$ npm install flatify-obj
```

## Usage

```js
const flatifyObject = require('flatify-obj');

flatifyObject({foo: {bar: {unicorn: '🦄'}}})
//=> { 'foo.bar.unicorn': '🦄' }

flatifyObject({foo: {unicorn: '🦄'}, bar: 'unicorn'}, {onlyLeaves: true});
//=> {unicorn: '🦄', bar: 'unicorn'}
```

## API

### flatifyObject(object, options?)

#### object

Type: `object`

Object to flatten

#### options

##### onlyLeaves

Type: `boolean`

Default: `false`

Removes the parent property and only returns the leaf nodes of the object

## License

MIT © [Rocktim Saikia](https://rocktim.xyz/)