Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

q-flat

DylanPiercey17.8kMIT1.0.7TypeScript support: included

Flatten a nested object using query string syntax.

flatten, q-set, querystring

readme


Q-Flat
API Stability TypeScript Styled with prettier Build status Test Coverage NPM Version Downloads Browser Bundle Size

Flatten a nested object using query string syntax.

Installation

Npm

npm install q-flat

API

qflat.flatten(obj: any): any

  • Converts a nested object into a shallow one with keys using query string syntax.
import { flatten } from 'q-flat';

// Flatten nested objects.
flatten({ a: { b: { c: { 1 } } }); // -> { "a[b][c]": 1 }

// Even flatten arrays.
flatten({ a: [{ b: 1 }, { c: 2 }] }); // -> { 'a[0][b]': 1, 'a[1][c]': 2 }

Contributions

  • Use npm test to build and run tests.

Please feel free to create a PR!