Skip to content

Get the value in an object using the string. The string 'person.info.name' will return you 'Pete' from the { person: { info: { name: 'Pete', age: 32 } } }

Notifications You must be signed in to change notification settings

evgeniyGusev/keysParser

Repository files navigation

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

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

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

About

Get the value in an object using the string. The string 'person.info.name' will return you 'Pete' from the { person: { info: { name: 'Pete', age: 32 } } }

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published