Comparing version 0.0.4 to 0.0.5
@@ -63,2 +63,23 @@ /* | ||
exports.find = function (object, iterator) { | ||
for( var key in object) { | ||
var value = object[key]; | ||
if(iterator(value, key)) | ||
return value; | ||
} | ||
}; | ||
// get an item from deep down inside an object | ||
exports.path = function (object, path) { | ||
for (var i in path) { | ||
//== is intended here. do not change to === | ||
if(object == null) return undefined; | ||
var key = path[i]; | ||
object = object[key]; | ||
} | ||
return object; | ||
}; | ||
// | ||
@@ -110,3 +131,3 @@ // ### function mixin (target [source0, source1, ...]) | ||
utile.randomString = function (length) { | ||
var chars, rand, i, ret, mod; | ||
var chars, rand, i, ret, mod, bits; | ||
@@ -141,11 +162,34 @@ chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-'; | ||
exports.filter = function (obj, test) { | ||
var n = Array.isArray(obj) ? [] : {} | ||
var n = Array.isArray(obj) ? [] : {}; | ||
exports.each(obj, function (v, k) { | ||
if(test(v, k, obj)) | ||
n[k] = v | ||
}) | ||
return n | ||
} | ||
if (test(v, k, obj)) { | ||
n[k] = v; | ||
} | ||
}); | ||
return n; | ||
}; | ||
// | ||
// readJSONFile | ||
// | ||
exports.readJSONFile = function (file, callback) { | ||
if ('function' != typeof callback) | ||
throw new Error('readJSONFile needs a callback'); | ||
fs.readFile(file, 'utf-8', function (err, json) { | ||
if (err) | ||
return callback (err); | ||
var obj; | ||
try { | ||
obj = JSON.parse(json); | ||
} catch (err) { | ||
return callback(err); | ||
} | ||
callback(null, obj); | ||
}); | ||
}; | ||
// | ||
// Extend the `utile` object with all methods from the | ||
@@ -152,0 +196,0 @@ // core node `util` methods |
@@ -8,3 +8,3 @@ /* | ||
*/ | ||
var fs = require('fs'); | ||
@@ -14,3 +14,3 @@ | ||
if (typeof callback !== 'function') { | ||
throw new Error('readJSONFile needs a callback') | ||
throw new Error('readJSONFile needs a callback'); | ||
} | ||
@@ -22,11 +22,11 @@ | ||
} | ||
try { | ||
var json = JSON.parse(data); | ||
callback(null, json) | ||
} | ||
callback(null, json); | ||
} | ||
catch (err) { | ||
return callback(err) | ||
return callback(err); | ||
} | ||
}); | ||
}; |
{ | ||
"name": "utile", | ||
"description": "A drop-in replacement for `util` with some additional advantageous functions", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"author": "Nodejitsu Inc <info@nodejitsu.com>", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
@@ -5,14 +5,2 @@ # utile | ||
## Installation | ||
### Installing npm (node package manager) | ||
``` | ||
curl http://npmjs.org/install.sh | sh | ||
``` | ||
### Installing utile | ||
``` | ||
[sudo] npm install utile | ||
``` | ||
## Motivation | ||
@@ -65,2 +53,14 @@ Javascript is definitely a "batteries not included language" when compared to languages like Ruby or Python. Node.js has a simple utility library which exposes some basic (but important) functionality: | ||
## Installation | ||
### Installing npm (node package manager) | ||
``` | ||
curl http://npmjs.org/install.sh | sh | ||
``` | ||
### Installing utile | ||
``` | ||
[sudo] npm install utile | ||
``` | ||
## Tests | ||
@@ -75,2 +75,3 @@ All tests are written with [vows][4] and should be run with [npm][5]: | ||
#### Contributors: [Charlie Robbins](http://github.com/indexzero), [Dominic Tarr](http://github.com/dominictarr) | ||
#### License: MIT | ||
@@ -77,0 +78,0 @@ [0]: https://github.com/caolan/async |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
12568
280
80
0