Skip to content

Commit 12e4bd4

Browse files
committed
first commit
0 parents  commit 12e4bd4

9 files changed

Lines changed: 3484 additions & 0 deletions

File tree

.babelrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"plugins": [
3+
["transform-es2015-modules-umd", {}],
4+
],
5+
}

.editorconfig

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = lf
5+
insert_final_newline = true
6+
charset = utf-8
7+
trim_trailing_whitespace = true
8+
9+
[*.{js,jsx,css,less,scss}]
10+
indent_style = tab
11+
tab_width = 2
12+
trim_trailing_whitespace = true
13+
14+
[*.{html,hbr,rt,sass}]
15+
indent_style = space
16+
indent_size = 2
17+
trim_trailing_whitespace = true
18+
19+
[*.json]
20+
indent_style = space
21+
indent_size = 2
22+
trim_trailing_whitespace = true
23+
24+
[*.md]
25+
trim_trailing_whitespace = false
26+
indent_size = 2

.eslintrc

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"parser": "babel-eslint",
3+
"plugins": [
4+
"jest",
5+
],
6+
"extends": [
7+
"standard",
8+
"plugin:promise/recommended",
9+
"plugin:import/recommended",
10+
"plugin:jest/recommended",
11+
],
12+
"env": {
13+
"browser": true,
14+
"node": true,
15+
"es6": true,
16+
"mocha": true,
17+
"jest": true,
18+
},
19+
"rules": {
20+
"import/no-absolute-path": 2,
21+
"import/no-extraneous-dependencies": 2,
22+
"import/no-mutable-exports": 2,
23+
"import/newline-after-import": 1,
24+
"import/unambiguous": 0,
25+
26+
"promise/avoid-new": 0,
27+
"promise/no-callback-in-promise": 0,
28+
"promise/always-return": 0,
29+
30+
"semi": [1, "always"],
31+
"no-tabs": 0,
32+
"comma-dangle": 0,
33+
"indent": [2, "tab", {
34+
"SwitchCase": 1
35+
}],
36+
"padded-blocks": 0,
37+
"space-before-function-paren": [1, {
38+
"anonymous": "always",
39+
"named": "never"
40+
}],
41+
"max-len": [1, {
42+
"code": 80,
43+
"tabWidth": 2,
44+
"ignoreComments": true,
45+
"ignoreStrings": true,
46+
"ignoreUrls": true,
47+
"ignoreRegExpLiterals": true,
48+
}],
49+
"brace-style": 0,
50+
"operator-linebreak": [1, "after"],
51+
"camelcase": 0,
52+
"no-multiple-empty-lines": [1, {
53+
"max": 2,
54+
}],
55+
"no-unused-vars": 1,
56+
"spaced-comment": 0,
57+
},
58+
"globals": {
59+
"__DEV__": true,
60+
},
61+
}

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.DS_Store
2+
.DS_Store?
3+
._*
4+
.Spotlight-V100
5+
.Trashes
6+
ehthumbs.db
7+
Thumbs.db
8+
.log
9+
.logs
10+
*.log
11+
node_modules
12+
lib

LICENSE.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
MIT License
2+
3+
Copyright (c) 2016 Webb
4+
5+
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:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
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.

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# tiny-querystring
2+
3+
## License
4+
5+
MIT

package.json

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"name": "tiny-querystring",
3+
"description": "Tiny parsing and formatting URL query strings for Node.js and browser",
4+
"version": "0.0.0",
5+
"main": "lib/index",
6+
"files": [
7+
"*.md",
8+
"lib"
9+
],
10+
"scripts": {
11+
"start": "yarn test -- --watchAll",
12+
"test": "cross-env NODE_ENV=development jest",
13+
"prebuild": "rimraf lib",
14+
"build": "babel src -d lib",
15+
"preversion": "yarn test && yarn build"
16+
},
17+
"author": "Cap32",
18+
"repository": "Cap32/tiny-querystring",
19+
"keywords": [],
20+
"license": "MIT",
21+
"dependencies": {},
22+
"devDependencies": {
23+
"babel-cli": "^6.11.4",
24+
"babel-core": "^6.13.2",
25+
"babel-eslint": "^7.2.3",
26+
"babel-plugin-transform-es2015-modules-umd": "^6.24.1",
27+
"babel-polyfill": "^6.13.0",
28+
"babel-preset-stage-0": "^6.5.0",
29+
"babel-register": "^6.11.6",
30+
"cross-env": "^4.0.0",
31+
"eslint": "^3.19.0",
32+
"eslint-config-standard": "^10.2.1",
33+
"eslint-plugin-import": "^2.2.0",
34+
"eslint-plugin-jest": "^19.0.1",
35+
"eslint-plugin-node": "^4.2.2",
36+
"eslint-plugin-promise": "^3.5.0",
37+
"eslint-plugin-standard": "^3.0.1",
38+
"jest": "^20.0.4",
39+
"rimraf": "^2.5.4"
40+
},
41+
"jest": {
42+
"collectCoverageFrom": [
43+
"src/**/*.js"
44+
],
45+
"modulePathIgnorePatterns": [
46+
"node_modules",
47+
"lib"
48+
]
49+
}
50+
}

src/index.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
exports.parse = function parse(str) {
3+
return (str + '')
4+
.replace(/\+/g, ' ')
5+
.split('&')
6+
.filter(function (item) {
7+
return !/^\s*$/.test(item);
8+
})
9+
.reduce(function (obj, item, index) {
10+
var ref = item.split('=');
11+
var key = ref[0] || '';
12+
var val = ref[1] || '';
13+
var prev = obj[key];
14+
obj[key] = typeof prev === 'undefined' ? val : [].concat(prev, val);
15+
return obj;
16+
}, {})
17+
;
18+
};
19+
20+
exports.stringify = function stringify(obj) {
21+
return Object.keys(obj || {})
22+
.reduce(function (arr, key) {
23+
var val = obj[key];
24+
if (val instanceof Array) { val = val.join('&' + key + '='); }
25+
arr.push(key + '=' + val);
26+
return arr;
27+
}, [])
28+
.join('&')
29+
.replace(/\s/g, '+')
30+
;
31+
};

0 commit comments

Comments
 (0)