The string 'person.info.name'
will return you 'Pete'
from the { person: { info: { name: 'Pete', age: 32 } } }
keysParser(string, object)
Param | Required | Description |
---|---|---|
string |
true | A string with the route to the desired key in the Object |
object |
true | The object to find the key in |
import { keysParser } from 'keys-parser'
const string = 'big.red.fruit'
const object = {
big: {
red: {
fruit: 'Apple',
car: 'Chevrolet'
}
}
}
keysParser(string, object) //--> 'Apple'
keysParser('big.red.fruit.banana', object) //--> console error:
//--> "keysParser ERROR: The key "banana" can't be found in the "fruit", because "fruit's" value is simple type"
keysParser('big.red.apple', object) //--> console error:
//--> "keysParser ERROR: The key "apple" can't be found... Maybe you meant something like these: "fruit,car""