7.1.2 • Published 5 years ago
@ezy/object-description v7.1.2
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.values) {
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({
Ctor: desc.Ctor,
values: desc.values.map(({ path, value }) => {
return { path, value: value.toString() };
})
});
console.log(stringified);
// {
// value: "true",
// lvl1: {
// lvl2: [
// [ undefined, { 50: "false" } ]
// ]
// }
// }
circular references support
deep clone made easy
import {
from as fromDescription,
to as toDescription
} from '@ezy/object-description';
const original: any = {
someprop: 'something'
};
original.imcircular = original;
const desc = toDescription(original);
console.log(desc);
// => {
// Ctor: Object,
// values: [{ path: ['someprop'], value: 'something' }],
// references: [{ path: ['imcircular'], target: [] }]
// }
const clone = fromDescription(desc);
console.log(clone);
// => {
// someprop: 'something',
// imcircular: [Circular]
// }
Links
See also
7.1.2
5 years ago
7.1.1
5 years ago
7.1.0
5 years ago
7.0.0
5 years ago
6.1.0
5 years ago
6.0.0
5 years ago
5.0.0
5 years ago
4.1.0
5 years ago
4.0.1
5 years ago
4.0.0
5 years ago
3.0.1
5 years ago
3.0.0
6 years ago
2.0.6
6 years ago
2.0.5
6 years ago
2.0.4
6 years ago
2.0.3
6 years ago
2.0.2
6 years ago
2.0.1
6 years ago
2.0.0
6 years ago
1.0.3
6 years ago
1.0.2
6 years ago
1.0.1
6 years ago