1.0.5 • Published 2 years ago

keys-parser v1.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

keysParser

Get the value in an object using a string.

npm npm npm

The string 'person.info.name' will return you 'Pete' from the { person: { info: { name: 'Pete', age: 32 } } }

Syntax

keysParser(string, object)

Params

ParamRequiredDescription
stringtrueA string with the route to the desired key in the Object
objecttrueThe object to find the key in

Examples

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""