html-entities
Advanced tools
Comparing version 2.4.0 to 2.5.0
201
lib/index.js
@@ -1,199 +0,2 @@ | ||
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var named_references_1 = require("./named-references"); | ||
var numeric_unicode_map_1 = require("./numeric-unicode-map"); | ||
var surrogate_pairs_1 = require("./surrogate-pairs"); | ||
var allNamedReferences = __assign(__assign({}, named_references_1.namedReferences), { all: named_references_1.namedReferences.html5 }); | ||
var encodeRegExps = { | ||
specialChars: /[<>'"&]/g, | ||
nonAscii: /[<>'"&\u0080-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/g, | ||
nonAsciiPrintable: /[<>'"&\x01-\x08\x11-\x15\x17-\x1F\x7f-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/g, | ||
nonAsciiPrintableOnly: /[\x01-\x08\x11-\x15\x17-\x1F\x7f-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/g, | ||
extensive: /[\x01-\x0c\x0e-\x1f\x21-\x2c\x2e-\x2f\x3a-\x40\x5b-\x60\x7b-\x7d\x7f-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/g | ||
}; | ||
var defaultEncodeOptions = { | ||
mode: 'specialChars', | ||
level: 'all', | ||
numeric: 'decimal' | ||
}; | ||
/** Encodes all the necessary (specified by `level`) characters in the text */ | ||
function encode(text, _a) { | ||
var _b = _a === void 0 ? defaultEncodeOptions : _a, _c = _b.mode, mode = _c === void 0 ? 'specialChars' : _c, _d = _b.numeric, numeric = _d === void 0 ? 'decimal' : _d, _e = _b.level, level = _e === void 0 ? 'all' : _e; | ||
if (!text) { | ||
return ''; | ||
} | ||
var encodeRegExp = encodeRegExps[mode]; | ||
var references = allNamedReferences[level].characters; | ||
var isHex = numeric === 'hexadecimal'; | ||
encodeRegExp.lastIndex = 0; | ||
var _b = encodeRegExp.exec(text); | ||
var _c; | ||
if (_b) { | ||
_c = ''; | ||
var _d = 0; | ||
do { | ||
if (_d !== _b.index) { | ||
_c += text.substring(_d, _b.index); | ||
} | ||
var _e = _b[0]; | ||
var result_1 = references[_e]; | ||
if (!result_1) { | ||
var code_1 = _e.length > 1 ? surrogate_pairs_1.getCodePoint(_e, 0) : _e.charCodeAt(0); | ||
result_1 = (isHex ? '&#x' + code_1.toString(16) : '&#' + code_1) + ';'; | ||
} | ||
_c += result_1; | ||
_d = _b.index + _e.length; | ||
} while ((_b = encodeRegExp.exec(text))); | ||
if (_d !== text.length) { | ||
_c += text.substring(_d); | ||
} | ||
} | ||
else { | ||
_c = | ||
text; | ||
} | ||
return _c; | ||
} | ||
exports.encode = encode; | ||
var defaultDecodeOptions = { | ||
scope: 'body', | ||
level: 'all' | ||
}; | ||
var strict = /&(?:#\d+|#[xX][\da-fA-F]+|[0-9a-zA-Z]+);/g; | ||
var attribute = /&(?:#\d+|#[xX][\da-fA-F]+|[0-9a-zA-Z]+)[;=]?/g; | ||
var baseDecodeRegExps = { | ||
xml: { | ||
strict: strict, | ||
attribute: attribute, | ||
body: named_references_1.bodyRegExps.xml | ||
}, | ||
html4: { | ||
strict: strict, | ||
attribute: attribute, | ||
body: named_references_1.bodyRegExps.html4 | ||
}, | ||
html5: { | ||
strict: strict, | ||
attribute: attribute, | ||
body: named_references_1.bodyRegExps.html5 | ||
} | ||
}; | ||
var decodeRegExps = __assign(__assign({}, baseDecodeRegExps), { all: baseDecodeRegExps.html5 }); | ||
var fromCharCode = String.fromCharCode; | ||
var outOfBoundsChar = fromCharCode(65533); | ||
var defaultDecodeEntityOptions = { | ||
level: 'all' | ||
}; | ||
/** Decodes a single entity */ | ||
function decodeEntity(entity, _a) { | ||
var _b = (_a === void 0 ? defaultDecodeEntityOptions : _a).level, level = _b === void 0 ? 'all' : _b; | ||
if (!entity) { | ||
return ''; | ||
} | ||
var _b = entity; | ||
var decodeEntityLastChar_1 = entity[entity.length - 1]; | ||
if (false | ||
&& decodeEntityLastChar_1 === '=') { | ||
_b = | ||
entity; | ||
} | ||
else if (false | ||
&& decodeEntityLastChar_1 !== ';') { | ||
_b = | ||
entity; | ||
} | ||
else { | ||
var decodeResultByReference_1 = allNamedReferences[level].entities[entity]; | ||
if (decodeResultByReference_1) { | ||
_b = decodeResultByReference_1; | ||
} | ||
else if (entity[0] === '&' && entity[1] === '#') { | ||
var decodeSecondChar_1 = entity[2]; | ||
var decodeCode_1 = decodeSecondChar_1 == 'x' || decodeSecondChar_1 == 'X' | ||
? parseInt(entity.substr(3), 16) | ||
: parseInt(entity.substr(2)); | ||
_b = | ||
decodeCode_1 >= 0x10ffff | ||
? outOfBoundsChar | ||
: decodeCode_1 > 65535 | ||
? surrogate_pairs_1.fromCodePoint(decodeCode_1) | ||
: fromCharCode(numeric_unicode_map_1.numericUnicodeMap[decodeCode_1] || decodeCode_1); | ||
} | ||
} | ||
return _b; | ||
} | ||
exports.decodeEntity = decodeEntity; | ||
/** Decodes all entities in the text */ | ||
function decode(text, _a) { | ||
var decodeSecondChar_1 = _a === void 0 ? defaultDecodeOptions : _a, decodeCode_1 = decodeSecondChar_1.level, level = decodeCode_1 === void 0 ? 'all' : decodeCode_1, _b = decodeSecondChar_1.scope, scope = _b === void 0 ? level === 'xml' ? 'strict' : 'body' : _b; | ||
if (!text) { | ||
return ''; | ||
} | ||
var decodeRegExp = decodeRegExps[level][scope]; | ||
var references = allNamedReferences[level].entities; | ||
var isAttribute = scope === 'attribute'; | ||
var isStrict = scope === 'strict'; | ||
decodeRegExp.lastIndex = 0; | ||
var replaceMatch_1 = decodeRegExp.exec(text); | ||
var replaceResult_1; | ||
if (replaceMatch_1) { | ||
replaceResult_1 = ''; | ||
var replaceLastIndex_1 = 0; | ||
do { | ||
if (replaceLastIndex_1 !== replaceMatch_1.index) { | ||
replaceResult_1 += text.substring(replaceLastIndex_1, replaceMatch_1.index); | ||
} | ||
var replaceInput_1 = replaceMatch_1[0]; | ||
var decodeResult_1 = replaceInput_1; | ||
var decodeEntityLastChar_2 = replaceInput_1[replaceInput_1.length - 1]; | ||
if (isAttribute | ||
&& decodeEntityLastChar_2 === '=') { | ||
decodeResult_1 = replaceInput_1; | ||
} | ||
else if (isStrict | ||
&& decodeEntityLastChar_2 !== ';') { | ||
decodeResult_1 = replaceInput_1; | ||
} | ||
else { | ||
var decodeResultByReference_2 = references[replaceInput_1]; | ||
if (decodeResultByReference_2) { | ||
decodeResult_1 = decodeResultByReference_2; | ||
} | ||
else if (replaceInput_1[0] === '&' && replaceInput_1[1] === '#') { | ||
var decodeSecondChar_2 = replaceInput_1[2]; | ||
var decodeCode_2 = decodeSecondChar_2 == 'x' || decodeSecondChar_2 == 'X' | ||
? parseInt(replaceInput_1.substr(3), 16) | ||
: parseInt(replaceInput_1.substr(2)); | ||
decodeResult_1 = | ||
decodeCode_2 >= 0x10ffff | ||
? outOfBoundsChar | ||
: decodeCode_2 > 65535 | ||
? surrogate_pairs_1.fromCodePoint(decodeCode_2) | ||
: fromCharCode(numeric_unicode_map_1.numericUnicodeMap[decodeCode_2] || decodeCode_2); | ||
} | ||
} | ||
replaceResult_1 += decodeResult_1; | ||
replaceLastIndex_1 = replaceMatch_1.index + replaceInput_1.length; | ||
} while ((replaceMatch_1 = decodeRegExp.exec(text))); | ||
if (replaceLastIndex_1 !== text.length) { | ||
replaceResult_1 += text.substring(replaceLastIndex_1); | ||
} | ||
} | ||
else { | ||
replaceResult_1 = | ||
text; | ||
} | ||
return replaceResult_1; | ||
} | ||
exports.decode = decode; | ||
"use strict";var __assign=this&&this.__assign||function(){__assign=Object.assign||function(t){for(var s,i=1,n=arguments.length;i<n;i++){s=arguments[i];for(var p in s)if(Object.prototype.hasOwnProperty.call(s,p))t[p]=s[p]}return t};return __assign.apply(this,arguments)};Object.defineProperty(exports,"__esModule",{value:true});var named_references_1=require("./named-references");var numeric_unicode_map_1=require("./numeric-unicode-map");var surrogate_pairs_1=require("./surrogate-pairs");var allNamedReferences=__assign(__assign({},named_references_1.namedReferences),{all:named_references_1.namedReferences.html5});function replaceUsingRegExp(macroText,macroRegExp,macroReplacer){macroRegExp.lastIndex=0;var replaceMatch=macroRegExp.exec(macroText);var replaceResult;if(replaceMatch){replaceResult="";var replaceLastIndex=0;do{if(replaceLastIndex!==replaceMatch.index){replaceResult+=macroText.substring(replaceLastIndex,replaceMatch.index)}var replaceInput=replaceMatch[0];replaceResult+=macroReplacer(replaceInput);replaceLastIndex=replaceMatch.index+replaceInput.length}while(replaceMatch=macroRegExp.exec(macroText));if(replaceLastIndex!==macroText.length){replaceResult+=macroText.substring(replaceLastIndex)}}else{replaceResult=macroText}return replaceResult}var encodeRegExps={specialChars:/[<>'"&]/g,nonAscii:/[<>'"&\u0080-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/g,nonAsciiPrintable:/[<>'"&\x01-\x08\x11-\x15\x17-\x1F\x7f-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/g,nonAsciiPrintableOnly:/[\x01-\x08\x11-\x15\x17-\x1F\x7f-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/g,extensive:/[\x01-\x0c\x0e-\x1f\x21-\x2c\x2e-\x2f\x3a-\x40\x5b-\x60\x7b-\x7d\x7f-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/g};var defaultEncodeOptions={mode:"specialChars",level:"all",numeric:"decimal"};function encode(text,_a){var _b=_a===void 0?defaultEncodeOptions:_a,_c=_b.mode,mode=_c===void 0?"specialChars":_c,_d=_b.numeric,numeric=_d===void 0?"decimal":_d,_e=_b.level,level=_e===void 0?"all":_e;if(!text){return""}var encodeRegExp=encodeRegExps[mode];var references=allNamedReferences[level].characters;var isHex=numeric==="hexadecimal";return replaceUsingRegExp(text,encodeRegExp,(function(input){var result=references[input];if(!result){var code=input.length>1?surrogate_pairs_1.getCodePoint(input,0):input.charCodeAt(0);result=(isHex?"&#x"+code.toString(16):"&#"+code)+";"}return result}))}exports.encode=encode;var defaultDecodeOptions={scope:"body",level:"all"};var strict=/&(?:#\d+|#[xX][\da-fA-F]+|[0-9a-zA-Z]+);/g;var attribute=/&(?:#\d+|#[xX][\da-fA-F]+|[0-9a-zA-Z]+)[;=]?/g;var baseDecodeRegExps={xml:{strict:strict,attribute:attribute,body:named_references_1.bodyRegExps.xml},html4:{strict:strict,attribute:attribute,body:named_references_1.bodyRegExps.html4},html5:{strict:strict,attribute:attribute,body:named_references_1.bodyRegExps.html5}};var decodeRegExps=__assign(__assign({},baseDecodeRegExps),{all:baseDecodeRegExps.html5});var fromCharCode=String.fromCharCode;var outOfBoundsChar=fromCharCode(65533);var defaultDecodeEntityOptions={level:"all"};function getDecodedEntity(entity,references,isAttribute,isStrict){var decodeResult=entity;var decodeEntityLastChar=entity[entity.length-1];if(isAttribute&&decodeEntityLastChar==="="){decodeResult=entity}else if(isStrict&&decodeEntityLastChar!==";"){decodeResult=entity}else{var decodeResultByReference=references[entity];if(decodeResultByReference){decodeResult=decodeResultByReference}else if(entity[0]==="&"&&entity[1]==="#"){var decodeSecondChar=entity[2];var decodeCode=decodeSecondChar=="x"||decodeSecondChar=="X"?parseInt(entity.substr(3),16):parseInt(entity.substr(2));decodeResult=decodeCode>=1114111?outOfBoundsChar:decodeCode>65535?surrogate_pairs_1.fromCodePoint(decodeCode):fromCharCode(numeric_unicode_map_1.numericUnicodeMap[decodeCode]||decodeCode)}}return decodeResult}function decodeEntity(entity,_a){var _b=(_a===void 0?defaultDecodeEntityOptions:_a).level,level=_b===void 0?"all":_b;if(!entity){return""}return getDecodedEntity(entity,allNamedReferences[level].entities,false,false)}exports.decodeEntity=decodeEntity;function decode(text,_a){var _b=_a===void 0?defaultDecodeOptions:_a,_c=_b.level,level=_c===void 0?"all":_c,_d=_b.scope,scope=_d===void 0?level==="xml"?"strict":"body":_d;if(!text){return""}var decodeRegExp=decodeRegExps[level][scope];var references=allNamedReferences[level].entities;var isAttribute=scope==="attribute";var isStrict=scope==="strict";return replaceUsingRegExp(text,decodeRegExp,(function(entity){return getDecodedEntity(entity,references,isAttribute,isStrict)}))}exports.decode=decode; | ||
//# sourceMappingURL=./index.js.map |
@@ -1,1 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.numericUnicodeMap={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}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.numericUnicodeMap={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}; | ||
//# sourceMappingURL=./numeric-unicode-map.js.map |
@@ -1,1 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.fromCodePoint=String.fromCodePoint||function(astralCodePoint){return String.fromCharCode(Math.floor((astralCodePoint-65536)/1024)+55296,(astralCodePoint-65536)%1024+56320)};exports.getCodePoint=String.prototype.codePointAt?function(input,position){return input.codePointAt(position)}:function(input,position){return(input.charCodeAt(position)-55296)*1024+input.charCodeAt(position+1)-56320+65536};exports.highSurrogateFrom=55296;exports.highSurrogateTo=56319; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.fromCodePoint=String.fromCodePoint||function(astralCodePoint){return String.fromCharCode(Math.floor((astralCodePoint-65536)/1024)+55296,(astralCodePoint-65536)%1024+56320)};exports.getCodePoint=String.prototype.codePointAt?function(input,position){return input.codePointAt(position)}:function(input,position){return(input.charCodeAt(position)-55296)*1024+input.charCodeAt(position+1)-56320+65536};exports.highSurrogateFrom=55296;exports.highSurrogateTo=56319; | ||
//# sourceMappingURL=./surrogate-pairs.js.map |
{ | ||
"name": "html-entities", | ||
"version": "2.4.0", | ||
"version": "2.5.0", | ||
"description": "Fastest HTML entities encode/decode library.", | ||
@@ -50,5 +50,3 @@ "keywords": [ | ||
"ts-node": "^8.9.1", | ||
"ttypescript": "^1.5.15", | ||
"typescript": "^3.8.3", | ||
"typescript-transform-macros": "^1.1.1" | ||
"typescript": "^3.8.3" | ||
}, | ||
@@ -64,10 +62,11 @@ "repository": { | ||
"scripts": { | ||
"test": "TS_NODE_COMPILER=ttypescript mocha --recursive -r ts-node/register test/**/*.ts", | ||
"test": "mocha --recursive -r ts-node/register test/**/*.ts", | ||
"test:watch": "mocha -w --recursive -r ts-node/register test/**/*.ts", | ||
"test:lib": "TEST_LIB=1 npm run test", | ||
"benchmark": "TS_NODE_COMPILER=ttypescript ts-node benchmark/benchmark", | ||
"benchmark": "ts-node benchmark/benchmark", | ||
"lint": "eslint src/**.ts", | ||
"flow-type-gen": "flowgen --add-flow-header lib/index.d.ts -o lib/index.js.flow", | ||
"remove-unused-declarations": "find lib -type f \\( -name '*.d.ts' ! -name index.d.ts \\) | xargs rm", | ||
"minimize-lib-files": "find lib -type f \\( -name '*.js' ! -name index.js \\) | while read fn; do terser $fn -o $fn; done", | ||
"build": "rm -Rf lib/* && ttsc && npm run remove-unused-declarations && npm run flow-type-gen && npm run minimize-lib-files && npm run test:lib", | ||
"minimize-lib-files": "cd lib && find . -type f \\( -name '*.js' \\) | while read fn; do terser --source-map \"content='$fn.map',filename='$fn.map',url='$fn.map'\" $fn -o $fn; done", | ||
"build": "rm -Rf lib/* && tsc && npm run remove-unused-declarations && npm run flow-type-gen && npm run minimize-lib-files && npm run test:lib", | ||
"prepublishOnly": "npm run build" | ||
@@ -74,0 +73,0 @@ }, |
Sorry, the diff of this file is too big to display
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
143567
22
13
337
1
1