web.js
1.04 KB
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
'use strict';
/**
* Escape the given string of `html`.
*
* @param {String} html
* @return {String}
* @public
*/
exports.escape = require('escape-html');
/**
* Unescape the given string from html
* @param {String} html
* @param {String} type
* @return {String}
* @public
*/
exports.unescape = require('unescape');
/**
* Safe encodeURIComponent, won't throw any error.
* If `encodeURIComponent` error happen, just return the original value.
*
* @param {String} text
* @return {String} URL encode string.
*/
exports.encodeURIComponent = function encodeURIComponent_(text) {
try {
return encodeURIComponent(text);
} catch (e) {
return text;
}
};
/**
* Safe decodeURIComponent, won't throw any error.
* If `decodeURIComponent` error happen, just return the original value.
*
* @param {String} encodeText
* @return {String} URL decode original string.
*/
exports.decodeURIComponent = function decodeURIComponent_(encodeText) {
try {
return decodeURIComponent(encodeText);
} catch (e) {
return encodeText;
}
};