Comparing version 0.0.10 to 0.1.0
@@ -24,3 +24,3 @@ /* | ||
} | ||
return encoded; | ||
@@ -36,3 +36,3 @@ }; | ||
var decoded; | ||
try { | ||
@@ -44,4 +44,4 @@ decoded = new Buffer(encoded || '', 'base64').toString('utf8'); | ||
} | ||
return decoded; | ||
}; |
@@ -19,9 +19,4 @@ /* | ||
// | ||
// Remark: Somehow copying `util.inspect` makes the `utile` | ||
// object `2`. See: https://github.com/joyent/node/issues/2225 | ||
// | ||
Object.keys(util).forEach(function (key) { | ||
if (key !== 'inspect') { | ||
utile[key] = util[key]; | ||
} | ||
utile[key] = util[key]; | ||
}); | ||
@@ -34,3 +29,4 @@ | ||
utile.__defineGetter__('async', function () { | ||
return require('async'); | ||
delete utile.async; | ||
return utile.async = require('async'); | ||
}); | ||
@@ -43,3 +39,4 @@ | ||
utile.__defineGetter__('mkdirp', function () { | ||
return require('mkdirp'); | ||
delete utile.mkdirp; | ||
return utile.mkdirp = require('mkdirp'); | ||
}); | ||
@@ -52,3 +49,4 @@ | ||
utile.__defineGetter__('rimraf', function () { | ||
return require('rimraf'); | ||
delete utile.rimraf; | ||
return utile.rimraf = require('rimraf'); | ||
}); | ||
@@ -61,3 +59,4 @@ | ||
utile.__defineGetter__('cpr', function () { | ||
return require('ncp').ncp; | ||
delete utile.cpr; | ||
return utile.cpr = require('ncp').ncp; | ||
}); | ||
@@ -70,6 +69,16 @@ | ||
utile.__defineGetter__('file', function () { | ||
return require('./file'); | ||
delete utile.file; | ||
return utile.file = require('./file'); | ||
}); | ||
// | ||
// ### @args {Object} | ||
// Lazy-loaded `args` module | ||
// | ||
utile.__defineGetter__('args', function () { | ||
delete utile.args; | ||
return utile.args = require('./args'); | ||
}); | ||
// | ||
// ### @base64 {Object} | ||
@@ -79,6 +88,34 @@ // Lazy-loaded `base64` object | ||
utile.__defineGetter__('base64', function () { | ||
return require('./base64'); | ||
delete utile.base64; | ||
return utile.base64 = require('./base64'); | ||
}); | ||
// | ||
// ### function rargs(_args) | ||
// #### _args {Arguments} Original function arguments | ||
// | ||
// Top-level method will accept a javascript "arguments" object | ||
// (the actual keyword "arguments" inside any scope) and return | ||
// back an Array. | ||
// | ||
utile.rargs = function (_args, slice) { | ||
if (!slice) { | ||
slice = 0; | ||
} | ||
var len = (_args || []).length, | ||
args = new Array(len - slice), | ||
i; | ||
// | ||
// Convert the raw `_args` to a proper Array. | ||
// | ||
for (i = slice; i < len; i++) { | ||
args[i - slice] = _args[i]; | ||
} | ||
return args; | ||
}; | ||
// | ||
// ### function each (obj, iterator) | ||
@@ -119,3 +156,3 @@ // #### @obj {Object} Object to iterate over | ||
var key, i; | ||
for (i in path) { | ||
@@ -125,7 +162,7 @@ if (typeof obj === 'undefined') { | ||
} | ||
key = path[i]; | ||
obj = obj[key]; | ||
} | ||
return obj; | ||
@@ -144,3 +181,3 @@ }; | ||
var key, i; | ||
for (i in path) { | ||
@@ -151,3 +188,3 @@ key = path[i]; | ||
} | ||
obj = obj[key]; | ||
@@ -163,18 +200,21 @@ } | ||
utile.mixin = function (target) { | ||
var objs = Array.prototype.slice.call(arguments, 1); | ||
objs.forEach(function (o) { | ||
utile.rargs(arguments, 1).forEach(function (o) { | ||
Object.keys(o).forEach(function (attr) { | ||
var getter = o.__lookupGetter__(attr); | ||
if (!getter) { | ||
var getter = o.__lookupGetter__(attr), | ||
setter = o.__lookupSetter__(attr); | ||
if (!getter && !setter) { | ||
target[attr] = o[attr]; | ||
} | ||
else { | ||
target.__defineGetter__(attr, getter); | ||
if (setter) { target.__defineSetter__(attr, setter) } | ||
if (getter) { target.__defineGetter__(attr, getter) } | ||
} | ||
}); | ||
}); | ||
return target; | ||
}; | ||
// | ||
@@ -233,3 +273,3 @@ // ### function capitalize (str) | ||
}); | ||
return copy; | ||
@@ -250,3 +290,3 @@ }; | ||
files.forEach(function (file) { | ||
if (file.substr(-3) == '.js') { | ||
if (file.substr(-3) === '.js') { | ||
file = file.substr(0, file.length - 3); | ||
@@ -271,7 +311,8 @@ } | ||
files.forEach(function (file) { | ||
if (file.substr(-3) == '.js') { | ||
if (file.substr(-3) === '.js') { | ||
file = file.substr(0, file.length - 3); | ||
} | ||
result.__defineGetter__(file, function () { | ||
return require(path.resolve(directory, file)); | ||
delete result[file]; | ||
return result[file] = require(path.resolve(directory, file)); | ||
}); | ||
@@ -278,0 +319,0 @@ }); |
{ | ||
"name": "utile", | ||
"description": "A drop-in replacement for `util` with some additional advantageous functions", | ||
"version": "0.0.10", | ||
"author": "Nodejitsu Inc <info@nodejitsu.com>", | ||
"contributors": [ | ||
{ "name": "Charlie Robbins", "email": "charlie@nodejitsu.com" }, | ||
{ "name": "Dominic Tarr", "email": "dominic@nodejitsu.com" }, | ||
{ "name": "Maciej Malecki", "email": "maciej@nodejitsu.com" } | ||
"version": "0.1.0", | ||
"author": "Nodejitsu Inc. <info@nodejitsu.com>", | ||
"maintainers": [ | ||
"indexzero <charlie@nodejitsu.com>" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "http://github.com/flatiron/utile.git" | ||
"url": "http://github.com/flatiron/utile.git" | ||
}, | ||
@@ -28,3 +26,6 @@ "dependencies": { | ||
"main": "./lib/index", | ||
"engines": { "node": ">= 0.4.0" } | ||
"engines": { | ||
"node": ">= 0.6.4" | ||
} | ||
} | ||
@@ -8,3 +8,3 @@ # utile [![Build Status](https://secure.travis-ci.org/flatiron/utile.png)](http://travis-ci.org/flatiron/utile) | ||
``` | ||
``` | ||
$ node | ||
@@ -30,3 +30,4 @@ > var util = require('util'); | ||
utile.inherits utile.log utile.mixin utile.mkdirp utile.p utile.path | ||
utile.print utile.pump utile.puts utile.randomString utile.rimraf | ||
utile.print utile.pump utile.puts utile.randomString utile.requireDir uile.requireDirLazy | ||
utile.rimraf | ||
``` | ||
@@ -36,4 +37,2 @@ | ||
**Remark:** The `util.inspect` method is not exposed in `utile` [until this issue is resolved](https://github.com/joyent/node/issues/2225). | ||
## Methods | ||
@@ -48,4 +47,7 @@ The `utile` modules exposes some simple utility methods: | ||
* `.filter(obj, test)`: return an object with the properties that `test` returns true on. | ||
* `.args(arguments)`: Converts function arguments into actual array with special `callback`, `cb`, `array`, and `last` properties. Also supports *optional* argument contracts. See [the example](https://github.com/flatiron/utile/blob/master/examples/utile-args.js) for more details. | ||
* `.requireDir(directory)`: Requires all files and directories from `directory`, returning an object with keys being filenames (without trailing `.js`) and respective values being return values of `require(filename)`. | ||
* `.requireDirLazy(directoy)`: Lazily requires all files and directories from `directory`, returning an object with keys being filenames (without trailing `.js`) and respective values (getters) being return values of `require(filename)`. | ||
## Packaged Dependencies | ||
## Packaged Dependencies | ||
In addition to the methods that are built-in, utile includes a number of commonly used dependencies to reduce the number of includes in your package.json. These modules _are not eagerly loaded to be respectful of startup time,_ but instead are lazy-loaded getters on the `utile` object | ||
@@ -52,0 +54,0 @@ |
@@ -8,3 +8,3 @@ /* | ||
*/ | ||
var assert = require('assert'), | ||
@@ -11,0 +11,0 @@ path = require('path'), |
@@ -7,3 +7,3 @@ /* | ||
*/ | ||
var assert = require('assert'), | ||
@@ -10,0 +10,0 @@ vows = require('vows'), |
@@ -26,3 +26,2 @@ /* | ||
topic: utile.requireDirLazy(requireFixtures), | ||
'should contain all wanted modules': macros.assertDirectoryRequired, | ||
'all properties should be getters': function (obj) { | ||
@@ -32,3 +31,4 @@ assert.isObject(obj); | ||
assert.isTrue(!!obj.__lookupGetter__('helloWorld')); | ||
} | ||
}, | ||
'should contain all wanted modules': macros.assertDirectoryRequired | ||
} | ||
@@ -35,0 +35,0 @@ } |
@@ -8,3 +8,3 @@ /* | ||
*/ | ||
var assert = require('assert'), | ||
@@ -26,8 +26,17 @@ vows = require('vows'), | ||
baz: true, | ||
buzz: 'buzz' | ||
buzz: 'buzz' | ||
}; | ||
obj2.__defineGetter__('bazz', function () { | ||
return 'bazz'; | ||
}); | ||
obj2.__defineSetter__('bazz', function () { | ||
return 'bazz'; | ||
}); | ||
obj2.__defineSetter__('wat', function () { | ||
return 'wat'; | ||
}); | ||
vows.describe('utile').addBatch({ | ||
@@ -37,5 +46,3 @@ "When using utile": { | ||
Object.keys(require('util')).forEach(function (fn) { | ||
if (fn !== 'inspect') { | ||
assert.isFunction(utile[fn]); | ||
} | ||
assert.isFunction(utile[fn]); | ||
}); | ||
@@ -57,2 +64,4 @@ }, | ||
assert.isTrue(!!mixed.__lookupGetter__('bazz')); | ||
assert.isTrue(!!mixed.__lookupSetter__('bazz')); | ||
assert.isTrue(!!mixed.__lookupSetter__('wat')); | ||
assert.isString(mixed.bazz); | ||
@@ -67,5 +76,5 @@ }, | ||
"the createPath() method": function () { | ||
var x = {}, | ||
var x = {}, | ||
r = Math.random(); | ||
utile.createPath(x, ['a','b','c'], r) | ||
@@ -72,0 +81,0 @@ assert.equal(x.a.b.c, r) |
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
24876
18
687
85