node-helper-utilities
Advanced tools
Comparing version 2.0.1 to 2.1.0
2.1.0 / 2015-10-16 | ||
================== | ||
* docs: update documentation for clean method | ||
* code: add support for clean method | ||
2.0.1 / 2015-10-01 | ||
@@ -3,0 +9,0 @@ ================== |
28
index.js
@@ -11,2 +11,29 @@ 'use strict'; | ||
function clean(obj) { | ||
if(obj === null || typeof obj !== 'object') { | ||
return obj; | ||
} | ||
if(obj instanceof Array) { | ||
return obj.filter(function(item) { | ||
return !!clean(item); | ||
}); | ||
} | ||
if(obj instanceof Date) { | ||
return obj; | ||
} | ||
var r = {}; | ||
Object.keys(obj).forEach(function(key) { | ||
var item = clean(obj[key]); | ||
if(!!item) { | ||
r[key] = item; | ||
} | ||
}); | ||
return r; | ||
} | ||
function clone(obj) { | ||
@@ -193,2 +220,3 @@ var copy; | ||
clone: clone, | ||
clean: clean, | ||
merge: merge, | ||
@@ -195,0 +223,0 @@ cluster: setupCluster, |
{ | ||
"name": "node-helper-utilities", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"description": "Generic helper utilities", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -21,2 +21,19 @@ node-helper-utilities | ||
### Clean: Filter out all non-true values | ||
```js | ||
var util = require('./'); | ||
var obj = { | ||
a: false, | ||
b: true | ||
}; | ||
var b = util.clean(obj); | ||
console.log(b); | ||
// { | ||
// b: true | ||
// } | ||
``` | ||
### Clone: Clone an object | ||
@@ -128,3 +145,3 @@ | ||
}); | ||
util | ||
@@ -135,4 +152,4 @@ .compare('password', hashed) | ||
}) | ||
.catch(function(err) { | ||
console.log(err); | ||
.catch(function(err) { | ||
console.log(err); | ||
}); | ||
@@ -159,3 +176,3 @@ ```` | ||
Often when you deal with async processes and have to pass data as JSON around, there is always potential for errors. | ||
Often when you deal with async processes and have to pass data as JSON around, there is always potential for errors. | ||
This function is to parse json safely, and return a promise. | ||
@@ -213,3 +230,3 @@ | ||
All tests are within `tests`. | ||
All tests are within `tests`. | ||
@@ -220,5 +237,8 @@ Run tests using `make test` or `make test-cov` for test coverage. | ||
- `0.10` | ||
- `0.11` | ||
- `0.10` | ||
- `0.11` | ||
- `0.12` | ||
- `iojs` (latest) | ||
- `1.x` | ||
- `2.x` | ||
- `3.x` | ||
- `4.x` |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
88052
16
571
239