New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

objpath

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

objpath - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

3

package.json
{
"name": "objpath",
"version": "0.0.5",
"version": "0.0.6",
"description": "create/access objects with a key-string",
"main": "./objpath.js",

@@ -5,0 +6,0 @@ "scripts": {

# objpath
create/access objects with a key-string
``` javascript
/**
* create/access objects with a key-string
*
* objpath(this, 'foo.bar', 'blub')
* assert.equal(this.foo.bar,'blub')
* assert.equal(objpath(this,'foo.bar'),'blub')
*
* @param {Object} scope
* @param {String} key-string (e.g. 'a.b.c.d')
* @param {Object} value to store in key (optional)
* @return {Object} if value-param is given it will return
* the object, otherwise it will return the value
* of the selected key
*/
function objpath(obj, keyString, value) {
if (arguments.length<2) return false
keyString = keyString+''
var keys = keyString.split('.') || [keyString]
if (obj[keys[0]] === undefined) obj[keys[0]] = {}
var temp = obj[keys[0]]
, keys = keys.slice(1)
if (value === undefined) { // get data
var value = temp
for (var i=0, len=keys.length; i<len; i++) {
if (value === undefined) return false
value = value[keys[i]]
}
return value
} else { // set data
if (keys.length==0) {
obj[keyString] = value
return obj
}
for (var i=0, len=keys.length; i<len; i++) {
if (i==(len-1)) {
temp[keys[i]] = value
} else {
temp = temp[keys[i]]
}
}
return obj
}
}
```
var objpath = require('objpath')
objpath(this, 'foo.bar', 'blub')
assert.equal(this.foo.bar,'blub')
assert.equal(objpath(this,'foo.bar'),'blub')
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc