react / wstein / node_modules / jest-cli / node_modules / jsdom / node_modules / request / node_modules / hawk / node_modules / hoek / lib / escape.js
81154 views// Declare internals12var internals = {};345exports.escapeJavaScript = function (input) {67if (!input) {8return '';9}1011var escaped = '';1213for (var i = 0, il = input.length; i < il; ++i) {1415var charCode = input.charCodeAt(i);1617if (internals.isSafe(charCode)) {18escaped += input[i];19}20else {21escaped += internals.escapeJavaScriptChar(charCode);22}23}2425return escaped;26};272829exports.escapeHtml = function (input) {3031if (!input) {32return '';33}3435var escaped = '';3637for (var i = 0, il = input.length; i < il; ++i) {3839var charCode = input.charCodeAt(i);4041if (internals.isSafe(charCode)) {42escaped += input[i];43}44else {45escaped += internals.escapeHtmlChar(charCode);46}47}4849return escaped;50};515253internals.escapeJavaScriptChar = function (charCode) {5455if (charCode >= 256) {56return '\\u' + internals.padLeft('' + charCode, 4);57}5859var hexValue = new Buffer(String.fromCharCode(charCode), 'ascii').toString('hex');60return '\\x' + internals.padLeft(hexValue, 2);61};626364internals.escapeHtmlChar = function (charCode) {6566var namedEscape = internals.namedHtml[charCode];67if (typeof namedEscape !== 'undefined') {68return namedEscape;69}7071if (charCode >= 256) {72return '&#' + charCode + ';';73}7475var hexValue = new Buffer(String.fromCharCode(charCode), 'ascii').toString('hex');76return '&#x' + internals.padLeft(hexValue, 2) + ';';77};787980internals.padLeft = function (str, len) {8182while (str.length < len) {83str = '0' + str;84}8586return str;87};888990internals.isSafe = function (charCode) {9192return (typeof internals.safeCharCodes[charCode] !== 'undefined');93};949596internals.namedHtml = {97'38': '&',98'60': '<',99'62': '>',100'34': '"',101'160': ' ',102'162': '¢',103'163': '£',104'164': '¤',105'169': '©',106'174': '®'107};108109110internals.safeCharCodes = (function () {111112var safe = {};113114for (var i = 32; i < 123; ++i) {115116if ((i >= 97) || // a-z117(i >= 65 && i <= 90) || // A-Z118(i >= 48 && i <= 57) || // 0-9119i === 32 || // space120i === 46 || // .121i === 44 || // ,122i === 45 || // -123i === 58 || // :124i === 95) { // _125126safe[i] = null;127}128}129130return safe;131}());132133134