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

utility

Package Overview
Dependencies
Maintainers
1
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 0.0.1 to 0.0.2

7

History.md
0.0.2 / 2013-01-31
==================
* add base64 encode and urlsafe base64 encode
* add html escape()
* update makefile
0.0.1 / 2012-11-13

@@ -3,0 +10,0 @@ ==================

@@ -35,1 +35,51 @@ /*!

};
/**
* Base64 encode string.
*
* @param {String|Buffer} s
* @param {Boolean} [urlsafe=false] Encode string s using a URL-safe alphabet,
* which substitutes - instead of + and _ instead of / in the standard Base64 alphabet.
* @return {String} base64 encode format string.
*/
exports.base64encode = function (s, urlsafe) {
if (!Buffer.isBuffer(s)) {
s = new Buffer(s);
}
var encode = s.toString('base64');
if (urlsafe) {
encode = encode.replace(/\+/g, '-').replace(/\//g, '_');
}
return encode;
};
/**
* Base64 string decode.
*
* @param {String} encode, base64 encoding string.
* @param {Boolean} [urlsafe=false] Decode string s using a URL-safe alphabet,
* which substitutes - instead of + and _ instead of / in the standard Base64 alphabet.
* @return {String} plain text.
*/
exports.base64decode = function (encode, urlsafe) {
if (urlsafe) {
encode = encode.replace(/\-/g, '+').replace(/_/g, '/');
}
encode = new Buffer(encode, 'base64');
return encode.toString();
};
/**
* Escape the given string of `html`.
*
* @param {String} html
* @return {String}
* @public
*/
exports.escape = function (html) {
return String(html)
.replace(/&(?!\w+;)/g, '&')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;');
};

2

package.json
{
"name": "utility",
"version": "0.0.1",
"version": "0.0.2",
"description": "A collection of useful utilities.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -25,2 +25,10 @@ utility [![Build Status](https://secure.travis-ci.org/fengmk2/utility.png)](http://travis-ci.org/fengmk2/utility)

// base64 encode
utils.base64encode('你好¥'); // '5L2g5aW977+l'
utils.base64decode('5L2g5aW977+l') // '你好¥'
// urlsafe base64 encode
utils.base64encode('你好¥', true); // '5L2g5aW977-l'
utils.base64decode('5L2g5aW977-l', true); // '你好¥'
// empty function

@@ -31,2 +39,5 @@ process.nextTick(utils.noop);

}
// html escape
utils.escape('<script/>"& &amp;'); // '&lt;script/&gt;&quot;&amp; &amp;'
```

@@ -33,0 +44,0 @@

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