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
a more robust representation for flatten objects/arrays.
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" } ]
// ]
// }
// })