oro-php-locutus
Version:
Fork of few Locutus functions that have been rewritten in TypeScript.
733 lines (725 loc) • 23.5 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var index_exports = {};
__export(index_exports, {
HTMLSPECIALCHARS_ENT_COMPAT: () => HTMLSPECIALCHARS_ENT_COMPAT,
HTMLSPECIALCHARS_ENT_HTML_QUOTE_DOUBLE: () => HTMLSPECIALCHARS_ENT_HTML_QUOTE_DOUBLE,
HTMLSPECIALCHARS_ENT_HTML_QUOTE_SINGLE: () => HTMLSPECIALCHARS_ENT_HTML_QUOTE_SINGLE,
HTMLSPECIALCHARS_ENT_IGNORE: () => HTMLSPECIALCHARS_ENT_IGNORE,
HTMLSPECIALCHARS_ENT_NOQUOTES: () => HTMLSPECIALCHARS_ENT_NOQUOTES,
HTMLSPECIALCHARS_ENT_QUOTES: () => HTMLSPECIALCHARS_ENT_QUOTES,
htmlspecialchars: () => htmlspecialchars,
md5: () => md5,
serialize: () => serialize,
unserialize: () => unserialize,
utf8Decode: () => utf8Decode,
utf8Encode: () => utf8Encode
});
module.exports = __toCommonJS(index_exports);
// src/locutus/htmlspecialchars/htmlspecialchars.ts
var HTMLSPECIALCHARS_ENT_NOQUOTES = "ENT_NOQUOTES";
var HTMLSPECIALCHARS_ENT_HTML_QUOTE_SINGLE = "ENT_HTML_QUOTE_SINGLE";
var HTMLSPECIALCHARS_ENT_HTML_QUOTE_DOUBLE = "ENT_HTML_QUOTE_DOUBLE";
var HTMLSPECIALCHARS_ENT_COMPAT = "ENT_COMPAT";
var HTMLSPECIALCHARS_ENT_QUOTES = "ENT_QUOTES";
var HTMLSPECIALCHARS_ENT_IGNORE = "ENT_IGNORE";
function htmlspecialchars(string, quoteStyle, charset, doubleEncode) {
let optTemp = 0;
let index = 0;
let noquotes = false;
if (quoteStyle === void 0 || quoteStyle === null) {
quoteStyle = 2;
}
string = string || "";
string = string.toString();
if (doubleEncode !== false) {
string = string.replace(/&/g, "&");
}
string = string.replace(/</g, "<").replace(/>/g, ">");
const OPTS = {
ENT_NOQUOTES: 0,
ENT_HTML_QUOTE_SINGLE: 1,
ENT_HTML_QUOTE_DOUBLE: 2,
ENT_COMPAT: 2,
ENT_QUOTES: 3,
ENT_IGNORE: 4
};
if (quoteStyle === 0) {
noquotes = true;
}
if (typeof quoteStyle !== "number") {
quoteStyle = Array.isArray(quoteStyle) ? quoteStyle : [quoteStyle];
for (index = 0; index < quoteStyle.length; index++) {
if (OPTS[quoteStyle[index]] === 0) {
noquotes = true;
} else if (OPTS[quoteStyle[index]]) {
optTemp = optTemp | OPTS[quoteStyle[index]];
}
}
quoteStyle = optTemp;
}
if (quoteStyle & OPTS.ENT_HTML_QUOTE_SINGLE) {
string = string.replace(/'/g, "'");
}
if (!noquotes) {
string = string.replace(/"/g, """);
}
return string;
}
// src/locutus/utf8-encode/utf8-encode.ts
function utf8Encode(string) {
if (string === null || string === void 0) {
return "";
}
const strData = String(string);
let utftext = "";
let start;
let end;
const stringl = strData.length;
start = end = 0;
for (let n = 0; n < stringl; n++) {
let c1 = strData.charCodeAt(n);
let enc = null;
if (c1 < 128) {
end++;
} else if (c1 > 127 && c1 < 2048) {
enc = String.fromCharCode(c1 >> 6 | 192, c1 & 63 | 128);
} else if ((c1 & 63488) !== 55296) {
enc = String.fromCharCode(c1 >> 12 | 224, c1 >> 6 & 63 | 128, c1 & 63 | 128);
} else {
if ((c1 & 64512) !== 55296) {
throw new RangeError("Unmatched trail surrogate at " + n);
}
const c2 = strData.charCodeAt(++n);
if ((c2 & 64512) !== 56320) {
throw new RangeError("Unmatched lead surrogate at " + (n - 1));
}
c1 = ((c1 & 1023) << 10) + (c2 & 1023) + 65536;
enc = String.fromCharCode(c1 >> 18 | 240, c1 >> 12 & 63 | 128, c1 >> 6 & 63 | 128, c1 & 63 | 128);
}
if (enc !== null) {
if (end > start) {
utftext += strData.slice(start, end);
}
utftext += enc;
start = end = n + 1;
}
}
if (end > start) {
utftext += strData.slice(start, stringl);
}
return utftext;
}
// src/locutus/md5/md5.ts
function md5(string) {
if (string === void 0 || string === null) {
return "";
}
let hash;
try {
const crypto = require("crypto");
const md5sum = crypto.createHash("md5");
md5sum.update(string);
hash = md5sum.digest("hex");
} catch {
hash = void 0;
}
if (hash !== void 0) {
return hash;
}
const _rotateLeft = function(lValue, indexShiftBits) {
return lValue << indexShiftBits | lValue >>> 32 - indexShiftBits;
};
const _addUnsigned = function(lX, lY) {
const lX8 = lX & 2147483648;
const lY8 = lY & 2147483648;
const lX4 = lX & 1073741824;
const lY4 = lY & 1073741824;
const lResult = (lX & 1073741823) + (lY & 1073741823);
if (lX4 & lY4) {
return lResult ^ 2147483648 ^ lX8 ^ lY8;
}
if (lX4 | lY4) {
return lResult & 1073741824 ? lResult ^ 3221225472 ^ lX8 ^ lY8 : lResult ^ 1073741824 ^ lX8 ^ lY8;
} else {
return lResult ^ lX8 ^ lY8;
}
};
const _F = function(x2, y, z) {
return x2 & y | ~x2 & z;
};
const _G = function(x2, y, z) {
return x2 & z | y & ~z;
};
const _H = function(x2, y, z) {
return x2 ^ y ^ z;
};
const _I = function(x2, y, z) {
return y ^ (x2 | ~z);
};
const _FF = function(a2, b2, c2, d2, x2, s, ac) {
a2 = _addUnsigned(a2, _addUnsigned(_addUnsigned(_F(b2, c2, d2), x2), ac));
return _addUnsigned(_rotateLeft(a2, s), b2);
};
const _GG = function(a2, b2, c2, d2, x2, s, ac) {
a2 = _addUnsigned(a2, _addUnsigned(_addUnsigned(_G(b2, c2, d2), x2), ac));
return _addUnsigned(_rotateLeft(a2, s), b2);
};
const _HH = function(a2, b2, c2, d2, x2, s, ac) {
a2 = _addUnsigned(a2, _addUnsigned(_addUnsigned(_H(b2, c2, d2), x2), ac));
return _addUnsigned(_rotateLeft(a2, s), b2);
};
const _II = function(a2, b2, c2, d2, x2, s, ac) {
a2 = _addUnsigned(a2, _addUnsigned(_addUnsigned(_I(b2, c2, d2), x2), ac));
return _addUnsigned(_rotateLeft(a2, s), b2);
};
const _convertToWordArray = function(string2) {
let lWordCount;
const lMessageLength = string2.length;
const lNumberOfWordsTemporary1 = lMessageLength + 8;
const lNumberOfWordsTemporary2 = (lNumberOfWordsTemporary1 - lNumberOfWordsTemporary1 % 64) / 64;
const lNumberOfWords = (lNumberOfWordsTemporary2 + 1) * 16;
const lWordArray = Array.from({ length: lNumberOfWords - 1 });
let lBytePosition = 0;
let lByteCount = 0;
while (lByteCount < lMessageLength) {
lWordCount = (lByteCount - lByteCount % 4) / 4;
lBytePosition = lByteCount % 4 * 8;
lWordArray[lWordCount] = lWordArray[lWordCount] | string2.charCodeAt(lByteCount) << lBytePosition;
lByteCount++;
}
lWordCount = (lByteCount - lByteCount % 4) / 4;
lBytePosition = lByteCount % 4 * 8;
lWordArray[lWordCount] = lWordArray[lWordCount] | 128 << lBytePosition;
lWordArray[lNumberOfWords - 2] = lMessageLength << 3;
lWordArray[lNumberOfWords - 1] = lMessageLength >>> 29;
return lWordArray;
};
const _wordToHex = function(lValue) {
let wordToHexValue = "";
let wordToHexValueTemporary = "";
let lByte;
let lCount;
for (lCount = 0; lCount <= 3; lCount++) {
lByte = lValue >>> lCount * 8 & 255;
wordToHexValueTemporary = "0" + lByte.toString(16);
wordToHexValue = wordToHexValue + wordToHexValueTemporary.slice(-2, wordToHexValueTemporary.length - 2 + 2);
}
return wordToHexValue;
};
let k;
let AA;
let BB;
let CC;
let DD;
let a;
let b;
let c;
let d;
const S11 = 7;
const S12 = 12;
const S13 = 17;
const S14 = 22;
const S21 = 5;
const S22 = 9;
const S23 = 14;
const S24 = 20;
const S31 = 4;
const S32 = 11;
const S33 = 16;
const S34 = 23;
const S41 = 6;
const S42 = 10;
const S43 = 15;
const S44 = 21;
string = utf8Encode(string);
const x = _convertToWordArray(string);
a = 1732584193;
b = 4023233417;
c = 2562383102;
d = 271733878;
const xl = x.length;
for (k = 0; k < xl; k += 16) {
AA = a;
BB = b;
CC = c;
DD = d;
a = _FF(a, b, c, d, x[k + 0], S11, 3614090360);
d = _FF(d, a, b, c, x[k + 1], S12, 3905402710);
c = _FF(c, d, a, b, x[k + 2], S13, 606105819);
b = _FF(b, c, d, a, x[k + 3], S14, 3250441966);
a = _FF(a, b, c, d, x[k + 4], S11, 4118548399);
d = _FF(d, a, b, c, x[k + 5], S12, 1200080426);
c = _FF(c, d, a, b, x[k + 6], S13, 2821735955);
b = _FF(b, c, d, a, x[k + 7], S14, 4249261313);
a = _FF(a, b, c, d, x[k + 8], S11, 1770035416);
d = _FF(d, a, b, c, x[k + 9], S12, 2336552879);
c = _FF(c, d, a, b, x[k + 10], S13, 4294925233);
b = _FF(b, c, d, a, x[k + 11], S14, 2304563134);
a = _FF(a, b, c, d, x[k + 12], S11, 1804603682);
d = _FF(d, a, b, c, x[k + 13], S12, 4254626195);
c = _FF(c, d, a, b, x[k + 14], S13, 2792965006);
b = _FF(b, c, d, a, x[k + 15], S14, 1236535329);
a = _GG(a, b, c, d, x[k + 1], S21, 4129170786);
d = _GG(d, a, b, c, x[k + 6], S22, 3225465664);
c = _GG(c, d, a, b, x[k + 11], S23, 643717713);
b = _GG(b, c, d, a, x[k + 0], S24, 3921069994);
a = _GG(a, b, c, d, x[k + 5], S21, 3593408605);
d = _GG(d, a, b, c, x[k + 10], S22, 38016083);
c = _GG(c, d, a, b, x[k + 15], S23, 3634488961);
b = _GG(b, c, d, a, x[k + 4], S24, 3889429448);
a = _GG(a, b, c, d, x[k + 9], S21, 568446438);
d = _GG(d, a, b, c, x[k + 14], S22, 3275163606);
c = _GG(c, d, a, b, x[k + 3], S23, 4107603335);
b = _GG(b, c, d, a, x[k + 8], S24, 1163531501);
a = _GG(a, b, c, d, x[k + 13], S21, 2850285829);
d = _GG(d, a, b, c, x[k + 2], S22, 4243563512);
c = _GG(c, d, a, b, x[k + 7], S23, 1735328473);
b = _GG(b, c, d, a, x[k + 12], S24, 2368359562);
a = _HH(a, b, c, d, x[k + 5], S31, 4294588738);
d = _HH(d, a, b, c, x[k + 8], S32, 2272392833);
c = _HH(c, d, a, b, x[k + 11], S33, 1839030562);
b = _HH(b, c, d, a, x[k + 14], S34, 4259657740);
a = _HH(a, b, c, d, x[k + 1], S31, 2763975236);
d = _HH(d, a, b, c, x[k + 4], S32, 1272893353);
c = _HH(c, d, a, b, x[k + 7], S33, 4139469664);
b = _HH(b, c, d, a, x[k + 10], S34, 3200236656);
a = _HH(a, b, c, d, x[k + 13], S31, 681279174);
d = _HH(d, a, b, c, x[k + 0], S32, 3936430074);
c = _HH(c, d, a, b, x[k + 3], S33, 3572445317);
b = _HH(b, c, d, a, x[k + 6], S34, 76029189);
a = _HH(a, b, c, d, x[k + 9], S31, 3654602809);
d = _HH(d, a, b, c, x[k + 12], S32, 3873151461);
c = _HH(c, d, a, b, x[k + 15], S33, 530742520);
b = _HH(b, c, d, a, x[k + 2], S34, 3299628645);
a = _II(a, b, c, d, x[k + 0], S41, 4096336452);
d = _II(d, a, b, c, x[k + 7], S42, 1126891415);
c = _II(c, d, a, b, x[k + 14], S43, 2878612391);
b = _II(b, c, d, a, x[k + 5], S44, 4237533241);
a = _II(a, b, c, d, x[k + 12], S41, 1700485571);
d = _II(d, a, b, c, x[k + 3], S42, 2399980690);
c = _II(c, d, a, b, x[k + 10], S43, 4293915773);
b = _II(b, c, d, a, x[k + 1], S44, 2240044497);
a = _II(a, b, c, d, x[k + 8], S41, 1873313359);
d = _II(d, a, b, c, x[k + 15], S42, 4264355552);
c = _II(c, d, a, b, x[k + 6], S43, 2734768916);
b = _II(b, c, d, a, x[k + 13], S44, 1309151649);
a = _II(a, b, c, d, x[k + 4], S41, 4149444226);
d = _II(d, a, b, c, x[k + 11], S42, 3174756917);
c = _II(c, d, a, b, x[k + 2], S43, 718787259);
b = _II(b, c, d, a, x[k + 9], S44, 3951481745);
a = _addUnsigned(a, AA);
b = _addUnsigned(b, BB);
c = _addUnsigned(c, CC);
d = _addUnsigned(d, DD);
}
const temporary = _wordToHex(a) + _wordToHex(b) + _wordToHex(c) + _wordToHex(d);
return temporary.toLowerCase();
}
// src/locutus/serialize/serialize.ts
function serialize(mixedValue) {
let value;
let key;
let okey;
let ktype = "";
let vals = "";
let count = 0;
const _utf8Size = function(string) {
return ~-encodeURI(string).split(/%..|./).length;
};
const _getType = function(input) {
let match;
let key2;
let cons;
let types;
let type2 = typeof input;
if (type2 === "object" && !input) {
return "null";
}
if (type2 === "object") {
if (!input.constructor) {
return "object";
}
cons = input.constructor.toString();
match = cons.match(/(\w+)\(/);
if (match) {
cons = match[1].toLowerCase();
}
types = ["boolean", "number", "string", "array"];
for (key2 in types) {
if (cons === types[key2]) {
type2 = types[key2];
break;
}
}
}
return type2;
};
const type = _getType(mixedValue);
switch (type) {
case "function":
value = "";
break;
case "boolean":
value = "b:" + (mixedValue ? "1" : "0");
break;
case "number":
value = (Math.round(mixedValue) === mixedValue ? "i" : "d") + ":" + mixedValue;
break;
case "string":
value = "s:" + _utf8Size(mixedValue) + ':"' + mixedValue + '"';
break;
case "array":
case "object":
value = "a";
for (key in mixedValue) {
if (Object.prototype.hasOwnProperty.call(mixedValue, key)) {
ktype = _getType(mixedValue[key]);
if (ktype === "function") {
continue;
}
okey = /^\d+$/.test(key) ? Number.parseInt(key, 10) : key;
vals += serialize(okey) + serialize(mixedValue[key]);
count++;
}
}
value += ":" + count + ":{" + vals + "}";
break;
// case 'undefined':
default:
value = "N";
break;
}
if (type !== "object" && type !== "array") {
value += ";";
}
return value;
}
// src/locutus/unserialize/unserialize.ts
function unserialize(string, showError = false) {
try {
if (typeof string !== "string") {
return string;
}
return expectType(string, initCache())[0];
} catch (error) {
if (showError) {
console.error(error);
}
return string;
}
}
function initCache() {
const store = [];
const cache = function cache2(value) {
store.push(value[0]);
return value;
};
cache.get = (index) => {
if (index >= store.length) {
throw new RangeError(`Can't resolve reference ${index + 1}`);
}
return store[index];
};
return cache;
}
function expectType(string, cache) {
const types = /^(?:N(?=;)|[CORSabdirs](?=:)|[^:]+(?=:))/g;
const type = (types.exec(string) || [])[0];
if (!type) {
throw new SyntaxError("Invalid input: " + string);
}
switch (type) {
case "N":
return cache([null, 2]);
case "b":
return cache(expectBool(string));
case "i":
return cache(expectInt(string));
case "d":
return cache(expectFloat(string));
case "s":
return cache(expectString(string));
case "S":
return cache(expectEscapedString(string));
case "a":
return expectArray(string, cache);
case "O":
return expectObject(string, cache);
case "C":
throw new Error("Not yet implemented");
// return expectClass(string, cache);
case "r":
case "R":
return expectReference(string, cache);
default:
throw new SyntaxError(`Invalid or unsupported data type: ${type}`);
}
}
function expectBool(string) {
const reBool = /^b:([01]);/;
const [match, boolMatch] = reBool.exec(string) || [];
if (!boolMatch) {
throw new SyntaxError("Invalid bool value, expected 0 or 1");
}
return [boolMatch === "1", match.length];
}
function expectInt(string) {
const reInt = /^i:([+-]?\d+);/;
const [match, intMatch] = reInt.exec(string) || [];
if (!intMatch) {
throw new SyntaxError("Expected an integer value");
}
return [Number.parseInt(intMatch, 10), match.length];
}
function expectFloat(string) {
const reFloat = /^d:(NAN|-?INF|(?:\d+\.\d*|\d*\.\d+|\d+)(?:[Ee][+-]\d+)?);/;
const [match, floatMatch] = reFloat.exec(string) || [];
if (!floatMatch) {
throw new SyntaxError("Expected a float value");
}
let floatValue;
switch (floatMatch) {
case "NAN":
floatValue = Number.NaN;
break;
case "-INF":
floatValue = Number.NEGATIVE_INFINITY;
break;
case "INF":
floatValue = Number.POSITIVE_INFINITY;
break;
default:
floatValue = Number.parseFloat(floatMatch);
break;
}
return [floatValue, match.length];
}
function readBytes(string, length, escapedString = false) {
let bytes = 0;
let out = "";
let c = 0;
const stringLength = string.length;
let wasHighSurrogate = false;
let escapedChars = 0;
while (bytes < length && c < stringLength) {
let chr = string.charAt(c);
const code = chr.charCodeAt(0);
const isHighSurrogate = code >= 55296 && code <= 56319;
const isLowSurrogate = code >= 56320 && code <= 57343;
if (escapedString && chr === "\\") {
chr = String.fromCharCode(Number.parseInt(string.slice(c + 1, 2), 16));
escapedChars++;
c += 2;
}
c++;
bytes += isHighSurrogate || isLowSurrogate && wasHighSurrogate ? (
// if high surrogate, count 2 bytes, as expectation is to be followed by low surrogate
// if low surrogate preceded by high surrogate, add 2 bytes
2
) : code > 2047 ? (
// otherwise low surrogate falls into this part
3
) : code > 127 ? 2 : 1;
bytes += wasHighSurrogate && !isLowSurrogate ? 1 : 0;
out += chr;
wasHighSurrogate = isHighSurrogate;
}
return [out, bytes, escapedChars];
}
function expectString(string) {
const reStringLength = /^s:(\d+):"/g;
const [match, byteLengthMatch] = reStringLength.exec(string) || [];
if (!match) {
throw new SyntaxError("Expected a string value");
}
const length = Number.parseInt(byteLengthMatch, 10);
string = string.slice(match.length);
const [stringMatch, bytes] = readBytes(string, length);
if (bytes !== length) {
throw new SyntaxError(`Expected string of ${length} bytes, but got ${bytes}`);
}
string = string.slice(stringMatch.length);
if (!string.startsWith('";')) {
throw new SyntaxError('Expected ";');
}
return [stringMatch, match.length + stringMatch.length + 2];
}
function expectEscapedString(string) {
const reStringLength = /^S:(\d+):"/g;
const [match, stringLengthMatch] = reStringLength.exec(string) || [];
if (!match) {
throw new SyntaxError("Expected an escaped string value");
}
const length = Number.parseInt(stringLengthMatch, 10);
string = string.slice(match.length);
const [stringMatch, bytes, escapedChars] = readBytes(string, length, true);
if (bytes !== length) {
throw new SyntaxError(`Expected escaped string of ${length} bytes, but got ${bytes}`);
}
string = string.slice(stringMatch.length + escapedChars * 2);
if (!string.startsWith('";')) {
throw new SyntaxError('Expected ";');
}
return [stringMatch, match.length + stringMatch.length + 2];
}
function expectKeyOrIndex(string) {
try {
return expectString(string);
} catch {
}
try {
return expectEscapedString(string);
} catch {
}
try {
return expectInt(string);
} catch {
throw new SyntaxError("Expected key or index");
}
}
function expectObject(string, cache) {
const reObjectLiteral = /^O:(\d+):"([^"]+)":(\d+):{/;
const [objectLiteralBeginMatch, , className, propertyCountMatch] = reObjectLiteral.exec(string) || [];
if (!objectLiteralBeginMatch) {
throw new SyntaxError("Invalid input");
}
if (className !== "stdClass") {
throw new SyntaxError(`Unsupported object type: ${className}`);
}
let totalOffset = objectLiteralBeginMatch.length;
const propertyCount = Number.parseInt(propertyCountMatch, 10);
const object = {};
cache([object]);
string = string.slice(totalOffset);
for (let index = 0; index < propertyCount; index++) {
const property = expectKeyOrIndex(string);
string = string.slice(property[1]);
totalOffset += property[1];
const value = expectType(string, cache);
string = string.slice(value[1]);
totalOffset += value[1];
object[property[0]] = value[0];
}
if (string.charAt(0) !== "}") {
throw new SyntaxError("Expected }");
}
return [object, totalOffset + 1];
}
function expectReference(string, cache) {
const reReference = /^[Rr]:([1-9]\d*);/;
const [match, referenceIndex] = reReference.exec(string) || [];
if (!match) {
throw new SyntaxError("Expected reference value");
}
return [cache.get(Number.parseInt(referenceIndex, 10) - 1), match.length];
}
function expectArray(string, cache) {
const reArrayLength = /^a:(\d+):{/;
const [arrayLiteralBeginMatch, arrayLengthMatch] = reArrayLength.exec(string) || [];
if (!arrayLengthMatch) {
throw new SyntaxError("Expected array length annotation");
}
string = string.slice(arrayLiteralBeginMatch.length);
const array = expectArrayItems(string, Number.parseInt(arrayLengthMatch, 10), cache);
if (string.charAt(array[1]) !== "}") {
throw new SyntaxError("Expected }");
}
return [array[0], arrayLiteralBeginMatch.length + array[1] + 1];
}
function expectArrayItems(string, expectedItems = 0, cache) {
let key;
let item;
let totalOffset = 0;
let hasContinousIndexes = true;
let lastIndex = -1;
let items = {};
cache([items]);
for (let index = 0; index < expectedItems; index++) {
key = expectKeyOrIndex(string);
hasContinousIndexes = hasContinousIndexes && typeof key[0] === "number" && key[0] === lastIndex + 1;
lastIndex = key[0];
string = string.slice(key[1]);
totalOffset += key[1];
item = expectType(string, cache);
string = string.slice(item[1]);
totalOffset += item[1];
items[key[0]] = item[0];
}
if (hasContinousIndexes) {
items = Object.values(items);
}
return [items, totalOffset];
}
// src/locutus/utf8-decode/utf8-decode.ts
function utf8Decode(string) {
let strData = string;
if (strData === null || strData === void 0) {
return "";
}
const tmpArr = [];
let index = 0;
let c1 = 0;
let seqlen = 0;
strData = String(strData);
while (index < strData.length) {
c1 = strData.charCodeAt(index) & 255;
seqlen = 0;
if (c1 <= 191) {
c1 = c1 & 127;
seqlen = 1;
} else if (c1 <= 223) {
c1 = c1 & 31;
seqlen = 2;
} else if (c1 <= 239) {
c1 = c1 & 15;
seqlen = 3;
} else {
c1 = c1 & 7;
seqlen = 4;
}
for (let ai = 1; ai < seqlen; ++ai) {
c1 = c1 << 6 | strData.charCodeAt(ai + index) & 63;
}
if (seqlen === 4) {
c1 -= 65536;
tmpArr.push(String.fromCharCode(55296 | c1 >> 10 & 1023), String.fromCharCode(56320 | c1 & 1023));
} else {
tmpArr.push(String.fromCharCode(c1));
}
index += seqlen;
}
return tmpArr.join("");
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
HTMLSPECIALCHARS_ENT_COMPAT,
HTMLSPECIALCHARS_ENT_HTML_QUOTE_DOUBLE,
HTMLSPECIALCHARS_ENT_HTML_QUOTE_SINGLE,
HTMLSPECIALCHARS_ENT_IGNORE,
HTMLSPECIALCHARS_ENT_NOQUOTES,
HTMLSPECIALCHARS_ENT_QUOTES,
htmlspecialchars,
md5,
serialize,
unserialize,
utf8Decode,
utf8Encode
});
;