Path: blob/master/node_modules/@hapi/hoek/lib/escapeHtml.js
2593 views
'use strict';12const internals = {};345module.exports = function (input) {67if (!input) {8return '';9}1011let escaped = '';1213for (let i = 0; i < input.length; ++i) {1415const charCode = input.charCodeAt(i);1617if (internals.isSafe(charCode)) {18escaped += input[i];19}20else {21escaped += internals.escapeHtmlChar(charCode);22}23}2425return escaped;26};272829internals.escapeHtmlChar = function (charCode) {3031const namedEscape = internals.namedHtml[charCode];32if (typeof namedEscape !== 'undefined') {33return namedEscape;34}3536if (charCode >= 256) {37return '&#' + charCode + ';';38}3940const hexValue = charCode.toString(16).padStart(2, '0');41return `&#x${hexValue};`;42};434445internals.isSafe = function (charCode) {4647return (typeof internals.safeCharCodes[charCode] !== 'undefined');48};495051internals.namedHtml = {52'38': '&',53'60': '<',54'62': '>',55'34': '"',56'160': ' ',57'162': '¢',58'163': '£',59'164': '¤',60'169': '©',61'174': '®'62};636465internals.safeCharCodes = (function () {6667const safe = {};6869for (let i = 32; i < 123; ++i) {7071if ((i >= 97) || // a-z72(i >= 65 && i <= 90) || // A-Z73(i >= 48 && i <= 57) || // 0-974i === 32 || // space75i === 46 || // .76i === 44 || // ,77i === 45 || // -78i === 58 || // :79i === 95) { // _8081safe[i] = null;82}83}8485return safe;86}());878889