Skip to content

Commit bcfff60

Browse files
committed
init
0 parents  commit bcfff60

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

Diff for: README.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# JSON to HTTP Query string
2+
> This package allows you to convert JSON to Http query string.
3+
4+
## Getting Started
5+
To install the module, run the following in the command line:
6+
```bash
7+
npm i json-to-http-query-string --save
8+
```
9+
Use within your application with the following line of JavaScript:
10+
```js
11+
const jsonToQuery = require('json-to-http-query-string');
12+
```
13+
Example:
14+
```js
15+
jsonToQuery({
16+
foo: "hi",
17+
bar: {
18+
blah: [1, 2, 3],
19+
blah2: 123
20+
}
21+
})
22+
//foo=hi&bar%5Bblah%5D%5B0%5D=1&bar%5Bblah%5D%5B1%5D=2&bar%5Bblah%5D%5B2%5D=3&bar%5Bblah2%5D=123
23+
```

Diff for: index.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const jsonToQuery = function (obj, prefix) {
2+
var str = [], p;
3+
for (p in obj) {
4+
if (obj.hasOwnProperty(p)) {
5+
var k = prefix ? prefix + "[" + p + "]" : p,
6+
v = obj[p];
7+
str.push(
8+
v !== null && typeof v === "object"
9+
? serialize(v, k)
10+
: encodeURIComponent(k) + "=" + encodeURIComponent(v)
11+
);
12+
}
13+
}
14+
return str.join("&");
15+
};
16+
17+
module.exports = jsonToQuery;

Diff for: package.json

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "json-to-http-query-string",
3+
"version": "1.0.0",
4+
"description": "Convert JSON to HTTP Query string",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/SyysBiir/json-to-http-query-string.git"
12+
},
13+
"keywords": [
14+
"json",
15+
"http",
16+
"request",
17+
"data",
18+
"url",
19+
"website",
20+
"ajax",
21+
"fetch",
22+
"request",
23+
"http"
24+
],
25+
"author": "Maxim Boyanov",
26+
"license": "MIT",
27+
"bugs": {
28+
"url": "https://github.com/SyysBiir/json-to-http-query-string/issues"
29+
},
30+
"homepage": "https://github.com/SyysBiir/json-to-http-query-string#readme"
31+
}

0 commit comments

Comments
 (0)