draft: refactor project so it sits on top of a standalone app
This commit is contained in:
+11
@@ -0,0 +1,11 @@
|
||||
Copyright (c) Felix Böhm
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS,
|
||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
# entities [](https://npmjs.org/package/entities) [](https://npmjs.org/package/entities) [](http://travis-ci.org/fb55/entities) [](https://coveralls.io/r/fb55/entities)
|
||||
|
||||
En- & decoder for XML/HTML entities.
|
||||
|
||||
## How to…
|
||||
|
||||
### …install `entities`
|
||||
|
||||
npm i entities
|
||||
|
||||
### …use `entities`
|
||||
|
||||
```javascript
|
||||
const entities = require("entities");
|
||||
//encoding
|
||||
entities.escape("&"); // "&"
|
||||
entities.encodeXML("&"); // "&"
|
||||
entities.encodeHTML("&"); // "&"
|
||||
//decoding
|
||||
entities.decodeXML("asdf & ÿ ü '"); // "asdf & ÿ ü '"
|
||||
entities.decodeHTML("asdf & ÿ ü '"); // "asdf & ÿ ü '"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
License: BSD-2-Clause
|
||||
|
||||
[Get supported entities with the Tidelift Subscription](https://tidelift.com/subscription/pkg/npm-entities?utm_source=npm-entities&utm_medium=referral&utm_campaign=readme)
|
||||
|
||||
## Security contact information
|
||||
|
||||
To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security).
|
||||
Tidelift will coordinate the fix and disclosure.
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
export declare const decodeXML: (str: string) => string;
|
||||
export declare const decodeHTMLStrict: (str: string) => string;
|
||||
export interface MapType {
|
||||
[key: string]: string;
|
||||
}
|
||||
export declare const decodeHTML: (str: string) => string;
|
||||
//# sourceMappingURL=decode.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["../src/decode.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,SAAS,yBAA2B,CAAC;AAClD,eAAO,MAAM,gBAAgB,yBAA8B,CAAC;AAE5D,MAAM,WAAW,OAAO;IACpB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CACzB;AAeD,eAAO,MAAM,UAAU,yBA4BnB,CAAC"}
|
||||
+54
@@ -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)];
|
||||
};
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
export default function decodeCodePoint(codePoint: number): string;
|
||||
//# sourceMappingURL=decode_codepoint.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"decode_codepoint.d.ts","sourceRoot":"","sources":["../src/decode_codepoint.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,SAAS,EAAE,MAAM,UAoBxD"}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var decode_json_1 = __importDefault(require("./maps/decode.json"));
|
||||
// modified version of https://github.com/mathiasbynens/he/blob/master/src/he.js#L94-L119
|
||||
function decodeCodePoint(codePoint) {
|
||||
if ((codePoint >= 0xd800 && codePoint <= 0xdfff) || codePoint > 0x10ffff) {
|
||||
return "\uFFFD";
|
||||
}
|
||||
if (codePoint in decode_json_1.default) {
|
||||
// @ts-ignore
|
||||
codePoint = decode_json_1.default[codePoint];
|
||||
}
|
||||
var output = "";
|
||||
if (codePoint > 0xffff) {
|
||||
codePoint -= 0x10000;
|
||||
output += String.fromCharCode(((codePoint >>> 10) & 0x3ff) | 0xd800);
|
||||
codePoint = 0xdc00 | (codePoint & 0x3ff);
|
||||
}
|
||||
output += String.fromCharCode(codePoint);
|
||||
return output;
|
||||
}
|
||||
exports.default = decodeCodePoint;
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
export declare const encodeXML: (data: string) => string;
|
||||
export declare const encodeHTML: (data: string) => string;
|
||||
export declare function escape(data: string): string;
|
||||
//# sourceMappingURL=encode.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../src/encode.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,SAAS,0BAAsC,CAAC;AAO7D,eAAO,MAAM,UAAU,0BAAwC,CAAC;AA4DhE,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,UAKlC"}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var xml_json_1 = __importDefault(require("./maps/xml.json"));
|
||||
var inverseXML = getInverseObj(xml_json_1.default);
|
||||
var xmlReplacer = getInverseReplacer(inverseXML);
|
||||
exports.encodeXML = getInverse(inverseXML, xmlReplacer);
|
||||
var entities_json_1 = __importDefault(require("./maps/entities.json"));
|
||||
var inverseHTML = getInverseObj(entities_json_1.default);
|
||||
var htmlReplacer = getInverseReplacer(inverseHTML);
|
||||
exports.encodeHTML = getInverse(inverseHTML, htmlReplacer);
|
||||
function getInverseObj(obj) {
|
||||
return Object.keys(obj)
|
||||
.sort()
|
||||
.reduce(function (inverse, name) {
|
||||
inverse[obj[name]] = "&" + name + ";";
|
||||
return inverse;
|
||||
}, {});
|
||||
}
|
||||
function getInverseReplacer(inverse) {
|
||||
var single = [];
|
||||
var multiple = [];
|
||||
Object.keys(inverse).forEach(function (k) {
|
||||
return k.length === 1
|
||||
? // Add value to single array
|
||||
single.push("\\" + k)
|
||||
: // Add value to multiple array
|
||||
multiple.push(k);
|
||||
});
|
||||
//TODO add ranges
|
||||
multiple.unshift("[" + single.join("") + "]");
|
||||
return new RegExp(multiple.join("|"), "g");
|
||||
}
|
||||
var reNonASCII = /[^\0-\x7F]/g;
|
||||
var reAstralSymbols = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
|
||||
function singleCharReplacer(c) {
|
||||
return "&#x" + c
|
||||
.charCodeAt(0)
|
||||
.toString(16)
|
||||
.toUpperCase() + ";";
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
|
||||
function astralReplacer(c, _) {
|
||||
// http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
|
||||
var high = c.charCodeAt(0);
|
||||
var low = c.charCodeAt(1);
|
||||
var codePoint = (high - 0xd800) * 0x400 + low - 0xdc00 + 0x10000;
|
||||
return "&#x" + codePoint.toString(16).toUpperCase() + ";";
|
||||
}
|
||||
function getInverse(inverse, re) {
|
||||
return function (data) {
|
||||
return data
|
||||
.replace(re, function (name) { return inverse[name]; })
|
||||
.replace(reAstralSymbols, astralReplacer)
|
||||
.replace(reNonASCII, singleCharReplacer);
|
||||
};
|
||||
}
|
||||
var reXmlChars = getInverseReplacer(inverseXML);
|
||||
function escape(data) {
|
||||
return data
|
||||
.replace(reXmlChars, singleCharReplacer)
|
||||
.replace(reAstralSymbols, astralReplacer)
|
||||
.replace(reNonASCII, singleCharReplacer);
|
||||
}
|
||||
exports.escape = escape;
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
export declare function decode(data: string, level?: number): string;
|
||||
export declare function decodeStrict(data: string, level?: number): string;
|
||||
export declare function encode(data: string, level?: number): string;
|
||||
export { encodeXML, encodeHTML, escape, encodeHTML as encodeHTML4, encodeHTML as encodeHTML5 } from "./encode";
|
||||
export { decodeXML, decodeHTML, decodeHTMLStrict, decodeHTML as decodeHTML4, decodeHTML as decodeHTML5, decodeHTMLStrict as decodeHTML4Strict, decodeHTMLStrict as decodeHTML5Strict, decodeXML as decodeXMLStrict } from "./decode";
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAE3D;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAEjE;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAE3D;AAED,OAAO,EACH,SAAS,EACT,UAAU,EACV,MAAM,EAEN,UAAU,IAAI,WAAW,EACzB,UAAU,IAAI,WAAW,EAC5B,MAAM,UAAU,CAAC;AAElB,OAAO,EACH,SAAS,EACT,UAAU,EACV,gBAAgB,EAEhB,UAAU,IAAI,WAAW,EACzB,UAAU,IAAI,WAAW,EACzB,gBAAgB,IAAI,iBAAiB,EACrC,gBAAgB,IAAI,iBAAiB,EACrC,SAAS,IAAI,eAAe,EAC/B,MAAM,UAAU,CAAC"}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var decode_1 = require("./decode");
|
||||
var encode_1 = require("./encode");
|
||||
function decode(data, level) {
|
||||
return (!level || level <= 0 ? decode_1.decodeXML : decode_1.decodeHTML)(data);
|
||||
}
|
||||
exports.decode = decode;
|
||||
function decodeStrict(data, level) {
|
||||
return (!level || level <= 0 ? decode_1.decodeXML : decode_1.decodeHTMLStrict)(data);
|
||||
}
|
||||
exports.decodeStrict = decodeStrict;
|
||||
function encode(data, level) {
|
||||
return (!level || level <= 0 ? encode_1.encodeXML : encode_1.encodeHTML)(data);
|
||||
}
|
||||
exports.encode = encode;
|
||||
var encode_2 = require("./encode");
|
||||
exports.encodeXML = encode_2.encodeXML;
|
||||
exports.encodeHTML = encode_2.encodeHTML;
|
||||
exports.escape = encode_2.escape;
|
||||
// Legacy aliases
|
||||
exports.encodeHTML4 = encode_2.encodeHTML;
|
||||
exports.encodeHTML5 = encode_2.encodeHTML;
|
||||
var decode_2 = require("./decode");
|
||||
exports.decodeXML = decode_2.decodeXML;
|
||||
exports.decodeHTML = decode_2.decodeHTML;
|
||||
exports.decodeHTMLStrict = decode_2.decodeHTMLStrict;
|
||||
// Legacy aliases
|
||||
exports.decodeHTML4 = decode_2.decodeHTML;
|
||||
exports.decodeHTML5 = decode_2.decodeHTML;
|
||||
exports.decodeHTML4Strict = decode_2.decodeHTMLStrict;
|
||||
exports.decodeHTML5Strict = decode_2.decodeHTMLStrict;
|
||||
exports.decodeXMLStrict = decode_2.decodeXML;
|
||||
+1
@@ -0,0 +1 @@
|
||||
{ "0": 65533, "128": 8364, "130": 8218, "131": 402, "132": 8222, "133": 8230, "134": 8224, "135": 8225, "136": 710, "137": 8240, "138": 352, "139": 8249, "140": 338, "142": 381, "145": 8216, "146": 8217, "147": 8220, "148": 8221, "149": 8226, "150": 8211, "151": 8212, "152": 732, "153": 8482, "154": 353, "155": 8250, "156": 339, "158": 382, "159": 376 }
|
||||
+1
File diff suppressed because one or more lines are too long
+1
@@ -0,0 +1 @@
|
||||
{ "Aacute": "\u00C1", "aacute": "\u00E1", "Acirc": "\u00C2", "acirc": "\u00E2", "acute": "\u00B4", "AElig": "\u00C6", "aelig": "\u00E6", "Agrave": "\u00C0", "agrave": "\u00E0", "amp": "&", "AMP": "&", "Aring": "\u00C5", "aring": "\u00E5", "Atilde": "\u00C3", "atilde": "\u00E3", "Auml": "\u00C4", "auml": "\u00E4", "brvbar": "\u00A6", "Ccedil": "\u00C7", "ccedil": "\u00E7", "cedil": "\u00B8", "cent": "\u00A2", "copy": "\u00A9", "COPY": "\u00A9", "curren": "\u00A4", "deg": "\u00B0", "divide": "\u00F7", "Eacute": "\u00C9", "eacute": "\u00E9", "Ecirc": "\u00CA", "ecirc": "\u00EA", "Egrave": "\u00C8", "egrave": "\u00E8", "ETH": "\u00D0", "eth": "\u00F0", "Euml": "\u00CB", "euml": "\u00EB", "frac12": "\u00BD", "frac14": "\u00BC", "frac34": "\u00BE", "gt": ">", "GT": ">", "Iacute": "\u00CD", "iacute": "\u00ED", "Icirc": "\u00CE", "icirc": "\u00EE", "iexcl": "\u00A1", "Igrave": "\u00CC", "igrave": "\u00EC", "iquest": "\u00BF", "Iuml": "\u00CF", "iuml": "\u00EF", "laquo": "\u00AB", "lt": "<", "LT": "<", "macr": "\u00AF", "micro": "\u00B5", "middot": "\u00B7", "nbsp": "\u00A0", "not": "\u00AC", "Ntilde": "\u00D1", "ntilde": "\u00F1", "Oacute": "\u00D3", "oacute": "\u00F3", "Ocirc": "\u00D4", "ocirc": "\u00F4", "Ograve": "\u00D2", "ograve": "\u00F2", "ordf": "\u00AA", "ordm": "\u00BA", "Oslash": "\u00D8", "oslash": "\u00F8", "Otilde": "\u00D5", "otilde": "\u00F5", "Ouml": "\u00D6", "ouml": "\u00F6", "para": "\u00B6", "plusmn": "\u00B1", "pound": "\u00A3", "quot": "\"", "QUOT": "\"", "raquo": "\u00BB", "reg": "\u00AE", "REG": "\u00AE", "sect": "\u00A7", "shy": "\u00AD", "sup1": "\u00B9", "sup2": "\u00B2", "sup3": "\u00B3", "szlig": "\u00DF", "THORN": "\u00DE", "thorn": "\u00FE", "times": "\u00D7", "Uacute": "\u00DA", "uacute": "\u00FA", "Ucirc": "\u00DB", "ucirc": "\u00FB", "Ugrave": "\u00D9", "ugrave": "\u00F9", "uml": "\u00A8", "Uuml": "\u00DC", "uuml": "\u00FC", "Yacute": "\u00DD", "yacute": "\u00FD", "yen": "\u00A5", "yuml": "\u00FF" }
|
||||
+1
@@ -0,0 +1 @@
|
||||
{ "amp": "&", "apos": "'", "gt": ">", "lt": "<", "quot": "\"" }
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
export declare const decodeXML: (str: string) => string;
|
||||
export declare const decodeHTMLStrict: (str: string) => string;
|
||||
export interface MapType {
|
||||
[key: string]: string;
|
||||
}
|
||||
export declare const decodeHTML: (str: string) => string;
|
||||
//# sourceMappingURL=decode.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["../../src/decode.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,SAAS,yBAA2B,CAAC;AAClD,eAAO,MAAM,gBAAgB,yBAA8B,CAAC;AAE5D,MAAM,WAAW,OAAO;IACpB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CACzB;AAeD,eAAO,MAAM,UAAU,yBA4BnB,CAAC"}
|
||||
+54
@@ -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)];
|
||||
};
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
export default function decodeCodePoint(codePoint: number): string;
|
||||
//# sourceMappingURL=decode_codepoint.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"decode_codepoint.d.ts","sourceRoot":"","sources":["../../src/decode_codepoint.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,SAAS,EAAE,MAAM,UAoBxD"}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var decode_json_1 = __importDefault(require("../maps/decode.json"));
|
||||
// modified version of https://github.com/mathiasbynens/he/blob/master/src/he.js#L94-L119
|
||||
function decodeCodePoint(codePoint) {
|
||||
if ((codePoint >= 0xd800 && codePoint <= 0xdfff) || codePoint > 0x10ffff) {
|
||||
return "\uFFFD";
|
||||
}
|
||||
if (codePoint in decode_json_1.default) {
|
||||
// @ts-ignore
|
||||
codePoint = decode_json_1.default[codePoint];
|
||||
}
|
||||
var output = "";
|
||||
if (codePoint > 0xffff) {
|
||||
codePoint -= 0x10000;
|
||||
output += String.fromCharCode(((codePoint >>> 10) & 0x3ff) | 0xd800);
|
||||
codePoint = 0xdc00 | (codePoint & 0x3ff);
|
||||
}
|
||||
output += String.fromCharCode(codePoint);
|
||||
return output;
|
||||
}
|
||||
exports.default = decodeCodePoint;
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
export declare const encodeXML: (data: string) => string;
|
||||
export declare const encodeHTML: (data: string) => string;
|
||||
export declare function escape(data: string): string;
|
||||
//# sourceMappingURL=encode.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../../src/encode.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,SAAS,0BAAsC,CAAC;AAO7D,eAAO,MAAM,UAAU,0BAAwC,CAAC;AA4DhE,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,UAKlC"}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var xml_json_1 = __importDefault(require("../maps/xml.json"));
|
||||
var inverseXML = getInverseObj(xml_json_1.default);
|
||||
var xmlReplacer = getInverseReplacer(inverseXML);
|
||||
exports.encodeXML = getInverse(inverseXML, xmlReplacer);
|
||||
var entities_json_1 = __importDefault(require("../maps/entities.json"));
|
||||
var inverseHTML = getInverseObj(entities_json_1.default);
|
||||
var htmlReplacer = getInverseReplacer(inverseHTML);
|
||||
exports.encodeHTML = getInverse(inverseHTML, htmlReplacer);
|
||||
function getInverseObj(obj) {
|
||||
return Object.keys(obj)
|
||||
.sort()
|
||||
.reduce(function (inverse, name) {
|
||||
inverse[obj[name]] = "&" + name + ";";
|
||||
return inverse;
|
||||
}, {});
|
||||
}
|
||||
function getInverseReplacer(inverse) {
|
||||
var single = [];
|
||||
var multiple = [];
|
||||
Object.keys(inverse).forEach(function (k) {
|
||||
return k.length === 1
|
||||
? // Add value to single array
|
||||
single.push("\\" + k)
|
||||
: // Add value to multiple array
|
||||
multiple.push(k);
|
||||
});
|
||||
//TODO add ranges
|
||||
multiple.unshift("[" + single.join("") + "]");
|
||||
return new RegExp(multiple.join("|"), "g");
|
||||
}
|
||||
var reNonASCII = /[^\0-\x7F]/g;
|
||||
var reAstralSymbols = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
|
||||
function singleCharReplacer(c) {
|
||||
return "&#x" + c
|
||||
.charCodeAt(0)
|
||||
.toString(16)
|
||||
.toUpperCase() + ";";
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
|
||||
function astralReplacer(c, _) {
|
||||
// http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
|
||||
var high = c.charCodeAt(0);
|
||||
var low = c.charCodeAt(1);
|
||||
var codePoint = (high - 0xd800) * 0x400 + low - 0xdc00 + 0x10000;
|
||||
return "&#x" + codePoint.toString(16).toUpperCase() + ";";
|
||||
}
|
||||
function getInverse(inverse, re) {
|
||||
return function (data) {
|
||||
return data
|
||||
.replace(re, function (name) { return inverse[name]; })
|
||||
.replace(reAstralSymbols, astralReplacer)
|
||||
.replace(reNonASCII, singleCharReplacer);
|
||||
};
|
||||
}
|
||||
var reXmlChars = getInverseReplacer(inverseXML);
|
||||
function escape(data) {
|
||||
return data
|
||||
.replace(reXmlChars, singleCharReplacer)
|
||||
.replace(reAstralSymbols, astralReplacer)
|
||||
.replace(reNonASCII, singleCharReplacer);
|
||||
}
|
||||
exports.escape = escape;
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
export declare function decode(data: string, level?: number): string;
|
||||
export declare function decodeStrict(data: string, level?: number): string;
|
||||
export declare function encode(data: string, level?: number): string;
|
||||
export { encodeXML, encodeHTML, escape, encodeHTML as encodeHTML4, encodeHTML as encodeHTML5 } from "./encode";
|
||||
export { decodeXML, decodeHTML, decodeHTMLStrict, decodeHTML as decodeHTML4, decodeHTML as decodeHTML5, decodeHTMLStrict as decodeHTML4Strict, decodeHTMLStrict as decodeHTML5Strict, decodeXML as decodeXMLStrict } from "./decode";
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAIA,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAE3D;AAGD,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAEjE;AAGD,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAE3D;AAED,OAAO,EACH,SAAS,EACT,UAAU,EACV,MAAM,EAEN,UAAU,IAAI,WAAW,EACzB,UAAU,IAAI,WAAW,EAC5B,MAAM,UAAU,CAAC;AAElB,OAAO,EACH,SAAS,EACT,UAAU,EACV,gBAAgB,EAEhB,UAAU,IAAI,WAAW,EACzB,UAAU,IAAI,WAAW,EACzB,gBAAgB,IAAI,iBAAiB,EACrC,gBAAgB,IAAI,iBAAiB,EACrC,SAAS,IAAI,eAAe,EAC/B,MAAM,UAAU,CAAC"}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var decode_1 = require("./decode");
|
||||
var encode_1 = require("./encode");
|
||||
// Note: Deprecated
|
||||
function decode(data, level) {
|
||||
return (!level || level <= 0 ? decode_1.decodeXML : decode_1.decodeHTML)(data);
|
||||
}
|
||||
exports.decode = decode;
|
||||
// Note: Deprecated
|
||||
function decodeStrict(data, level) {
|
||||
return (!level || level <= 0 ? decode_1.decodeXML : decode_1.decodeHTMLStrict)(data);
|
||||
}
|
||||
exports.decodeStrict = decodeStrict;
|
||||
// Note: Deprecated
|
||||
function encode(data, level) {
|
||||
return (!level || level <= 0 ? encode_1.encodeXML : encode_1.encodeHTML)(data);
|
||||
}
|
||||
exports.encode = encode;
|
||||
var encode_2 = require("./encode");
|
||||
exports.encodeXML = encode_2.encodeXML;
|
||||
exports.encodeHTML = encode_2.encodeHTML;
|
||||
exports.escape = encode_2.escape;
|
||||
// Legacy aliases
|
||||
exports.encodeHTML4 = encode_2.encodeHTML;
|
||||
exports.encodeHTML5 = encode_2.encodeHTML;
|
||||
var decode_2 = require("./decode");
|
||||
exports.decodeXML = decode_2.decodeXML;
|
||||
exports.decodeHTML = decode_2.decodeHTML;
|
||||
exports.decodeHTMLStrict = decode_2.decodeHTMLStrict;
|
||||
// Legacy aliases
|
||||
exports.decodeHTML4 = decode_2.decodeHTML;
|
||||
exports.decodeHTML5 = decode_2.decodeHTML;
|
||||
exports.decodeHTML4Strict = decode_2.decodeHTMLStrict;
|
||||
exports.decodeHTML5Strict = decode_2.decodeHTMLStrict;
|
||||
exports.decodeXMLStrict = decode_2.decodeXML;
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
{
|
||||
"_from": "entities@^2.0.0",
|
||||
"_id": "entities@2.0.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-D9f7V0JSRwIxlRI2mjMqufDrRDnx8p+eEOz7aUM9SuvF8gsBzra0/6tbjl1m8eQHrZlYj6PxqE00hZ1SAIKPLw==",
|
||||
"_location": "/entities",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "entities@^2.0.0",
|
||||
"name": "entities",
|
||||
"escapedName": "entities",
|
||||
"rawSpec": "^2.0.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^2.0.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/dom-serializer"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/entities/-/entities-2.0.0.tgz",
|
||||
"_shasum": "68d6084cab1b079767540d80e56a39b423e4abf4",
|
||||
"_spec": "entities@^2.0.0",
|
||||
"_where": "O:\\zero\\zero.Web\\node_modules\\dom-serializer",
|
||||
"author": {
|
||||
"name": "Felix Boehm",
|
||||
"email": "me@feedic.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/fb55/entities/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"deprecated": false,
|
||||
"description": "Encode & decode XML/HTML entities with ease",
|
||||
"devDependencies": {
|
||||
"@types/mocha": "^5.2.7",
|
||||
"@types/node": "^12.6.8",
|
||||
"@typescript-eslint/eslint-plugin": "^1.12.0",
|
||||
"@typescript-eslint/parser": "^1.12.0",
|
||||
"coveralls": "*",
|
||||
"eslint": "^6.0.1",
|
||||
"eslint-config-prettier": "^6.0.0",
|
||||
"mocha": "^6.1.4",
|
||||
"mocha-lcov-reporter": "*",
|
||||
"nyc": "^14.1.1",
|
||||
"prettier": "^1.18.2",
|
||||
"source-map-support": "^0.5.12",
|
||||
"ts-node": "^8.3.0",
|
||||
"typescript": "^3.5.3"
|
||||
},
|
||||
"directories": {
|
||||
"test": "test"
|
||||
},
|
||||
"files": [
|
||||
"lib/**/*"
|
||||
],
|
||||
"homepage": "https://github.com/fb55/entities#readme",
|
||||
"keywords": [
|
||||
"html",
|
||||
"xml",
|
||||
"entity",
|
||||
"decoding",
|
||||
"encoding"
|
||||
],
|
||||
"license": "BSD-2-Clause",
|
||||
"main": "lib/index.js",
|
||||
"name": "entities",
|
||||
"nyc": {
|
||||
"extension": [
|
||||
".ts",
|
||||
".tsx"
|
||||
],
|
||||
"exclude": [
|
||||
"**/*.d.ts"
|
||||
],
|
||||
"reporter": [
|
||||
"html",
|
||||
"text"
|
||||
],
|
||||
"all": true
|
||||
},
|
||||
"prettier": {
|
||||
"tabWidth": 4
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/fb55/entities.git"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"coverage": "nyc report --reporter=text-lcov | coveralls",
|
||||
"eslint": "eslint '**/*.ts'",
|
||||
"format": "prettier --write **/*.{ts,md}",
|
||||
"prepare": "npm run build",
|
||||
"test": "nyc mocha && npm run eslint"
|
||||
},
|
||||
"version": "2.0.0"
|
||||
}
|
||||
Reference in New Issue
Block a user