-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
Copy pathQueryStringDecode.mjs
74 lines (69 loc) · 1.88 KB
/
QueryStringDecode.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
65
66
67
68
69
70
71
72
73
74
/**
* @author Benjamin Altpeter [[email protected]]
* @copyright Crown Copyright 2022
* @license Apache-2.0
*/
import qs from "qs";
import Operation from "../Operation.mjs";
/**
* Query String Decode operation
*/
class QueryStringDecode extends Operation {
/**
* QueryStringDecode constructor
*/
constructor() {
super();
this.name = "Query String Decode";
this.module = "URL";
this.description =
"Converts URL query strings into a JSON 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 = "string";
this.outputType = "JSON";
this.args = [
{
name: "Depth",
type: "number",
value: 5,
},
{
name: "Parameter limit",
type: "number",
value: 1000,
},
{
name: "Delimiter",
type: "string",
value: "&",
},
{
name: "Allow dot notation (<code>a.b=c</code>)?",
type: "boolean",
value: false,
},
{
name: "Allow comma arrays (<code>a=b,c</code>)?",
type: "boolean",
value: false,
},
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {JSON}
*/
run(input, args) {
const [depth, parameterLimit, delimiter, allowDots, comma] = args;
return qs.parse(input, {
depth,
delimiter,
parameterLimit,
allowDots,
comma,
ignoreQueryPrefix: true,
});
}
}
export default QueryStringDecode;