Skip to content

crush

Flattens a deep object to a single dimension

290 bytes

Usage

Flattens a deep object to a single dimension. The deep keys will be converted to a dot notation in the new object.

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