Sorry, the diff of this file is not supported yet
+46
| /* | ||
| * args.js: function argument parsing helper utility | ||
| * | ||
| * (C) 2012, Nodejitsu Inc. | ||
| * MIT LICENSE | ||
| * | ||
| */ | ||
| var utile = require('./index'); | ||
| // | ||
| // ### function args(_args) | ||
| // #### _args {Arguments} Original function arguments | ||
| // | ||
| // Top-level method will accept a javascript "arguments" object (the actual keyword | ||
| // "arguments" inside any scope), and attempt to return back an intelligent object | ||
| // representing the functions arguments | ||
| // | ||
| module.exports = function (_args) { | ||
| var args = utile.rargs(_args), | ||
| _cb; | ||
| // | ||
| // Find and define the first argument | ||
| // | ||
| Object.defineProperty(args, 'first', { value: args[0] }); | ||
| // | ||
| // Find and define any callback | ||
| // | ||
| _cb = args[args.length - 1] || args[args.length]; | ||
| if (typeof _cb === "function") { | ||
| Object.defineProperty(args, 'callback', { value: _cb }); | ||
| Object.defineProperty(args, 'cb', { value: _cb }); | ||
| args.pop(); | ||
| } | ||
| // | ||
| // Find and define the last argument | ||
| // | ||
| if (args.length) { | ||
| Object.defineProperty(args, 'last', { value: args[args.length - 1] }); | ||
| } | ||
| return args; | ||
| }; |
| /* | ||
| * function-args-test.js: Tests for `args` method | ||
| * | ||
| * (C) 2012, Nodejitsu Inc. | ||
| * MIT LICENSE | ||
| * | ||
| */ | ||
| var assert = require('assert'), | ||
| path = require('path'), | ||
| vows = require('vows'), | ||
| macros = require('./helpers/macros'), | ||
| utile = require('../'); | ||
| vows.describe('utile/args').addBatch({ | ||
| 'When using utile': { | ||
| 'the `args` function': { | ||
| topic: utile, | ||
| 'should be a function': function (_utile) { | ||
| assert.isFunction(_utile.args); | ||
| }, | ||
| } | ||
| }, | ||
| 'utile.rargs()': { | ||
| 'with no arguments': { | ||
| topic: utile.rargs(), | ||
| 'should return an empty object': function (result) { | ||
| assert.isArray(result); | ||
| assert.lengthOf(result, 0); | ||
| } | ||
| }, | ||
| 'with simple arguments': { | ||
| topic: function () { | ||
| return (function () { | ||
| return utile.rargs(arguments); | ||
| })('a', 'b', 'c'); | ||
| }, | ||
| 'should return an array with three items': function (result) { | ||
| assert.isArray(result); | ||
| assert.equal(3, result.length); | ||
| assert.equal(result[0], 'a'); | ||
| assert.equal(result[1], 'b'); | ||
| assert.equal(result[2], 'c'); | ||
| } | ||
| }, | ||
| 'with a simple slice': { | ||
| topic: function () { | ||
| return (function () { | ||
| return utile.rargs(arguments, 1); | ||
| })('a', 'b', 'c'); | ||
| }, | ||
| 'should return an array with three items': function (result) { | ||
| assert.isArray(result); | ||
| assert.equal(2, result.length); | ||
| assert.equal(result[0], 'b'); | ||
| assert.equal(result[1], 'c'); | ||
| } | ||
| } | ||
| }, | ||
| 'utile.args()': { | ||
| 'with no arguments': { | ||
| topic: utile.args(), | ||
| 'should return an empty Array': function (result) { | ||
| assert.isUndefined(result.callback); | ||
| assert.isArray(result); | ||
| assert.lengthOf(result, 0); | ||
| } | ||
| }, | ||
| 'with simple arguments': { | ||
| topic: function () { | ||
| return (function () { | ||
| return utile.args(arguments); | ||
| })('a', 'b', 'c', function () { | ||
| return 'ok'; | ||
| }); | ||
| }, | ||
| 'should return an array with three items': function (result) { | ||
| assert.isArray(result); | ||
| assert.equal(3, result.length); | ||
| assert.equal(result[0], 'a'); | ||
| assert.equal(result[1], 'b'); | ||
| assert.equal(result[2], 'c'); | ||
| // | ||
| // Ensure that the Array returned | ||
| // by `utile.args()` enumerates correctly | ||
| // | ||
| var length = 0; | ||
| result.forEach(function (item) { | ||
| length++; | ||
| }); | ||
| assert.equal(length, 3); | ||
| }, | ||
| 'should return lookup helpers': function (result) { | ||
| assert.isArray(result); | ||
| assert.equal(result.first, 'a'); | ||
| assert.equal(result.last, 'c'); | ||
| assert.isFunction(result.callback); | ||
| assert.isFunction(result.cb); | ||
| } | ||
| } | ||
| } | ||
| }).export(module); |
+1
-0
@@ -5,2 +5,3 @@ language: node_js | ||
| - 0.6 | ||
| - 0.7 | ||
@@ -7,0 +8,0 @@ notifications: |
+3
-3
@@ -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; | ||
| }; |
+68
-27
@@ -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 @@ }); |
+9
-8
| { | ||
| "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" | ||
| } | ||
| } | ||
+7
-5
@@ -8,3 +8,3 @@ # utile [](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 @@ } |
+17
-8
@@ -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) |
| node_modules | ||
| npm-debug.log |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
24876
28.17%18
12.5%687
35.24%85
2.41%