Installation
$ npm install flat-object
Methods
flatten({ data })
Returns an array of "flattened" paths for the Object specified.
const data = nestedArray: 'string' boolean: true string: 'yes' // "nestedArray[0]", "nestedArray[1]", "nestedArray[1].boolean", "nestedArray[1].string"
read({ data, path })
Returns the property value of the flattened path or undefined if the property does not exist.
const data = name: 'Example' nestedArray: id: 1 id: 2 // "Example" // 2
write({ data, path, value })
Writes a value to the specified path. This method just-in-time creates any missing properties along the specified path.
This method will throw an error if an Array value is specified for a property containing an Object (or vice versa).
const data = {} // data == { name: "Example" } // data == { name: "Example", address: { street: "123 Bird Ave" } } // Throws error (since address is already defined as an Object)