tenebrous-dicebot/api/node_modules/html-entities/lib/html5-entities.js

168 lines
49 KiB
JavaScript
Raw Normal View History

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var surrogate_pairs_1 = require("./surrogate-pairs");
var ENTITIES = [['Aacute', [193]], ['aacute', [225]], ['Abreve', [258]], ['abreve', [259]], ['ac', [8766]], ['acd', [8767]], ['acE', [8766, 819]], ['Acirc', [194]], ['acirc', [226]], ['acute', [180]], ['Acy', [1040]], ['acy', [1072]], ['AElig', [198]], ['aelig', [230]], ['af', [8289]], ['Afr', [120068]], ['afr', [120094]], ['Agrave', [192]], ['agrave', [224]], ['alefsym', [8501]], ['aleph', [8501]], ['Alpha', [913]], ['alpha', [945]], ['Amacr', [256]], ['amacr', [257]], ['amalg', [10815]], ['amp', [38]], ['AMP', [38]], ['andand', [10837]], ['And', [10835]], ['and', [8743]], ['andd', [10844]], ['andslope', [10840]], ['andv', [10842]], ['ang', [8736]], ['ange', [10660]], ['angle', [8736]], ['angmsdaa', [10664]], ['angmsdab', [10665]], ['angmsdac', [10666]], ['angmsdad', [10667]], ['angmsdae', [10668]], ['angmsdaf', [10669]], ['angmsdag', [10670]], ['angmsdah', [10671]], ['angmsd', [8737]], ['angrt', [8735]], ['angrtvb', [8894]], ['angrtvbd', [10653]], ['angsph', [8738]], ['angst', [197]], ['angzarr', [9084]], ['Aogon', [260]], ['aogon', [261]], ['Aopf', [120120]], ['aopf', [120146]], ['apacir', [10863]], ['ap', [8776]], ['apE', [10864]], ['ape', [8778]], ['apid', [8779]], ['apos', [39]], ['ApplyFunction', [8289]], ['approx', [8776]], ['approxeq', [8778]], ['Aring', [197]], ['aring', [229]], ['Ascr', [119964]], ['ascr', [119990]], ['Assign', [8788]], ['ast', [42]], ['asymp', [8776]], ['asympeq', [8781]], ['Atilde', [195]], ['atilde', [227]], ['Auml', [196]], ['auml', [228]], ['awconint', [8755]], ['awint', [10769]], ['backcong', [8780]], ['backepsilon', [1014]], ['backprime', [8245]], ['backsim', [8765]], ['backsimeq', [8909]], ['Backslash', [8726]], ['Barv', [10983]], ['barvee', [8893]], ['barwed', [8965]], ['Barwed', [8966]], ['barwedge', [8965]], ['bbrk', [9141]], ['bbrktbrk', [9142]], ['bcong', [8780]], ['Bcy', [1041]], ['bcy', [1073]], ['bdquo', [8222]], ['becaus', [8757]], ['because', [8757]], ['Because', [8757]], ['bemptyv', [10672]], ['bepsi', [1014]], ['bernou', [8492]], ['Bernoullis', [8492]], ['Beta', [914]], ['beta', [946]], ['beth', [8502]], ['between', [8812]], ['Bfr', [120069]], ['bfr', [120095]], ['bigcap', [8898]], ['bigcirc', [9711]], ['bigcup', [8899]], ['bigodot', [10752]], ['bigoplus', [10753]], ['bigotimes', [10754]], ['bigsqcup', [10758]], ['bigstar', [9733]], ['bigtriangledown', [9661]], ['bigtriangleup', [9651]], ['biguplus', [10756]], ['bigvee', [8897]], ['bigwedge', [8896]], ['bkarow', [10509]], ['blacklozenge', [10731]], ['blacksquare', [9642]], ['blacktriangle', [9652]], ['blacktriangledown', [9662]], ['blacktriangleleft', [9666]], ['blacktriangleright', [9656]], ['blank', [9251]], ['blk12', [9618]], ['blk14', [9617]], ['blk34', [9619]], ['block', [9608]], ['bne', [61, 8421]], ['bnequiv', [8801, 8421]], ['bNot', [10989]], ['bnot', [8976]], ['Bopf', [120121]], ['bopf', [120147]], ['bot', [8869]], ['bottom', [8869]], ['bowtie', [8904]], ['boxbox', [10697]], ['boxdl', [9488]], ['boxdL', [9557]], ['boxDl', [9558]], ['boxDL', [9559]], ['boxdr', [9484]], ['boxdR', [9554]], ['boxDr', [9555]], ['boxDR', [9556]], ['boxh', [9472]], ['boxH', [9552]], ['boxhd', [9516]], ['boxHd', [9572]], ['boxhD', [9573]], ['boxHD', [9574]], ['boxhu', [9524]], ['boxHu', [9575]], ['boxhU', [9576]], ['boxHU', [9577]], ['boxminus', [8863]], ['boxplus', [8862]], ['boxtimes', [8864]], ['boxul', [9496]], ['boxuL', [9563]], ['boxUl', [9564]], ['boxUL', [9565]], ['boxur', [9492]], ['boxuR', [9560]], ['boxUr', [9561]], ['boxUR', [9562]], ['boxv', [9474]], ['boxV', [9553]], ['boxvh', [9532]], ['boxvH', [9578]], ['boxVh', [9579]], ['boxVH', [9580]], ['boxvl', [9508]], ['boxvL', [9569]], ['boxVl', [9570]], ['boxVL', [9571]], ['boxvr', [9500]], ['boxvR', [9566]], ['boxVr', [9567]], ['boxVR', [9568]], ['bprime', [8245]], ['breve', [728]], ['Breve', [728]], ['brvbar', [166]], ['bscr', [119991]], ['Bscr', [8492]], ['bsemi', [8271]], ['bsim', [8765]], ['bsime', [8909]], ['bsolb', [10693]], ['bsol', [92]], ['bsolhsub', [10184]], ['bull', [8226]], ['bullet', [8226]], ['bump', [8782]], ['bumpE', [10926]], ['bumpe', [8783]], ['Bumpeq', [8782]
var DECODE_ONLY_ENTITIES = [['NewLine', [10]]];
var alphaIndex = {};
var charIndex = {};
createIndexes(alphaIndex, charIndex);
var Html5Entities = /** @class */ (function () {
function Html5Entities() {
}
Html5Entities.prototype.decode = function (str) {
if (!str || !str.length) {
return '';
}
return str.replace(/&(#?[\w\d]+);?/g, function (s, entity) {
var chr;
if (entity.charAt(0) === "#") {
var code = entity.charAt(1) === 'x' ?
parseInt(entity.substr(2).toLowerCase(), 16) :
parseInt(entity.substr(1));
if (!isNaN(code) || code >= -32768) {
if (code <= 65535) {
chr = String.fromCharCode(code);
}
else {
chr = surrogate_pairs_1.fromCodePoint(code);
}
}
}
else {
chr = alphaIndex[entity];
}
return chr || s;
});
};
Html5Entities.decode = function (str) {
return new Html5Entities().decode(str);
};
Html5Entities.prototype.encode = function (str) {
if (!str || !str.length) {
return '';
}
var strLength = str.length;
var result = '';
var i = 0;
while (i < strLength) {
var charInfo = charIndex[str.charCodeAt(i)];
if (charInfo) {
var alpha = charInfo[str.charCodeAt(i + 1)];
if (alpha) {
i++;
}
else {
alpha = charInfo[''];
}
if (alpha) {
result += "&" + alpha + ";";
i++;
continue;
}
}
result += str.charAt(i);
i++;
}
return result;
};
Html5Entities.encode = function (str) {
return new Html5Entities().encode(str);
};
Html5Entities.prototype.encodeNonUTF = function (str) {
if (!str || !str.length) {
return '';
}
var strLength = str.length;
var result = '';
var i = 0;
while (i < strLength) {
var c = str.charCodeAt(i);
var charInfo = charIndex[c];
if (charInfo) {
var alpha = charInfo[str.charCodeAt(i + 1)];
if (alpha) {
i++;
}
else {
alpha = charInfo[''];
}
if (alpha) {
result += "&" + alpha + ";";
i++;
continue;
}
}
if (c < 32 || c > 126) {
if (c >= surrogate_pairs_1.highSurrogateFrom && c <= surrogate_pairs_1.highSurrogateTo) {
result += '&#' + surrogate_pairs_1.getCodePoint(str, i) + ';';
i++;
}
else {
result += '&#' + c + ';';
}
}
else {
result += str.charAt(i);
}
i++;
}
return result;
};
Html5Entities.encodeNonUTF = function (str) {
return new Html5Entities().encodeNonUTF(str);
};
Html5Entities.prototype.encodeNonASCII = function (str) {
if (!str || !str.length) {
return '';
}
var strLength = str.length;
var result = '';
var i = 0;
while (i < strLength) {
var c = str.charCodeAt(i);
if (c <= 255) {
result += str[i++];
continue;
}
if (c >= surrogate_pairs_1.highSurrogateFrom && c <= surrogate_pairs_1.highSurrogateTo) {
result += '&#' + surrogate_pairs_1.getCodePoint(str, i) + ';';
i += 2;
}
else {
result += '&#' + c + ';';
i++;
}
}
return result;
};
Html5Entities.encodeNonASCII = function (str) {
return new Html5Entities().encodeNonASCII(str);
};
return Html5Entities;
}());
exports.Html5Entities = Html5Entities;
function createIndexes(alphaIndex, charIndex) {
var i = ENTITIES.length;
while (i--) {
var _a = ENTITIES[i], alpha = _a[0], _b = _a[1], chr = _b[0], chr2 = _b[1];
var addChar = (chr < 32 || chr > 126) || chr === 62 || chr === 60 || chr === 38 || chr === 34 || chr === 39;
var charInfo = void 0;
if (addChar) {
charInfo = charIndex[chr] = charIndex[chr] || {};
}
if (chr2) {
alphaIndex[alpha] = String.fromCharCode(chr) + String.fromCharCode(chr2);
addChar && (charInfo[chr2] = alpha);
}
else {
alphaIndex[alpha] = String.fromCharCode(chr);
addChar && (charInfo[''] = alpha);
}
}
i = DECODE_ONLY_ENTITIES.length;
while (i--) {
var _c = DECODE_ONLY_ENTITIES[i], alpha = _c[0], _d = _c[1], chr = _d[0], chr2 = _d[1];
alphaIndex[alpha] = String.fromCharCode(chr) + (chr2 ? String.fromCharCode(chr2) : '');
}
}