/nest-deep

A utility library to convert between nested and flattened objects.

Primary LanguageTypeScriptMIT LicenseMIT

nest-deep

Usage

import { nested, flatten } from 'nest-deep';

nested({
  'a.b': 1,
  'c.d[0][0]': 1,
  'c.d[1]': 5,
  'c.d[2]': 12,
});

flatten({
  a: {
    b: 1,
  },
  c: {
    d: [[1], 5, 12],
  },
});

Output

nested
{
  "a": {
    "b": 1
  },
  "c": {
    "d": [[1], 5, 12]
  }
}
flatten
{
  "a.b": 1,
  "c.d[0][0]": 1,
  "c.d[1]": 5,
  "c.d[2]": 12
}