Skip to content

Make nested javascript object from string representation.

Notifications You must be signed in to change notification settings

backendsuraj/stringto-object

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Stringto-object

Make nested javascript object from string representation.

Installation

npm i @backendsuraj/stringto-object --save

Usage

const string2object = require('@backendsuraj/stringto-object');

string2object.getObject("users.details.phone", '91987***321')
// { users: { details: { phone: '91987***321' } } }

//using for loop
let elements = [{
    "user_phone": {
        "object_definition": {
            "string": "users.details.phone",
            "data": "91987***321"
        }
    },
    "user_address": {
        "object_definition": {
            "string": "users.details.address",
            "data": "Delhi, India"
        }
    },
}];

let objectHolder = {};

for (let [key, value] of Object.entries(elements[0])) {
    string2object.getObjectWithHolder(objectHolder, value.object_definition.string, value.object_definition.data);
}

console.log(objectHolder);
//{ users: { details: { phone: '91987***321', address: 'Delhi, India' } } }

Methods

string2object.getObject("hello.world.reply", "HI")
string2object.getObjectWithHolder(ObjectHolder = {}, "hello.world.reply", "HI")

License

MIT

About

Make nested javascript object from string representation.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published