Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

utility

Package Overview
Dependencies
Maintainers
2
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

utility - npm Package Compare versions

Comparing version 1.5.0 to 1.6.0

8

History.md
1.5.0 / 2015-10-20
1.6.0 / 2015-12-04
==================
* refactor: use escape-html
1.5.0 / 2015-11-25
==================
* feat: utility.dig
* test(date): fix timezone on test assert

@@ -6,0 +12,0 @@ * feat(date): make YYYYMMDDHHmmss() support param not Date

@@ -33,1 +33,26 @@ /*!

};
/**
* avoid if (a && a.b && a.b.c)
* @param {Object} obj
* @param {...String} keys
* @return {Object}
*/
exports.dig = function (obj) {
if (!obj) {
return;
}
if (arguments.length <= 1) {
return obj;
}
var value = obj[arguments[1]];
for (var i = 2; i < arguments.length; i++) {
if (!value) {
break;
}
value = value[arguments[i]];
}
return value;
};

8

lib/web.js

@@ -17,9 +17,3 @@ /*!

*/
exports.escape = function escape(html) {
return String(html)
.replace(/&(?!\w+;)/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;');
};
exports.escape = require('escape-html');

@@ -26,0 +20,0 @@ /**

{
"name": "utility",
"version": "1.5.0",
"version": "1.6.0",
"description": "A collection of useful utilities.",

@@ -17,3 +17,4 @@ "main": "lib/utility.js",

"dependencies": {
"copy-to": "~2.0.1"
"copy-to": "~2.0.1",
"escape-html": "~1.0.3"
},

@@ -20,0 +21,0 @@ "devDependencies": {

@@ -30,28 +30,44 @@ utility

var utils = require('utility');
```
// md5 hash
utils.md5('@Python发烧友'); // '1369e7668bc600f0d90c06f5e395d7a9'
utils.md5(new Buffer('')); // 'd41d8cd98f00b204e9800998ecf8427e'
// md5 hase output base64
### md5
```js
utils.md5('苏千').should.equal('5f733c47c58a077d61257102b2d44481');
utils.md5(new Buffer('苏千')).should.equal('5f733c47c58a077d61257102b2d44481');
// md5 base64 format
utils.md5('苏千', 'base64'); // 'X3M8R8WKB31hJXECstREgQ=='
// Object md5 hash
// Object md5 hash. Sorted by key, and JSON.stringify. See source code for detail
utils.md5({foo: 'bar', bar: 'foo'}).should.equal(utils.md5({bar: 'foo', foo: 'bar'}));
```
// sha1 hash
utils.sha1('@Python发烧友'); // 'ed6a2381ad20f2cf7875fc04d52257380015b574'
utils.sha1(new Buffer('')); // 'da39a3ee5e6b4b0d3255bfef95601890afd80709'
// sha1 hase output base64
### sha1
```js
utils.sha1('苏千').should.equal('0a4aff6bab634b9c2f99b71f25e976921fcde5a5');
utils.sha1(new Buffer('苏千')).should.equal('0a4aff6bab634b9c2f99b71f25e976921fcde5a5');
// sha1 base64 format
utils.sha1('苏千', 'base64'); // 'Ckr/a6tjS5wvmbcfJel2kh/N5aU='
// sha256 hash
utils.sha256('@Python发烧友'); // '80ddd84d1453c994af764bf558c4b96adaced9dd8d7d2194705fe58e1b3162df'
// Object sha1 hash
// Object sha1 hash. Sorted by key, and JSON.stringify. See source code for detail
utils.sha1({foo: 'bar', bar: 'foo'}).should.equal(utils.sha1({bar: 'foo', foo: 'bar'}));
```
// hmac
### sha256
```js
utils.sha256(new Buffer('苏千')).should.equal('75dd03e3fcdbba7d5bec07900bae740cc8e361d77e7df8949de421d3df5d3635');
```
### hmac
```js
// hmac-sha1 with base64 output encoding
utils.hmac('sha1', 'I am a key', 'hello world'); // 'pO6J0LKDxRRkvSECSEdxwKx84L0='
```
### decode and encode
```js
// base64 encode

@@ -65,8 +81,2 @@ utils.base64encode('你好¥'); // '5L2g5aW977+l'

// empty function
process.nextTick(utils.noop);
function foo(callback) {
callback = callback || utils.noop;
}
// html escape

@@ -77,10 +87,13 @@ utils.escape('<script/>"& &amp;'); // '&lt;script/&gt;&quot;&amp; &amp;'

utils.decodeURIComponent(utils.encodeURIComponent('你好, nodejs')).should.equal('你好, nodejs');
```
// get first ip
[WARNNING] getIP() remove, PLEASE use `https://github.com/node-modules/address` module instead
### others
___[WARNNING] getIP() remove, PLEASE use `https://github.com/node-modules/address` module instead.___
```js
// get a function parameter's names
utils.getParamNames(function (key1, key2) {}); // ['key1', 'key2']
// get a random string, default length is 16
// get a random string, default length is 16.
utils.randomString(32, '1234567890'); //18774480824014856763726145106142

@@ -90,2 +103,6 @@

utils.has({hello: 'world'}, 'hello'); //true
// empty function
utils.noop = function () {}
}
```

@@ -151,2 +168,4 @@

use `Object.create(null)`
```js

@@ -167,3 +186,3 @@ var map = utils.map({a: 1});

// split string by sep
utils.split('foo,bar,,,'); // ['foo', 'bar']
utils.split('foo,bar,,,', ','); // ['foo', 'bar']

@@ -170,0 +189,0 @@ // replace string work with special chars which `String.prototype.replace` can't handle

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc