enumerate-properties
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -1,3 +0,13 @@ | ||
// Generated by CoffeeScript 1.6.3 | ||
// Generated by CoffeeScript 1.8.0 | ||
module.exports = { | ||
/* | ||
* # enumerate(object, callback) | ||
* | ||
* Enumerates properties in a JSON object and callback | ||
* each as a dot notation format | ||
* | ||
* @param {Object} object The object on which to iterate | ||
* @param {Function} callback Callback function called for each property | ||
*/ | ||
enumerate: function(object, callback) { | ||
@@ -13,3 +23,3 @@ var walk; | ||
val = obj[prop]; | ||
if (walk(val, stack + '.' + prop)) { | ||
if (walk(val, "" + stack + "." + prop)) { | ||
str = ''; | ||
@@ -27,5 +37,16 @@ if (stack) { | ||
}, | ||
/* | ||
* # getAtPath(object, path) | ||
* | ||
* Retrieve nested value from a JSON object given | ||
* the dot notation of it's property | ||
* | ||
* @param {Object} object The object on which to get a value | ||
* @param {String} path Dot notation of the property to get | ||
* @return {* | null} | ||
*/ | ||
getAtPath: function(object, path) { | ||
var i, props, _i, _len; | ||
if (path === null) { | ||
if ((path == null) || (object == null)) { | ||
return null; | ||
@@ -36,3 +57,3 @@ } | ||
i = props[_i]; | ||
if (!object || typeof object !== 'object') { | ||
if (object[i] == null) { | ||
return null; | ||
@@ -42,7 +63,15 @@ } | ||
} | ||
if (object === void 0) { | ||
return null; | ||
} | ||
return object; | ||
}, | ||
/* | ||
* # setAtPath(object, path, value) | ||
* | ||
* Set nested value of a JSON object to the given | ||
* dot notation path | ||
* | ||
* @param {Object} object The object on which to set | ||
* @param {String} path Dot notation of the property to set | ||
* @param {*} value Value to set | ||
*/ | ||
setAtPath: function(object, path, value) { | ||
@@ -53,3 +82,3 @@ var i, len, parts, _i; | ||
for (i = _i = 0; 0 <= len ? _i < len : _i > len; i = 0 <= len ? ++_i : --_i) { | ||
if (!object[parts[i]]) { | ||
if (object[parts[i]] == null) { | ||
object[parts[i]] = {}; | ||
@@ -56,0 +85,0 @@ } |
{ | ||
"name": "enumerate-properties", | ||
"author": "Thibault Charbonnier <thibaultcha@me.com>", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Enumerates, get and set objects properties in a dot notation format", | ||
@@ -23,8 +23,8 @@ "keywords": [ | ||
"dependencies": { | ||
"coffee-script": "1.6.x" | ||
"coffee-script": "~1.8.0" | ||
}, | ||
"devDependencies": { | ||
"mocha": "1.1.x", | ||
"should": "2.1.x" | ||
"mocha": "~1.21.4", | ||
"should": "~4.0.4" | ||
} | ||
} |
@@ -13,15 +13,18 @@ # node-enumerate-properties | ||
### Usage | ||
### Documentation | ||
See [documentation.md](documentation.md) | ||
### Example | ||
```javascript | ||
var properties = require('enumerate-properties') | ||
obj = | ||
{ foo: 'bar' | ||
, bar: 'foo' | ||
, nested: | ||
{ foo: 'bar' | ||
, bar: 'foo' | ||
} | ||
, foobar: 'barfoo' | ||
obj = { | ||
foo: 'bar', | ||
bar: 'foo', | ||
nested: { | ||
foo: 'bar', | ||
bar: 'foo' | ||
}, | ||
foobar: 'barfoo' | ||
} | ||
@@ -28,0 +31,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10646
9
82
62
+ Addedcoffee-script@1.8.0(transitive)
+ Addedmkdirp@0.3.5(transitive)
- Removedcoffee-script@1.6.3(transitive)
Updatedcoffee-script@~1.8.0