node-helper-utilities
Advanced tools
Comparing version 1.7.5 to 2.0.0
32
index.js
@@ -55,15 +55,2 @@ 'use strict'; | ||
function memoize(fn) { | ||
var ctx = fn; | ||
ctx._values = ctx.values || {}; | ||
return function() { | ||
var args = slice.call(arguments); | ||
if(!ctx._values[args]) { | ||
ctx._values[args] = fn.apply(ctx, args); | ||
} | ||
return ctx._values[args]; | ||
}; | ||
} | ||
function setupCluster(config, done) { | ||
@@ -189,6 +176,20 @@ var defaults = { | ||
function padder(value, opts) { | ||
opts = opts || {}; | ||
var num = opts.length || value.length + 1; | ||
var prefix = opts.prefix || '0'; | ||
value = String(value); | ||
do { | ||
value = prefix + value; | ||
} while(value.length < num) | ||
return value; | ||
} | ||
module.exports = { | ||
clone: clone, | ||
merge: merge, | ||
memoize: memoize, | ||
cluster: setupCluster, | ||
@@ -201,3 +202,4 @@ unique: unique, | ||
read: readFile, | ||
write: writeFile | ||
write: writeFile, | ||
padder: padder | ||
}; |
{ | ||
"name": "node-helper-utilities", | ||
"version": "1.7.5", | ||
"version": "2.0.0", | ||
"description": "Generic helper utilities", | ||
@@ -20,13 +20,12 @@ "main": "index.js", | ||
"devDependencies": { | ||
"bluebird": "^2.9.16", | ||
"chai": "^2.2.0", | ||
"istanbul": "^0.3.11", | ||
"mocha": "^2.2.1", | ||
"chai": "^3.2.0", | ||
"istanbul": "^0.3.14", | ||
"mocha": "^2.2.5", | ||
"sinon": "^1.14.1" | ||
}, | ||
"dependencies": { | ||
"bcrypt": "^0.8.1", | ||
"bluebird": "^2.9.16", | ||
"bcrypt": "^0.8.4", | ||
"bluebird": "^2.9.34", | ||
"native-or-bluebird": "^1.2.0" | ||
} | ||
} |
@@ -8,2 +8,3 @@ node-helper-utilities | ||
[![github-tag](http://img.shields.io/github/tag/limianwang/node-utilities.svg?style=flat-square)](https://github.com/limianwang/node-utilities/releases) | ||
[![npm](https://img.shields.io/npm/dm/node-helper-utilities.svg?style=flat-square)](https://www.npmjs.com/package/node-helper-utilities) | ||
[![npm](https://img.shields.io/npm/v/node-helper-utilities.svg?style=flat-square)](https://www.npmjs.com/package/node-helper-utilities) | ||
@@ -52,17 +53,2 @@ [![Dependency Status](https://david-dm.org/limianwang/node-utilities.svg?style=flat-square)](https://david-dm.org/limianwang/node-utilities) | ||
### Memoize: memoize function responses | ||
```javascript | ||
var util = require('./'); | ||
function echo(i) { | ||
return i; | ||
} | ||
var cache = memoize(echo); | ||
cache(1); | ||
cache(1); // returns from cache | ||
``` | ||
### Cluster: Helper to start process in a cluster. | ||
@@ -211,2 +197,14 @@ | ||
### Padder | ||
```js | ||
var util = require('./'); | ||
var str = 'h'; | ||
var padded = util.padder(str, { prefix: 'x', length: 5 }); | ||
console.log(padded); // 'xxxxh' | ||
``` | ||
# Tests | ||
@@ -213,0 +211,0 @@ |
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
84868
4
16
554
219
1
Updatedbcrypt@^0.8.4
Updatedbluebird@^2.9.34