Skip to content

construct
693 bytes

Builds an object from key paths and values

Usage

The opposite of crush, given an object that was crushed into key paths and values will return the original object reconstructed.

import * as _ from 'radashi'
const flat = {
name: 'ra',
power: 100,
'friend.name': 'loki',
'friend.power': 80,
'enemies.0.name': 'hathor',
'enemies.0.power': 12,
}
const reconstructed = _.construct(flat)
// {
// name: 'ra',
// power: 100,
// friend: {
// name: 'loki',
// power: 80
// },
// enemies: [
// {
// name: 'hathor',
// power: 12
// }
// ]
// }