make-object-path
Creates an object structure based on a Path defined in an Array structure or String written in dot notation, e.g. 'objParent.objChild.objDeep', or with any delimiter that can be defined as a parameter, e.g. 'objParent|objChild|objDeep'. It can return a new object or create the path into an existing one. A value can be defined to be set into the deepest object's property.
Node.js and Browser ready.
Installation
npm install make-object-path
Usage / Examples
String path
const makeObjectPath = ; // Creating the path without setting any value to the property const result = ; // result: // { // "root":{ // "parent":{ // "child": undefined // } // } // } // Creating the path setting a value to the property + defining a different delimiter const result = ; // result: // { // "root":{ // "parent":{ // "child": "someValue" // } // } // }
Array path
const makeObjectPath = ; var variableToBePropertyName = 'propertyName';var existentObject = "someProperty": null; // Creating the path into an existing objectconst result = ; // result://{// "someProperty":null,// "propertyName":{// "createdBy":{// "variable": true// }// }//}