Comparing version 0.0.1 to 0.1.0
@@ -42,4 +42,4 @@ /*! | ||
// add listeners | ||
.on('cycle', function (event, bench) { | ||
console.log(String(bench)); | ||
.on('cycle', function (event) { | ||
console.log(String(event.target)); | ||
}) | ||
@@ -46,0 +46,0 @@ .on('complete', function () { |
0.1.0 / 2014-02-24 | ||
================== | ||
* decode with charset | ||
* add npm image | ||
* remove 0.6 for travis | ||
* update to support coveralls | ||
* use jscover instead of jscoverage | ||
* update gitignore | ||
* Merge pull request #1 from aleafs/master | ||
* Add http entries test case | ||
0.0.1 / 2012-10-31 | ||
@@ -3,0 +15,0 @@ ================== |
@@ -1,1 +0,1 @@ | ||
module.exports = process.env.URLENCODE_COV ? require('./lib-cov/urlencode') : require('./lib/urlencode'); | ||
module.exports = require('./lib/urlencode'); |
@@ -1,5 +0,9 @@ | ||
/*! | ||
/**! | ||
* urlencode - lib/urlencode.js | ||
* Copyright(c) 2012 fengmk2 <fengmk2@gmail.com> | ||
* | ||
* Copyright(c) 2012 - 2014 | ||
* MIT Licensed | ||
* | ||
* Authors: | ||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com) | ||
*/ | ||
@@ -14,10 +18,18 @@ | ||
var iconv = require('iconv-lite'); | ||
var QueryString = require('querystring'); | ||
var utility = require('utility'); | ||
function isUTF8(charset) { | ||
if (!charset) { | ||
return true; | ||
} | ||
charset = charset.toLowerCase(); | ||
return charset === 'utf8' || charset === 'utf-8'; | ||
} | ||
function encode(str, charset) { | ||
if (charset === 'utf8' || charset === 'utf-8') { | ||
charset = null; | ||
} | ||
if (!charset) { | ||
if (isUTF8(charset)) { | ||
return encodeURIComponent(str); | ||
} | ||
var buf = iconv.encode(str, charset); | ||
@@ -31,2 +43,93 @@ var encodeStr = ''; | ||
module.exports = encode; | ||
function decode(str, charset) { | ||
if (isUTF8(charset)) { | ||
return decodeURIComponent(str); | ||
} | ||
var bytes = []; | ||
for (var i = 0; i < str.length; ) { | ||
if (str[i] === '%') { | ||
i++; | ||
bytes.push(parseInt(str.substring(i, i + 2), 16)); | ||
i += 2; | ||
} else { | ||
bytes.push(str.charCodeAt(i)); | ||
i++; | ||
} | ||
} | ||
var buf = new Buffer(bytes); | ||
return iconv.decode(buf, charset); | ||
} | ||
function parse(qs, sep, eq, options) { | ||
if (typeof sep === 'object') { | ||
// parse(qs, options) | ||
options = sep; | ||
sep = null; | ||
} | ||
sep = sep || '&'; | ||
eq = eq || '='; | ||
var obj = {}; | ||
if (typeof qs !== 'string' || qs.length === 0) { | ||
return obj; | ||
} | ||
var regexp = /\+/g; | ||
qs = qs.split(sep); | ||
var maxKeys = 1000; | ||
var charset = null; | ||
if (options) { | ||
if (typeof options.maxKeys === 'number') { | ||
maxKeys = options.maxKeys; | ||
} | ||
if (typeof options.charset === 'string') { | ||
charset = options.charset; | ||
} | ||
} | ||
var len = qs.length; | ||
// maxKeys <= 0 means that we should not limit keys count | ||
if (maxKeys > 0 && len > maxKeys) { | ||
len = maxKeys; | ||
} | ||
for (var i = 0; i < len; ++i) { | ||
var x = qs[i].replace(regexp, '%20'); | ||
var idx = x.indexOf(eq); | ||
var kstr, vstr, k, v; | ||
if (idx >= 0) { | ||
kstr = x.substr(0, idx); | ||
vstr = x.substr(idx + 1); | ||
} else { | ||
kstr = x; | ||
vstr = ''; | ||
} | ||
try { | ||
k = decode(kstr, charset); | ||
v = decode(vstr, charset); | ||
} catch (e) { | ||
k = QueryString.unescape(kstr, true); | ||
v = QueryString.unescape(vstr, true); | ||
} | ||
if (!utility.hasOwnProperty(obj, k)) { | ||
obj[k] = v; | ||
} else if (Array.isArray(obj[k])) { | ||
obj[k].push(v); | ||
} else { | ||
obj[k] = [obj[k], v]; | ||
} | ||
} | ||
return obj; | ||
} | ||
module.exports = encode; | ||
module.exports.encode = encode; | ||
module.exports.decode = decode; | ||
module.exports.parse = parse; |
This software is licensed under the MIT License. | ||
Copyright (C) 2012 by fengmk2 <fengmk2@gmail.com> | ||
Copyright (C) 2012 - 2014 fengmk2 <fengmk2@gmail.com> | ||
@@ -5,0 +5,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy |
{ | ||
"name": "urlencode", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "encodeURIComponent with charset", | ||
"main": "index.js", | ||
"directories": { | ||
"test": "test" | ||
}, | ||
"scripts": { | ||
"test": "make test && make benchmark" | ||
"test": "make test-all" | ||
}, | ||
"config": { | ||
"blanket": { | ||
"pattern": "urlencode/lib" | ||
}, | ||
"travis-cov": { "threshold": 98 } | ||
}, | ||
"dependencies": { | ||
"iconv-lite": "0.2.x" | ||
"iconv-lite": "0.2.11", | ||
"utility": "0.1.10" | ||
}, | ||
"devDependencies": { | ||
"should": "*", | ||
"autod": "*", | ||
"benchmark": "*", | ||
"mocha": "*" | ||
"blanket": "*", | ||
"coveralls": "*", | ||
"mocha": "*", | ||
"mocha-lcov-reporter": "*", | ||
"should": "3.1.2", | ||
"travis-cov": "*" | ||
}, | ||
"homepage": "https://github.com/fengmk2/urlencode", | ||
"repository": { | ||
@@ -21,0 +31,0 @@ "type": "git", |
@@ -1,4 +0,6 @@ | ||
urlencode [![Build Status](https://secure.travis-ci.org/fengmk2/urlencode.png)](http://travis-ci.org/fengmk2/urlencode) | ||
urlencode [![Build Status](https://secure.travis-ci.org/fengmk2/urlencode.png)](http://travis-ci.org/fengmk2/urlencode) [![Coverage Status](https://coveralls.io/repos/fengmk2/urlencode/badge.png)](https://coveralls.io/r/fengmk2/urlencode) | ||
======= | ||
[![NPM](https://nodei.co/npm/urlencode.png?downloads=true&stars=true)](https://nodei.co/npm/urlencode/) | ||
![logo](https://raw.github.com/fengmk2/urlencode/master/logo.png) | ||
@@ -22,3 +24,9 @@ | ||
console.log(urlencode('苏千')); // default is utf8 | ||
console.log(urlencode('苏千', 'gbk')); | ||
console.log(urlencode('苏千', 'gbk')); // '%CB%D5%C7%A7' | ||
// decode gbk | ||
urlencode.decode('%CB%D5%C7%A7', 'gbk'); // '苏千' | ||
// parse gbk querystring | ||
urlencode.parse('nick=%CB%D5%C7%A7', 'gbk'); // {nick: '苏千'} | ||
``` | ||
@@ -36,7 +44,7 @@ | ||
## License | ||
## License | ||
(The MIT License) | ||
Copyright (c) 2012 fengmk2 <fengmk2@gmail.com> | ||
Copyright (c) 2012 - 2014 fengmk2 <fengmk2@gmail.com> | ||
@@ -60,2 +68,2 @@ Permission is hereby granted, free of charge, to any person obtaining | ||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
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
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
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
20164
10
155
1
67
0
2
8
1
+ Addedutility@0.1.10
+ Addedaddress@2.0.3(transitive)
+ Addedutility@0.1.10(transitive)
Updatediconv-lite@0.2.11