-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c04af1f
Showing
11 changed files
with
240 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,6 @@ | |||
[submodule "support/expresso"] | |||
path = support/expresso | |||
url = git://github.com/visionmedia/expresso.git | |||
[submodule "support/should"] | |||
path = support/should | |||
url = git://github.com/visionmedia/should.js.git |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,7 @@ | |||
|
|||
test: | |||
@./support/expresso/bin/expresso \ | |||
-I support \ | |||
-I lib | |||
|
|||
.PHONY: test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,29 @@ | |||
|
|||
# node-querystring | |||
|
|||
query string parser for node supporting nesting, as it was removed from `0.3.x`, so this library provides the previous and commonly desired behaviour. | |||
|
|||
## License | |||
|
|||
(The MIT License) | |||
|
|||
Copyright (c) 2010 TJ Holowaychuk <tj@vision-media.ca> | |||
|
|||
Permission is hereby granted, free of charge, to any person obtaining | |||
a copy of this software and associated documentation files (the | |||
'Software'), to deal in the Software without restriction, including | |||
without limitation the rights to use, copy, modify, merge, publish, | |||
distribute, sublicense, and/or sell copies of the Software, and to | |||
permit persons to whom the Software is furnished to do so, subject to | |||
the following conditions: | |||
|
|||
The above copyright notice and this permission notice shall be | |||
included in all copies or substantial portions of the Software. | |||
|
|||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, | |||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | |||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | |||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | |||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,32 @@ | |||
|
|||
var old = require('querystring') | |||
, qs = require('./') | |||
, times = 100000; | |||
|
|||
var start = new Date | |||
, n = times; | |||
|
|||
while (n--) old.parse('foo=bar'); | |||
console.log('old simple: %dms', new Date - start); | |||
|
|||
var start = new Date | |||
, n = times; | |||
|
|||
while (n--) old.parse('user[name][first]=tj&user[name][last]=holowaychuk'); | |||
console.log('old nested: %dms', new Date - start); | |||
|
|||
|
|||
console.log(); | |||
|
|||
|
|||
var start = new Date | |||
, n = times; | |||
|
|||
while (n--) qs.parse('foo=bar'); | |||
console.log('new simple: %dms', new Date - start); | |||
|
|||
var start = new Date | |||
, n = times; | |||
|
|||
while (n--) qs.parse('user[name][first]=tj&user[name][last]=holowaychuk'); | |||
console.log('new nested: %dms', new Date - start); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,21 @@ | |||
|
|||
/** | |||
* Module dependencies. | |||
*/ | |||
|
|||
var qs = require('./'); | |||
|
|||
var obj = qs.parse('users[]'); | |||
require('inspect')(obj) | |||
|
|||
var obj = qs.parse('name=tj&email=tj@vision-media.ca'); | |||
require('inspect')(obj) | |||
|
|||
var obj = qs.parse('users[]=tj&users[]=tobi&users[]=jane'); | |||
require('inspect')(obj) | |||
|
|||
var obj = qs.parse('user[name][first]=tj&user[name][last]=holowaychuk'); | |||
require('inspect')(obj) | |||
|
|||
var obj = qs.parse('users[][name][first]=tj&users[][name][last]=holowaychuk'); | |||
require('inspect')(obj) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,2 @@ | |||
|
|||
module.exports = require('./lib/querystring'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,59 @@ | |||
|
|||
/*! | |||
* querystring | |||
* Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca> | |||
* MIT Licensed | |||
*/ | |||
|
|||
/** | |||
* Library version. | |||
*/ | |||
|
|||
exports.version = '0.0.1'; | |||
|
|||
exports.parse = function(str) { | |||
return String(str) | |||
.split('&') | |||
.reduce(function(ret, pair){ | |||
var parts = decodeURIComponent(pair).split('=') | |||
, obj = ret | |||
, key = parts.shift() | |||
, val = parts.join('='); | |||
|
|||
// nested | |||
if (~key.indexOf(']')) { | |||
var parts = key.split('[') | |||
, len = parts.length | |||
, last = len - 1; | |||
|
|||
function parse(obj, parts, parent, key) { | |||
var part = parts.shift(); | |||
|
|||
// end | |||
if (!part) { | |||
parent[key] = val; | |||
// array | |||
} else if (']' == part) { | |||
obj = parent[key] = Array.isArray(parent[key]) | |||
? parent[key] | |||
: []; | |||
if ('' != val) obj.push(val); | |||
// prop | |||
} else if (~part.indexOf(']')) { | |||
part = part.substr(0, part.length - 1); | |||
parse(obj[part] = obj[part] || {}, parts, obj, part); | |||
// key | |||
} else { | |||
parse(obj[part] = obj[part] || {}, parts, obj, part); | |||
} | |||
} | |||
|
|||
parse(obj, parts); | |||
// optimize | |||
} else { | |||
obj[key] = val; | |||
} | |||
|
|||
return ret; | |||
}, {}); | |||
}; |
Submodule expresso
added at
2c8759
Submodule should
added at
c05fac
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,82 @@ | |||
|
|||
/** | |||
* Module dependencies. | |||
*/ | |||
|
|||
var qs = require('../') | |||
, should = require('should'); | |||
|
|||
module.exports = { | |||
'test basics': function(){ | |||
qs.parse('foo') | |||
.should.eql({ foo: '' }); | |||
|
|||
qs.parse('foo=bar') | |||
.should.eql({ foo: 'bar' }); | |||
|
|||
qs.parse('foo%3Dbar=baz') | |||
.should.eql({ foo: 'bar=baz' }); | |||
|
|||
qs.parse(' foo = bar = baz ') | |||
.should.eql({ ' foo ': ' bar = baz ' }); | |||
|
|||
qs.parse('foo=bar=baz') | |||
.should.eql({ foo: 'bar=baz' }); | |||
|
|||
qs.parse('foo=bar&bar=baz') | |||
.should.eql({ foo: 'bar', bar: 'baz' }); | |||
|
|||
qs.parse('foo=bar&baz') | |||
.should.eql({ foo: 'bar', baz: '' }); | |||
|
|||
qs.parse('cht=p3&chd=t:60,40&chs=250x100&chl=Hello|World') | |||
.should.eql({ | |||
cht: 'p3' | |||
, chd: 't:60,40' | |||
, chs: '250x100' | |||
, chl: 'Hello|World' | |||
}); | |||
}, | |||
|
|||
'test nesting': function(){ | |||
qs.parse('user[name]=tj') | |||
.should.eql({ user: { name: 'tj' }}); | |||
|
|||
qs.parse('user[name][first]=tj&user[name][last]=holowaychuk') | |||
.should.eql({ user: { name: { first: 'tj', last: 'holowaychuk' }}}); | |||
}, | |||
|
|||
'test escaping': function(){ | |||
qs.parse('foo=foo%20bar') | |||
.should.eql({ foo: 'foo bar' }); | |||
}, | |||
|
|||
'test arrays': function(){ | |||
qs.parse('images[]') | |||
.should.eql({ images: [] }); | |||
|
|||
qs.parse('user[]=tj') | |||
.should.eql({ user: ['tj'] }); | |||
|
|||
qs.parse('user[]=tj&user[]=tobi&user[]=jane') | |||
.should.eql({ user: ['tj', 'tobi', 'jane'] }); | |||
|
|||
qs.parse('user[names][]=tj&user[names][]=tyler') | |||
.should.eql({ user: { names: ['tj', 'tyler'] }}); | |||
|
|||
qs.parse('user[names][]=tj&user[names][]=tyler&user[email]=tj@vision-media.ca') | |||
.should.eql({ user: { names: ['tj', 'tyler'], email: 'tj@vision-media.ca' }}); | |||
}, | |||
|
|||
// 'test complex': function(){ | |||
// qs.parse('users[][name][first]=tj&users[foo]=bar') | |||
// .should.eql({ | |||
// users: [ { name: 'tj' }, { name: 'tobi' }, { foo: 'bar' }] | |||
// }); | |||
// | |||
// qs.parse('users[][name][first]=tj&users[][name][first]=tobi') | |||
// .should.eql({ | |||
// users: [ { name: 'tj' }, { name: 'tobi' }] | |||
// }); | |||
// } | |||
}; |