-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
Copy pathURLDecode.mjs
59 lines (52 loc) · 1.37 KB
/
URLDecode.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
/**
* @author n1474335 [[email protected]]
* @copyright Crown Copyright 2016
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
/**
* URL Decode operation
*/
class URLDecode extends Operation {
/**
* URLDecode constructor
*/
constructor() {
super();
this.name = "URL Decode";
this.module = "URL";
this.description = "Converts URI/URL percent-encoded characters back to their raw values.<br><br>e.g. <code>%3d</code> becomes <code>=</code>";
this.infoURL = "https://wikipedia.org/wiki/Percent-encoding";
this.inputType = "string";
this.outputType = "string";
this.args = [
{
"name": "Treat \"+\" as space",
"type": "boolean",
"value": false
},
];
this.checks = [
{
pattern: ".*(?:%[\\da-f]{2}.*){4}",
flags: "i",
args: []
},
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
const plusIsSpace = args[0];
const data = plusIsSpace ? input.replace(/\+/g, "%20") : input;
try {
return decodeURIComponent(data);
} catch (err) {
return unescape(data);
}
}
}
export default URLDecode;