Skip to content

Commit

Permalink
remove .stringify()
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanong committed Apr 16, 2015
1 parent 8e13b6e commit c3733e3
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 54 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ so you never have to check its type.

A drop-in implementation for `require('querystring')`.

### qs.stringify()

### qs.parse()

[npm-image]: https://img.shields.io/npm/v/qs-strict.svg?style=flat-square
Expand Down
44 changes: 2 additions & 42 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ var methods = [
'unescapeBuffer',
'unescape',
'escape',
'stringify',
'encode',
];

methods.forEach(function (method) {
Expand All @@ -19,47 +21,6 @@ methods.forEach(function (method) {
* As of version: https://github.com/iojs/io.js/blob/10e31ba56c676bdcad39ccad22ea9117733b8eb5/lib/querystring.js
*/

var stringifyPrimitive = function(v) {
if (typeof v === 'string')
return v;
if (typeof v === 'number' && isFinite(v))
return '' + v;
if (typeof v === 'boolean')
return v ? 'true' : 'false';
return '';
};

QueryString.stringify = QueryString.encode = function(obj, sep, eq, options) {
sep = sep || '&';
eq = eq || '=';

var encode = QueryString.escape;
if (options && typeof options.encodeURIComponent === 'function') {
encode = options.encodeURIComponent;
}

if (obj !== null && typeof obj === 'object') {
var keys = Object.keys(obj);
var len = keys.length;
var flast = len - 1;
var fields = '';
for (var i = 0; i < len; ++i) {
var k = keys[i];
var v = obj[k];
var ks = encode(stringifyPrimitive(k)) + eq;

if (Array.isArray(v))
v = v.join(',');

fields += ks + encode(stringifyPrimitive(v));
if (i < flast)
fields += sep;
}
return fields;
}
return '';
};

// Parse a key=val string.
QueryString.parse = QueryString.decode = function(qs, sep, eq, options) {
sep = sep || '&';
Expand Down Expand Up @@ -89,7 +50,6 @@ QueryString.parse = QueryString.decode = function(qs, sep, eq, options) {
decode = options.decodeURIComponent;
}

var keys = [];
for (var i = 0; i < len; ++i) {
var x = qs[i].replace(regexp, '%20'),
idx = x.indexOf(eq),
Expand Down
10 changes: 0 additions & 10 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,6 @@ var assert = require('assert');

var qs = require('..');

describe('.stringify()', function () {
it('should .join(";") arrays', function () {
var string = qs.stringify({
value: [1, 2]
});

assert.equal(string, 'value=' + qs.escape('1,2'));
})
})

describe('.parse()', function () {
describe('when there are duplicate keys', function () {
it('should only use the last value', function () {
Expand Down

0 comments on commit c3733e3

Please sign in to comment.