forked from sindresorhus/query-string
-
Notifications
You must be signed in to change notification settings - Fork 1
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 ddd0bd1
Showing
11 changed files
with
278 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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# editorconfig.org | ||
root = true | ||
|
||
[*] | ||
indent_style = tab | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* text=auto |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"node": true, | ||
"esnext": true, | ||
"bitwise": true, | ||
"camelcase": true, | ||
"curly": true, | ||
"eqeqeq": true, | ||
"immed": true, | ||
"indent": 4, | ||
"latedef": true, | ||
"newcap": true, | ||
"noarg": true, | ||
"quotmark": "single", | ||
"regexp": true, | ||
"undef": true, | ||
"unused": true, | ||
"strict": true, | ||
"trailing": true, | ||
"smarttabs": true | ||
} |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
language: node_js | ||
node_js: | ||
- '0.10' | ||
- '0.8' |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "query-string", | ||
"version": "0.0.0", | ||
"description": "Parse and stringify URL query strings", | ||
"main": "query-string.js", | ||
"keywords": [ | ||
"querystring", | ||
"query", | ||
"string", | ||
"qs", | ||
"param", | ||
"parameter", | ||
"url", | ||
"uri", | ||
"parse", | ||
"stringify", | ||
"encode", | ||
"decode" | ||
], | ||
"ignore": [ | ||
".*", | ||
"test.js", | ||
"component.json", | ||
"package.json" | ||
] | ||
} |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "query-string", | ||
"version": "0.0.0", | ||
"description": "Parse and stringify URL query strings", | ||
"repo": "sindresorhus/query-string", | ||
"keywords": [ | ||
"querystring", | ||
"query", | ||
"string", | ||
"qs", | ||
"param", | ||
"parameter", | ||
"url", | ||
"uri", | ||
"parse", | ||
"stringify", | ||
"encode", | ||
"decode" | ||
], | ||
"main": "query-string.js", | ||
"scripts": ["query-string.js"], | ||
"license": "MIT" | ||
} |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ | ||
"name": "query-string", | ||
"version": "0.0.0", | ||
"description": "Parse and stringify URL query strings", | ||
"keywords": [ | ||
"browser", | ||
"querystring", | ||
"query", | ||
"string", | ||
"qs", | ||
"param", | ||
"parameter", | ||
"url", | ||
"uri", | ||
"parse", | ||
"stringify", | ||
"encode", | ||
"decode" | ||
], | ||
"license": "MIT", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "[email protected]", | ||
"url": "http://sindresorhus.com" | ||
}, | ||
"files": [ | ||
"query-string.js" | ||
], | ||
"main": "query-string", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/sindresorhus/query-string.git" | ||
}, | ||
"scripts": { | ||
"test": "mocha" | ||
}, | ||
"devDependencies": { | ||
"mocha": "~1.14.0" | ||
}, | ||
"engines": { | ||
"node": ">=0.8.0" | ||
} | ||
} |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/*! | ||
query-string | ||
Parse and stringify URL query strings | ||
https://github.com/sindresorhus/query-string | ||
by Sindre Sorhus | ||
MIT License | ||
*/ | ||
(function () { | ||
'use strict'; | ||
var queryString = {}; | ||
|
||
queryString.parse = function (str) { | ||
if (typeof str !== 'string') { | ||
return {}; | ||
} | ||
|
||
str = str.trim().replace(/^\?/, ''); | ||
|
||
if (!str) { | ||
return {}; | ||
} | ||
|
||
return str.trim().split('&').reduce(function (ret, param) { | ||
var parts = param.split('='); | ||
// missing `=` should be `null`: | ||
// http://w3.org/TR/2012/WD-url-20120524/#collect-url-parameters | ||
ret[parts[0]] = parts[1] === undefined ? null : decodeURIComponent(parts[1]); | ||
return ret; | ||
}, {}); | ||
}; | ||
|
||
queryString.stringify = function (obj) { | ||
return obj ? Object.keys(obj).map(function (key) { | ||
return encodeURIComponent(key) + '=' + encodeURIComponent(obj[key]); | ||
}).join('&') : ''; | ||
}; | ||
|
||
if (typeof module !== 'undefined' && module.exports) { | ||
module.exports = queryString; | ||
} else { | ||
window.queryString = 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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# query-string [](http://travis-ci.org/sindresorhus/query-string) | ||
|
||
> Parse and stringify URL [query strings](http://en.wikipedia.org/wiki/Query_string) | ||
|
||
## Install | ||
|
||
Download [manually](https://github.com/sindresorhus/query-string/releases) or with a package-manager. | ||
|
||
#### [npm](https://npmjs.org/package/query-string) | ||
|
||
``` | ||
npm install --save query-string | ||
``` | ||
|
||
#### [Bower](http://bower.io) | ||
|
||
``` | ||
bower install --save query-string | ||
``` | ||
|
||
#### [Component](https://github.com/component/component) | ||
|
||
``` | ||
component install sindresorhus/query-string | ||
``` | ||
|
||
|
||
## Example using Node.js | ||
|
||
```js | ||
var queryString = require('query-string'); | ||
|
||
var url = 'http://sindresorhus.com?foo=bar'.split('?'); | ||
var parsed = queryString.parse(url[1]); | ||
console.log(parsed); | ||
// {foo: 'bar'} | ||
|
||
parsed.foo = 'unicorn'; | ||
parsed.ilike = 'pizza'; | ||
console.log(url[0] + '?' + queryString.stringify(parsed)); | ||
// http://sindresorhus.com?foo=unicorn&ilike=pizza | ||
``` | ||
|
||
|
||
## API | ||
|
||
### queryString.parse() | ||
|
||
Parse a query string into an object. | ||
|
||
### queryString.stringify() | ||
|
||
Stringify an object into a query string. | ||
|
||
|
||
## License | ||
|
||
MIT © [Sindre Sorhus](http://sindresorhus.com) |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/*global describe, it */ | ||
'use strict'; | ||
var assert = require('assert'); | ||
var qs = require('./query-string'); | ||
|
||
|
||
describe('.parse()', function () { | ||
it('should handle query strings starting with a `?`', function () { | ||
assert.deepEqual(qs.parse('?foo=bar'), {foo: 'bar'}); | ||
}); | ||
|
||
it('should parse a qseter', function () { | ||
assert.deepEqual(qs.parse('foo=bar'), {foo: 'bar'}); | ||
}); | ||
|
||
it('should parse multiple qseters', function () { | ||
assert.deepEqual(qs.parse('foo=bar&key=val'), {foo: 'bar', key: 'val'}); | ||
}); | ||
|
||
it('should parse qseters without a value', function () { | ||
assert.deepEqual(qs.parse('foo'), {foo: null}); | ||
assert.deepEqual(qs.parse('foo&key'), {foo: null, key: null}); | ||
assert.deepEqual(qs.parse('foo=bar&key'), {foo: 'bar', key: null}); | ||
}); | ||
|
||
it('should return empty object if no qss can be found', function () { | ||
assert.deepEqual(qs.parse('?'), {}); | ||
assert.deepEqual(qs.parse(' '), {}); | ||
}); | ||
}); | ||
|
||
describe('.stringify()', function () { | ||
it('should stringify', function () { | ||
assert.strictEqual(qs.stringify({foo: 'bar'}), 'foo=bar'); | ||
assert.strictEqual(qs.stringify({foo: 'bar', bar: 'baz'}), 'foo=bar&bar=baz'); | ||
}); | ||
|
||
it('should handle different types', function () { | ||
assert.strictEqual(qs.stringify(), ''); | ||
assert.strictEqual(qs.stringify(0), ''); | ||
}); | ||
|
||
it('should URI encode', function () { | ||
assert.strictEqual(qs.stringify({'foo bar': 'baz faz'}), 'foo%20bar=baz%20faz'); | ||
}); | ||
}); |