Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
jajbshjahavahh
GitHub Repository: jajbshjahavahh/Gojo-Satoru
Path: blob/master/node_modules/@hapi/hoek/lib/escapeJson.js
2593 views
1
'use strict';
2
3
const internals = {};
4
5
6
module.exports = function (input) {
7
8
if (!input) {
9
return '';
10
}
11
12
const lessThan = 0x3C;
13
const greaterThan = 0x3E;
14
const andSymbol = 0x26;
15
const lineSeperator = 0x2028;
16
17
// replace method
18
let charCode;
19
return input.replace(/[<>&\u2028\u2029]/g, (match) => {
20
21
charCode = match.charCodeAt(0);
22
23
if (charCode === lessThan) {
24
return '\\u003c';
25
}
26
27
if (charCode === greaterThan) {
28
return '\\u003e';
29
}
30
31
if (charCode === andSymbol) {
32
return '\\u0026';
33
}
34
35
if (charCode === lineSeperator) {
36
return '\\u2028';
37
}
38
39
return '\\u2029';
40
});
41
};
42
43