crush
@guoba-ai/utils / object / crush
Function: crush()
function crush(obj): Record<string, unknown>;Defined in: object.ts:437
Flatten a deeply nested object into a single-level object with dot-path keys. Arrays are treated as leaf values and are not flattened.
Parameters
obj
object
The object to flatten
Returns
Record<string, unknown>
A flat object with dot-path keys
Example
crush({ a: { b: 1, c: { d: 2 } } })
// { 'a.b': 1, 'a.c.d': 2 }
crush({ x: 1, y: 2 }) // { x: 1, y: 2 }
crush({ a: { b: [1, 2, 3] } }) // { 'a.b': [1, 2, 3] }