JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 46
  • Score
    100M100P100Q89814F
  • License MIT

a more robust representation for flatten objects

Package Exports

  • @ezy/object-description

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@ezy/object-description) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

object description

a more robust representation for flatten objects/arrays.

License CircleCI codecov Docs: typedoc GitHub issues Maintainability Dependencies status Dev Dependencies status Made with: typescript Code style: prettier Runkit: try now minified size minzipped size

Why

flatten/unflatten libraries relies on string based notation for paths leading to mismatches in conversions.

Install

npm i @ezy/object-description

Usage

iterate over values

import { to as toDescription } from '@ezy/object-description';

const desc = toDescription({
  value: true,
  lvl1: {
    lvl2: [[undefined, { 50: false }]]
  }
});

for (const { path, value } of desc.primitives) {
  console.log(path);
  console.log(value);
}

// ['value']
// true
// ['lvl1', 'lvl2', 0, 1, '50']
// false

change all values

import {
  from as fromDescription,
  to as toDescription
} from '@ezy/object-description';

const desc = toDescription({
  value: true,
  lvl1: {
    lvl2: [[undefined, { 50: false }]]
  }
});

const stringified = fromDescription({
  is_array: desc.is_array,
  primitives: desc.primitives.map(({ path, value }) => {
    return { path, value: value.toString() };
  })
});

console.log(stringified);

// {
//     value: "true",
//     lvl1: {
//         lvl2: [
//             [ undefined, { 50: "false" } ]
//         ]
//     }
// })

See also