source: trip-planner-front/node_modules/entities/lib/decode.js@ 76712b2

Last change on this file since 76712b2 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.2 KB
Line 
1"use strict";
2var __importDefault = (this && this.__importDefault) || function (mod) {
3 return (mod && mod.__esModule) ? mod : { "default": mod };
4};
5Object.defineProperty(exports, "__esModule", { value: true });
6exports.decodeHTML = exports.decodeHTMLStrict = exports.decodeXML = void 0;
7var entities_json_1 = __importDefault(require("./maps/entities.json"));
8var legacy_json_1 = __importDefault(require("./maps/legacy.json"));
9var xml_json_1 = __importDefault(require("./maps/xml.json"));
10var decode_codepoint_1 = __importDefault(require("./decode_codepoint"));
11var strictEntityRe = /&(?:[a-zA-Z0-9]+|#[xX][\da-fA-F]+|#\d+);/g;
12exports.decodeXML = getStrictDecoder(xml_json_1.default);
13exports.decodeHTMLStrict = getStrictDecoder(entities_json_1.default);
14function getStrictDecoder(map) {
15 var replace = getReplacer(map);
16 return function (str) { return String(str).replace(strictEntityRe, replace); };
17}
18var sorter = function (a, b) { return (a < b ? 1 : -1); };
19exports.decodeHTML = (function () {
20 var legacy = Object.keys(legacy_json_1.default).sort(sorter);
21 var keys = Object.keys(entities_json_1.default).sort(sorter);
22 for (var i = 0, j = 0; i < keys.length; i++) {
23 if (legacy[j] === keys[i]) {
24 keys[i] += ";?";
25 j++;
26 }
27 else {
28 keys[i] += ";";
29 }
30 }
31 var re = new RegExp("&(?:" + keys.join("|") + "|#[xX][\\da-fA-F]+;?|#\\d+;?)", "g");
32 var replace = getReplacer(entities_json_1.default);
33 function replacer(str) {
34 if (str.substr(-1) !== ";")
35 str += ";";
36 return replace(str);
37 }
38 // TODO consider creating a merged map
39 return function (str) { return String(str).replace(re, replacer); };
40})();
41function getReplacer(map) {
42 return function replace(str) {
43 if (str.charAt(1) === "#") {
44 var secondChar = str.charAt(2);
45 if (secondChar === "X" || secondChar === "x") {
46 return decode_codepoint_1.default(parseInt(str.substr(3), 16));
47 }
48 return decode_codepoint_1.default(parseInt(str.substr(2), 10));
49 }
50 // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
51 return map[str.slice(1, -1)] || str;
52 };
53}
Note: See TracBrowser for help on using the repository browser.