mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-22 03:55:17 +08:00
# Conflicts: # jsowell-ui/.env.development # jsowell-ui/.env.staging # jsowell-ui/bin/build-sit.bat # jsowell-ui/bin/build.bat # jsowell-ui/src/api/adapayMember/adapayMember.js # jsowell-ui/src/api/pile/merchant.js # jsowell-ui/src/router/index.js # jsowell-ui/src/views/financial/financeDetail.vue # jsowell-ui/src/views/financial/merchant.vue # jsowell-ui/src/views/homeIndex/homeIndex.vue # jsowell-ui/src/views/login.vue # jsowell-ui/src/views/pile/basic/detail.vue # jsowell-ui/src/views/pile/station/components/SiteInfo.vue # jsowell-ui/src/views/pile/station/detail.vue # jsowell-ui/src/views/pile/station/orderReport.vue
88 lines
1.7 KiB
JavaScript
88 lines
1.7 KiB
JavaScript
'use strict';
|
|
|
|
const internals = {};
|
|
|
|
|
|
module.exports = function (input) {
|
|
|
|
if (!input) {
|
|
return '';
|
|
}
|
|
|
|
let escaped = '';
|
|
|
|
for (let i = 0; i < input.length; ++i) {
|
|
|
|
const charCode = input.charCodeAt(i);
|
|
|
|
if (internals.isSafe(charCode)) {
|
|
escaped += input[i];
|
|
}
|
|
else {
|
|
escaped += internals.escapeHtmlChar(charCode);
|
|
}
|
|
}
|
|
|
|
return escaped;
|
|
};
|
|
|
|
|
|
internals.escapeHtmlChar = function (charCode) {
|
|
|
|
const namedEscape = internals.namedHtml[charCode];
|
|
if (typeof namedEscape !== 'undefined') {
|
|
return namedEscape;
|
|
}
|
|
|
|
if (charCode >= 256) {
|
|
return '&#' + charCode + ';';
|
|
}
|
|
|
|
const hexValue = charCode.toString(16).padStart(2, '0');
|
|
return `&#x${hexValue};`;
|
|
};
|
|
|
|
|
|
internals.isSafe = function (charCode) {
|
|
|
|
return (typeof internals.safeCharCodes[charCode] !== 'undefined');
|
|
};
|
|
|
|
|
|
internals.namedHtml = {
|
|
'38': '&',
|
|
'60': '<',
|
|
'62': '>',
|
|
'34': '"',
|
|
'160': ' ',
|
|
'162': '¢',
|
|
'163': '£',
|
|
'164': '¤',
|
|
'169': '©',
|
|
'174': '®'
|
|
};
|
|
|
|
|
|
internals.safeCharCodes = (function () {
|
|
|
|
const safe = {};
|
|
|
|
for (let i = 32; i < 123; ++i) {
|
|
|
|
if ((i >= 97) || // a-z
|
|
(i >= 65 && i <= 90) || // A-Z
|
|
(i >= 48 && i <= 57) || // 0-9
|
|
i === 32 || // space
|
|
i === 46 || // .
|
|
i === 44 || // ,
|
|
i === 45 || // -
|
|
i === 58 || // :
|
|
i === 95) { // _
|
|
|
|
safe[i] = null;
|
|
}
|
|
}
|
|
|
|
return safe;
|
|
}());
|