-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
Copy pathQueryStringEncode.mjs
64 lines (59 loc) · 1.66 KB
/
QueryStringEncode.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* @author Benjamin Altpeter [[email protected]]
* @copyright Crown Copyright 2022
* @license Apache-2.0
*/
import qs from "qs";
import Operation from "../Operation.mjs";
/**
* Query String Encode operation
*/
class QueryStringEncode extends Operation {
/**
* QueryStringEncode constructor
*/
constructor() {
super();
this.name = "Query String Encode";
this.module = "URL";
this.description =
"Converts JSON objects into a URL query string representation.<br><br>e.g. <code>{"a": "b", "c": 1}</code> becomes <code>a=b&c=1</code>";
this.infoURL = "https://wikipedia.org/wiki/Query_string";
this.inputType = "JSON";
this.outputType = "string";
this.args = [
{
name: "Array format",
type: "option",
value: ["brackets", "indices", "repeat", "comma"],
defaultIndex: 0,
},
{
name: "Object format",
type: "option",
value: ["brackets", "dots"],
defaultIndex: 0,
},
{
name: "Delimiter",
type: "string",
value: "&",
},
];
}
/**
* @param {JSON} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
const [arrayFormat, objectFormat, delimiter] = args;
return qs.stringify(input, {
arrayFormat,
delimiter,
allowDots: objectFormat === "dots",
encode: false,
});
}
}
export default QueryStringEncode;