summaryrefslogtreecommitdiff
path: root/bin/wiki/ImportarDesdeURL/node_modules/entities/lib/src/decode.js
diff options
context:
space:
mode:
Diffstat (limited to 'bin/wiki/ImportarDesdeURL/node_modules/entities/lib/src/decode.js')
-rw-r--r--bin/wiki/ImportarDesdeURL/node_modules/entities/lib/src/decode.js54
1 files changed, 54 insertions, 0 deletions
diff --git a/bin/wiki/ImportarDesdeURL/node_modules/entities/lib/src/decode.js b/bin/wiki/ImportarDesdeURL/node_modules/entities/lib/src/decode.js
new file mode 100644
index 00000000..d7f243a6
--- /dev/null
+++ b/bin/wiki/ImportarDesdeURL/node_modules/entities/lib/src/decode.js
@@ -0,0 +1,54 @@
+"use strict";
+var __importDefault = (this && this.__importDefault) || function (mod) {
+ return (mod && mod.__esModule) ? mod : { "default": mod };
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+var entities_json_1 = __importDefault(require("../maps/entities.json"));
+var legacy_json_1 = __importDefault(require("../maps/legacy.json"));
+var xml_json_1 = __importDefault(require("../maps/xml.json"));
+var decode_codepoint_1 = __importDefault(require("./decode_codepoint"));
+exports.decodeXML = getStrictDecoder(xml_json_1.default);
+exports.decodeHTMLStrict = getStrictDecoder(entities_json_1.default);
+function getStrictDecoder(map) {
+ var keys = Object.keys(map).join("|");
+ var replace = getReplacer(map);
+ keys += "|#[xX][\\da-fA-F]+|#\\d+";
+ var re = new RegExp("&(?:" + keys + ");", "g");
+ return function (str) { return String(str).replace(re, replace); };
+}
+var sorter = function (a, b) { return (a < b ? 1 : -1); };
+exports.decodeHTML = (function () {
+ var legacy = Object.keys(legacy_json_1.default).sort(sorter);
+ var keys = Object.keys(entities_json_1.default).sort(sorter);
+ for (var i = 0, j = 0; i < keys.length; i++) {
+ if (legacy[j] === keys[i]) {
+ keys[i] += ";?";
+ j++;
+ }
+ else {
+ keys[i] += ";";
+ }
+ }
+ var re = new RegExp("&(?:" + keys.join("|") + "|#[xX][\\da-fA-F]+;?|#\\d+;?)", "g");
+ var replace = getReplacer(entities_json_1.default);
+ function replacer(str) {
+ if (str.substr(-1) !== ";")
+ str += ";";
+ return replace(str);
+ }
+ //TODO consider creating a merged map
+ return function (str) {
+ return String(str).replace(re, replacer);
+ };
+})();
+function getReplacer(map) {
+ return function replace(str) {
+ if (str.charAt(1) === "#") {
+ if (str.charAt(2) === "X" || str.charAt(2) === "x") {
+ return decode_codepoint_1.default(parseInt(str.substr(3), 16));
+ }
+ return decode_codepoint_1.default(parseInt(str.substr(2), 10));
+ }
+ return map[str.slice(1, -1)];
+ };
+}