Comparing version 4.1.1 to 4.2.0
"use strict"; | ||
// Adapted from https://github.com/mathiasbynens/he/blob/36afe179392226cf1b6ccdb16ebbb7a5a844d93a/src/he.js#L106-L134 | ||
var _a; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -37,13 +38,12 @@ exports.replaceCodePoint = void 0; | ||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, node/no-unsupported-features/es-builtins | ||
String.fromCodePoint || | ||
function (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; | ||
}; | ||
(_a = String.fromCodePoint) !== null && _a !== void 0 ? _a : function (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; | ||
}; | ||
function replaceCodePoint(codePoint) { | ||
@@ -50,0 +50,0 @@ var _a; |
import htmlDecodeTree from "./generated/decode-data-html.js"; | ||
import xmlDecodeTree from "./generated/decode-data-xml.js"; | ||
import decodeCodePoint from "./decode_codepoint.js"; | ||
export { htmlDecodeTree, xmlDecodeTree, decodeCodePoint }; | ||
import { default as decodeCodePoint, replaceCodePoint } from "./decode_codepoint.js"; | ||
export { htmlDecodeTree, xmlDecodeTree, decodeCodePoint, replaceCodePoint }; | ||
export declare enum BinTrieFlags { | ||
@@ -6,0 +6,0 @@ VALUE_LENGTH = 49152, |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -6,3 +29,3 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.decodeXML = exports.decodeHTMLStrict = exports.decodeHTML = exports.determineBranch = exports.BinTrieFlags = exports.decodeCodePoint = exports.xmlDecodeTree = exports.htmlDecodeTree = void 0; | ||
exports.decodeXML = exports.decodeHTMLStrict = exports.decodeHTML = exports.determineBranch = exports.BinTrieFlags = exports.replaceCodePoint = exports.decodeCodePoint = exports.xmlDecodeTree = exports.htmlDecodeTree = void 0; | ||
var decode_data_html_js_1 = __importDefault(require("./generated/decode-data-html.js")); | ||
@@ -12,4 +35,5 @@ exports.htmlDecodeTree = decode_data_html_js_1.default; | ||
exports.xmlDecodeTree = decode_data_xml_js_1.default; | ||
var decode_codepoint_js_1 = __importDefault(require("./decode_codepoint.js")); | ||
exports.decodeCodePoint = decode_codepoint_js_1.default; | ||
var decode_codepoint_js_1 = __importStar(require("./decode_codepoint.js")); | ||
Object.defineProperty(exports, "decodeCodePoint", { enumerable: true, get: function () { return decode_codepoint_js_1.default; } }); | ||
Object.defineProperty(exports, "replaceCodePoint", { enumerable: true, get: function () { return decode_codepoint_js_1.replaceCodePoint; } }); | ||
var BinTrieFlags; | ||
@@ -16,0 +40,0 @@ (function (BinTrieFlags) { |
@@ -8,3 +8,3 @@ "use strict"; | ||
var encode_html_js_1 = __importDefault(require("./generated/encode-html.js")); | ||
function isHighSurrugate(c) { | ||
function isHighSurrogate(c) { | ||
return (c & 64512 /* Mask */) === 55296 /* High */; | ||
@@ -19,3 +19,3 @@ } | ||
function (c, index) { | ||
return isHighSurrugate(c.charCodeAt(index)) | ||
return isHighSurrogate(c.charCodeAt(index)) | ||
? (c.charCodeAt(index) - 55296 /* High */) * 0x400 + | ||
@@ -28,3 +28,2 @@ c.charCodeAt(index + 1) - | ||
function encodeHTMLTrieRe(regExp, str) { | ||
var _a; | ||
var ret = ""; | ||
@@ -35,29 +34,32 @@ var lastIdx = 0; | ||
var i = match.index; | ||
ret += str.substring(lastIdx, i); | ||
var char = str.charCodeAt(i); | ||
var next = encode_html_js_1.default.get(char); | ||
if (next != null) { | ||
if (typeof next !== "string") { | ||
// We are in a branch. Try to match the next char. | ||
if (i + 1 < str.length) { | ||
var value = typeof next.n === "number" | ||
? next.n === str.charCodeAt(i + 1) | ||
? next.o | ||
: null | ||
: next.n.get(str.charCodeAt(i + 1)); | ||
if (value) { | ||
ret += str.substring(lastIdx, i) + value; | ||
lastIdx = regExp.lastIndex += 1; | ||
continue; | ||
} | ||
if (typeof next === "object") { | ||
// We are in a branch. Try to match the next char. | ||
if (i + 1 < str.length) { | ||
var nextChar = str.charCodeAt(i + 1); | ||
var value = typeof next.n === "number" | ||
? next.n === nextChar | ||
? next.o | ||
: undefined | ||
: next.n.get(nextChar); | ||
if (value !== undefined) { | ||
ret += value; | ||
lastIdx = regExp.lastIndex += 1; | ||
continue; | ||
} | ||
// If we have a character without a value, use a numeric entitiy. | ||
next = (_a = next.v) !== null && _a !== void 0 ? _a : "&#x".concat(char.toString(16), ";"); | ||
} | ||
ret += str.substring(lastIdx, i) + next; | ||
next = next.v; | ||
} | ||
// We might have a tree node without a value; skip and use a numeric entitiy. | ||
if (next !== undefined) { | ||
ret += next; | ||
lastIdx = i + 1; | ||
} | ||
else { | ||
ret += "".concat(str.substring(lastIdx, i), "&#x").concat((0, exports.getCodePoint)(str, i).toString(16), ";"); | ||
var cp = (0, exports.getCodePoint)(str, i); | ||
ret += "&#x".concat(cp.toString(16), ";"); | ||
// Increase by 1 if we have a surrogate pair | ||
lastIdx = regExp.lastIndex += Number(isHighSurrugate(char)); | ||
lastIdx = regExp.lastIndex += Number(cp !== char); | ||
} | ||
@@ -64,0 +66,0 @@ } |
@@ -29,3 +29,3 @@ "use strict"; | ||
var next = xmlCodeMap.get(char); | ||
if (next) { | ||
if (next !== undefined) { | ||
ret += str.substring(lastIdx, i) + next; | ||
@@ -32,0 +32,0 @@ lastIdx = i + 1; |
// Adapted from https://github.com/mathiasbynens/he/blob/36afe179392226cf1b6ccdb16ebbb7a5a844d93a/src/he.js#L106-L134 | ||
var _a; | ||
const decodeMap = new Map([ | ||
@@ -34,13 +35,12 @@ [0, 65533], | ||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, node/no-unsupported-features/es-builtins | ||
String.fromCodePoint || | ||
function (codePoint) { | ||
let output = ""; | ||
if (codePoint > 0xffff) { | ||
codePoint -= 0x10000; | ||
output += String.fromCharCode(((codePoint >>> 10) & 0x3ff) | 0xd800); | ||
codePoint = 0xdc00 | (codePoint & 0x3ff); | ||
} | ||
output += String.fromCharCode(codePoint); | ||
return output; | ||
}; | ||
(_a = String.fromCodePoint) !== null && _a !== void 0 ? _a : function (codePoint) { | ||
let output = ""; | ||
if (codePoint > 0xffff) { | ||
codePoint -= 0x10000; | ||
output += String.fromCharCode(((codePoint >>> 10) & 0x3ff) | 0xd800); | ||
codePoint = 0xdc00 | (codePoint & 0x3ff); | ||
} | ||
output += String.fromCharCode(codePoint); | ||
return output; | ||
}; | ||
export function replaceCodePoint(codePoint) { | ||
@@ -47,0 +47,0 @@ var _a; |
import htmlDecodeTree from "./generated/decode-data-html.js"; | ||
import xmlDecodeTree from "./generated/decode-data-xml.js"; | ||
import decodeCodePoint from "./decode_codepoint.js"; | ||
export { htmlDecodeTree, xmlDecodeTree, decodeCodePoint }; | ||
import { default as decodeCodePoint, replaceCodePoint } from "./decode_codepoint.js"; | ||
export { htmlDecodeTree, xmlDecodeTree, decodeCodePoint, replaceCodePoint }; | ||
export declare enum BinTrieFlags { | ||
@@ -6,0 +6,0 @@ VALUE_LENGTH = 49152, |
import htmlDecodeTree from "./generated/decode-data-html.js"; | ||
import xmlDecodeTree from "./generated/decode-data-xml.js"; | ||
import decodeCodePoint from "./decode_codepoint.js"; | ||
import { default as decodeCodePoint, replaceCodePoint, } from "./decode_codepoint.js"; | ||
// Re-export for use by eg. htmlparser2 | ||
export { htmlDecodeTree, xmlDecodeTree, decodeCodePoint }; | ||
export { htmlDecodeTree, xmlDecodeTree, decodeCodePoint, replaceCodePoint }; | ||
export var BinTrieFlags; | ||
@@ -7,0 +7,0 @@ (function (BinTrieFlags) { |
import htmlTrie from "./generated/encode-html.js"; | ||
function isHighSurrugate(c) { | ||
function isHighSurrogate(c) { | ||
return (c & 64512 /* Mask */) === 55296 /* High */; | ||
@@ -11,3 +11,3 @@ } | ||
: // http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae | ||
(c, index) => isHighSurrugate(c.charCodeAt(index)) | ||
(c, index) => isHighSurrogate(c.charCodeAt(index)) | ||
? (c.charCodeAt(index) - 55296 /* High */) * 0x400 + | ||
@@ -19,3 +19,2 @@ c.charCodeAt(index + 1) - | ||
export function encodeHTMLTrieRe(regExp, str) { | ||
var _a; | ||
let ret = ""; | ||
@@ -26,29 +25,32 @@ let lastIdx = 0; | ||
const i = match.index; | ||
ret += str.substring(lastIdx, i); | ||
const char = str.charCodeAt(i); | ||
let next = htmlTrie.get(char); | ||
if (next != null) { | ||
if (typeof next !== "string") { | ||
// We are in a branch. Try to match the next char. | ||
if (i + 1 < str.length) { | ||
const value = typeof next.n === "number" | ||
? next.n === str.charCodeAt(i + 1) | ||
? next.o | ||
: null | ||
: next.n.get(str.charCodeAt(i + 1)); | ||
if (value) { | ||
ret += str.substring(lastIdx, i) + value; | ||
lastIdx = regExp.lastIndex += 1; | ||
continue; | ||
} | ||
if (typeof next === "object") { | ||
// We are in a branch. Try to match the next char. | ||
if (i + 1 < str.length) { | ||
const nextChar = str.charCodeAt(i + 1); | ||
const value = typeof next.n === "number" | ||
? next.n === nextChar | ||
? next.o | ||
: undefined | ||
: next.n.get(nextChar); | ||
if (value !== undefined) { | ||
ret += value; | ||
lastIdx = regExp.lastIndex += 1; | ||
continue; | ||
} | ||
// If we have a character without a value, use a numeric entitiy. | ||
next = (_a = next.v) !== null && _a !== void 0 ? _a : `&#x${char.toString(16)};`; | ||
} | ||
ret += str.substring(lastIdx, i) + next; | ||
next = next.v; | ||
} | ||
// We might have a tree node without a value; skip and use a numeric entitiy. | ||
if (next !== undefined) { | ||
ret += next; | ||
lastIdx = i + 1; | ||
} | ||
else { | ||
ret += `${str.substring(lastIdx, i)}&#x${getCodePoint(str, i).toString(16)};`; | ||
const cp = getCodePoint(str, i); | ||
ret += `&#x${cp.toString(16)};`; | ||
// Increase by 1 if we have a surrogate pair | ||
lastIdx = regExp.lastIndex += Number(isHighSurrugate(char)); | ||
lastIdx = regExp.lastIndex += Number(cp !== char); | ||
} | ||
@@ -55,0 +57,0 @@ } |
@@ -26,3 +26,3 @@ import { encodeHTMLTrieRe, getCodePoint } from "./encode-trie.js"; | ||
const next = xmlCodeMap.get(char); | ||
if (next) { | ||
if (next !== undefined) { | ||
ret += str.substring(lastIdx, i) + next; | ||
@@ -29,0 +29,0 @@ lastIdx = i + 1; |
{ | ||
"name": "entities", | ||
"version": "4.1.1", | ||
"version": "4.2.0", | ||
"description": "Encode & decode XML and HTML entities with ease & speed", | ||
@@ -41,4 +41,4 @@ "author": "Felix Boehm <me@feedic.com>", | ||
"@types/node": "^17.0.23", | ||
"@typescript-eslint/eslint-plugin": "^5.17.0", | ||
"@typescript-eslint/parser": "^5.17.0", | ||
"@typescript-eslint/eslint-plugin": "^5.18.0", | ||
"@typescript-eslint/parser": "^5.18.0", | ||
"eslint": "^8.12.0", | ||
@@ -48,3 +48,3 @@ "eslint-config-prettier": "^8.5.0", | ||
"jest": "^27.5.1", | ||
"prettier": "^2.6.1", | ||
"prettier": "^2.6.2", | ||
"ts-jest": "^27.1.4", | ||
@@ -51,0 +51,0 @@ "typedoc": "^0.22.13", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
726088
2150