obj-util
A simple helper to set/get keys from objects using a string path like 'some.key.here'
Last updated 10 years ago by royriojas .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install obj-util 
SYNC missed versions from official npm registry.

obj-util

A simple helper to set/get keys from objects using a string path like 'some.key.here'

Install

npm i --save obj-util

Usage

obj.getKeyValue

Returns the value from the given object which matches the passed key

  • param obj {Object} The object to get the values from
  • param key {String} a string representing a key in the object. Subkeys are supported separating them with dots. i.e. key1.subkey1.subsubkey1
  • returns {Mixed} the value of the given key in the passed obj
var objUtil = require('obj-util');

var obj = {
  some: {
    key: 'some value'
  }
};

// getKeyValue
objUtil.getKeyValue(obj, 'some.key'); // 'some value'

obj.setKeyValue

Sets a value in an object if a matching key is found inside the given object

  • param obj {Object} the object where to set the value using if the key is found
  • param key {String} a string that represents the key. Subkeys are supported by separating them with dots.
  • param val the value to be set in the object
var objUtil = require('obj-util');

var obj = {
};
objUtil.setKeyValue(obj, 'some.key', 'some value');
obj.some.key === 'some value' //==> true

That's it!

Current Tags

  • 2.0.0                                ...           latest (10 years ago)

2 Versions

  • 2.0.0                                ...           10 years ago
  • 1.0.0                                ...           11 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (0)
None
Dev Dependencies (0)
None
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |