linktree-parser
Version:
linktree-parser is a TypeScript library for scraping and extracting account, links, banners, and metadata from Linktree profiles.
1,422 lines (1,410 loc) • 1.74 MB
JavaScript
import {createRequire} from "node:module";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getProtoOf = Object.getPrototypeOf;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __toESM = (mod, isNodeMode, target) => {
target = mod != null ? __create(__getProtoOf(mod)) : {};
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
for (let key of __getOwnPropNames(mod))
if (!__hasOwnProp.call(to, key))
__defProp(to, key, {
get: () => mod[key],
enumerable: true
});
return to;
};
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, {
get: all[name],
enumerable: true,
configurable: true,
set: (newValue) => all[name] = () => newValue
});
};
var __require = createRequire(import.meta.url);
// node_modules/css-what/lib/commonjs/types.js
var require_types = __commonJS((exports) => {
Object.defineProperty(exports, "__esModule", { value: true });
exports.AttributeAction = exports.IgnoreCaseMode = exports.SelectorType = undefined;
var SelectorType;
(function(SelectorType2) {
SelectorType2["Attribute"] = "attribute";
SelectorType2["Pseudo"] = "pseudo";
SelectorType2["PseudoElement"] = "pseudo-element";
SelectorType2["Tag"] = "tag";
SelectorType2["Universal"] = "universal";
SelectorType2["Adjacent"] = "adjacent";
SelectorType2["Child"] = "child";
SelectorType2["Descendant"] = "descendant";
SelectorType2["Parent"] = "parent";
SelectorType2["Sibling"] = "sibling";
SelectorType2["ColumnCombinator"] = "column-combinator";
})(SelectorType = exports.SelectorType || (exports.SelectorType = {}));
exports.IgnoreCaseMode = {
Unknown: null,
QuirksMode: "quirks",
IgnoreCase: true,
CaseSensitive: false
};
var AttributeAction;
(function(AttributeAction2) {
AttributeAction2["Any"] = "any";
AttributeAction2["Element"] = "element";
AttributeAction2["End"] = "end";
AttributeAction2["Equals"] = "equals";
AttributeAction2["Exists"] = "exists";
AttributeAction2["Hyphen"] = "hyphen";
AttributeAction2["Not"] = "not";
AttributeAction2["Start"] = "start";
})(AttributeAction = exports.AttributeAction || (exports.AttributeAction = {}));
});
// node_modules/css-what/lib/commonjs/parse.js
var require_parse = __commonJS((exports) => {
var isTraversal = function(selector) {
switch (selector.type) {
case types_1.SelectorType.Adjacent:
case types_1.SelectorType.Child:
case types_1.SelectorType.Descendant:
case types_1.SelectorType.Parent:
case types_1.SelectorType.Sibling:
case types_1.SelectorType.ColumnCombinator:
return true;
default:
return false;
}
};
var funescape = function(_, escaped, escapedWhitespace) {
var high = parseInt(escaped, 16) - 65536;
return high !== high || escapedWhitespace ? escaped : high < 0 ? String.fromCharCode(high + 65536) : String.fromCharCode(high >> 10 | 55296, high & 1023 | 56320);
};
var unescapeCSS = function(str) {
return str.replace(reEscape, funescape);
};
var isQuote = function(c) {
return c === 39 || c === 34;
};
var isWhitespace = function(c) {
return c === 32 || c === 9 || c === 10 || c === 12 || c === 13;
};
var parse = function(selector) {
var subselects = [];
var endIndex = parseSelector(subselects, "".concat(selector), 0);
if (endIndex < selector.length) {
throw new Error("Unmatched selector: ".concat(selector.slice(endIndex)));
}
return subselects;
};
var parseSelector = function(subselects, selector, selectorIndex) {
var tokens = [];
function getName2(offset) {
var match = selector.slice(selectorIndex + offset).match(reName);
if (!match) {
throw new Error("Expected name, found ".concat(selector.slice(selectorIndex)));
}
var name = match[0];
selectorIndex += offset + name.length;
return unescapeCSS(name);
}
function stripWhitespace(offset) {
selectorIndex += offset;
while (selectorIndex < selector.length && isWhitespace(selector.charCodeAt(selectorIndex))) {
selectorIndex++;
}
}
function readValueWithParenthesis() {
selectorIndex += 1;
var start = selectorIndex;
var counter = 1;
for (;counter > 0 && selectorIndex < selector.length; selectorIndex++) {
if (selector.charCodeAt(selectorIndex) === 40 && !isEscaped(selectorIndex)) {
counter++;
} else if (selector.charCodeAt(selectorIndex) === 41 && !isEscaped(selectorIndex)) {
counter--;
}
}
if (counter) {
throw new Error("Parenthesis not matched");
}
return unescapeCSS(selector.slice(start, selectorIndex - 1));
}
function isEscaped(pos) {
var slashCount = 0;
while (selector.charCodeAt(--pos) === 92)
slashCount++;
return (slashCount & 1) === 1;
}
function ensureNotTraversal() {
if (tokens.length > 0 && isTraversal(tokens[tokens.length - 1])) {
throw new Error("Did not expect successive traversals.");
}
}
function addTraversal(type) {
if (tokens.length > 0 && tokens[tokens.length - 1].type === types_1.SelectorType.Descendant) {
tokens[tokens.length - 1].type = type;
return;
}
ensureNotTraversal();
tokens.push({ type });
}
function addSpecialAttribute(name, action2) {
tokens.push({
type: types_1.SelectorType.Attribute,
name,
action: action2,
value: getName2(1),
namespace: null,
ignoreCase: "quirks"
});
}
function finalizeSubselector() {
if (tokens.length && tokens[tokens.length - 1].type === types_1.SelectorType.Descendant) {
tokens.pop();
}
if (tokens.length === 0) {
throw new Error("Empty sub-selector");
}
subselects.push(tokens);
}
stripWhitespace(0);
if (selector.length === selectorIndex) {
return selectorIndex;
}
loop:
while (selectorIndex < selector.length) {
var firstChar = selector.charCodeAt(selectorIndex);
switch (firstChar) {
case 32:
case 9:
case 10:
case 12:
case 13: {
if (tokens.length === 0 || tokens[0].type !== types_1.SelectorType.Descendant) {
ensureNotTraversal();
tokens.push({ type: types_1.SelectorType.Descendant });
}
stripWhitespace(1);
break;
}
case 62: {
addTraversal(types_1.SelectorType.Child);
stripWhitespace(1);
break;
}
case 60: {
addTraversal(types_1.SelectorType.Parent);
stripWhitespace(1);
break;
}
case 126: {
addTraversal(types_1.SelectorType.Sibling);
stripWhitespace(1);
break;
}
case 43: {
addTraversal(types_1.SelectorType.Adjacent);
stripWhitespace(1);
break;
}
case 46: {
addSpecialAttribute("class", types_1.AttributeAction.Element);
break;
}
case 35: {
addSpecialAttribute("id", types_1.AttributeAction.Equals);
break;
}
case 91: {
stripWhitespace(1);
var name_1 = undefined;
var namespace = null;
if (selector.charCodeAt(selectorIndex) === 124) {
name_1 = getName2(1);
} else if (selector.startsWith("*|", selectorIndex)) {
namespace = "*";
name_1 = getName2(2);
} else {
name_1 = getName2(0);
if (selector.charCodeAt(selectorIndex) === 124 && selector.charCodeAt(selectorIndex + 1) !== 61) {
namespace = name_1;
name_1 = getName2(1);
}
}
stripWhitespace(0);
var action = types_1.AttributeAction.Exists;
var possibleAction = actionTypes.get(selector.charCodeAt(selectorIndex));
if (possibleAction) {
action = possibleAction;
if (selector.charCodeAt(selectorIndex + 1) !== 61) {
throw new Error("Expected `=`");
}
stripWhitespace(2);
} else if (selector.charCodeAt(selectorIndex) === 61) {
action = types_1.AttributeAction.Equals;
stripWhitespace(1);
}
var value = "";
var ignoreCase = null;
if (action !== "exists") {
if (isQuote(selector.charCodeAt(selectorIndex))) {
var quote = selector.charCodeAt(selectorIndex);
var sectionEnd = selectorIndex + 1;
while (sectionEnd < selector.length && (selector.charCodeAt(sectionEnd) !== quote || isEscaped(sectionEnd))) {
sectionEnd += 1;
}
if (selector.charCodeAt(sectionEnd) !== quote) {
throw new Error("Attribute value didn't end");
}
value = unescapeCSS(selector.slice(selectorIndex + 1, sectionEnd));
selectorIndex = sectionEnd + 1;
} else {
var valueStart = selectorIndex;
while (selectorIndex < selector.length && (!isWhitespace(selector.charCodeAt(selectorIndex)) && selector.charCodeAt(selectorIndex) !== 93 || isEscaped(selectorIndex))) {
selectorIndex += 1;
}
value = unescapeCSS(selector.slice(valueStart, selectorIndex));
}
stripWhitespace(0);
var forceIgnore = selector.charCodeAt(selectorIndex) | 32;
if (forceIgnore === 115) {
ignoreCase = false;
stripWhitespace(1);
} else if (forceIgnore === 105) {
ignoreCase = true;
stripWhitespace(1);
}
}
if (selector.charCodeAt(selectorIndex) !== 93) {
throw new Error("Attribute selector didn't terminate");
}
selectorIndex += 1;
var attributeSelector = {
type: types_1.SelectorType.Attribute,
name: name_1,
action,
value,
namespace,
ignoreCase
};
tokens.push(attributeSelector);
break;
}
case 58: {
if (selector.charCodeAt(selectorIndex + 1) === 58) {
tokens.push({
type: types_1.SelectorType.PseudoElement,
name: getName2(2).toLowerCase(),
data: selector.charCodeAt(selectorIndex) === 40 ? readValueWithParenthesis() : null
});
continue;
}
var name_2 = getName2(1).toLowerCase();
var data2 = null;
if (selector.charCodeAt(selectorIndex) === 40) {
if (unpackPseudos.has(name_2)) {
if (isQuote(selector.charCodeAt(selectorIndex + 1))) {
throw new Error("Pseudo-selector ".concat(name_2, " cannot be quoted"));
}
data2 = [];
selectorIndex = parseSelector(data2, selector, selectorIndex + 1);
if (selector.charCodeAt(selectorIndex) !== 41) {
throw new Error("Missing closing parenthesis in :".concat(name_2, " (").concat(selector, ")"));
}
selectorIndex += 1;
} else {
data2 = readValueWithParenthesis();
if (stripQuotesFromPseudos.has(name_2)) {
var quot = data2.charCodeAt(0);
if (quot === data2.charCodeAt(data2.length - 1) && isQuote(quot)) {
data2 = data2.slice(1, -1);
}
}
data2 = unescapeCSS(data2);
}
}
tokens.push({ type: types_1.SelectorType.Pseudo, name: name_2, data: data2 });
break;
}
case 44: {
finalizeSubselector();
tokens = [];
stripWhitespace(1);
break;
}
default: {
if (selector.startsWith("/*", selectorIndex)) {
var endIndex = selector.indexOf("*/", selectorIndex + 2);
if (endIndex < 0) {
throw new Error("Comment was not terminated");
}
selectorIndex = endIndex + 2;
if (tokens.length === 0) {
stripWhitespace(0);
}
break;
}
var namespace = null;
var name_3 = undefined;
if (firstChar === 42) {
selectorIndex += 1;
name_3 = "*";
} else if (firstChar === 124) {
name_3 = "";
if (selector.charCodeAt(selectorIndex + 1) === 124) {
addTraversal(types_1.SelectorType.ColumnCombinator);
stripWhitespace(2);
break;
}
} else if (reName.test(selector.slice(selectorIndex))) {
name_3 = getName2(0);
} else {
break loop;
}
if (selector.charCodeAt(selectorIndex) === 124 && selector.charCodeAt(selectorIndex + 1) !== 124) {
namespace = name_3;
if (selector.charCodeAt(selectorIndex + 1) === 42) {
name_3 = "*";
selectorIndex += 2;
} else {
name_3 = getName2(1);
}
}
tokens.push(name_3 === "*" ? { type: types_1.SelectorType.Universal, namespace } : { type: types_1.SelectorType.Tag, name: name_3, namespace });
}
}
}
finalizeSubselector();
return selectorIndex;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.parse = exports.isTraversal = undefined;
var types_1 = require_types();
var reName = /^[^\\#]?(?:\\(?:[\da-f]{1,6}\s?|.)|[\w\-\u00b0-\uFFFF])+/;
var reEscape = /\\([\da-f]{1,6}\s?|(\s)|.)/gi;
var actionTypes = new Map([
[126, types_1.AttributeAction.Element],
[94, types_1.AttributeAction.Start],
[36, types_1.AttributeAction.End],
[42, types_1.AttributeAction.Any],
[33, types_1.AttributeAction.Not],
[124, types_1.AttributeAction.Hyphen]
]);
var unpackPseudos = new Set([
"has",
"not",
"matches",
"is",
"where",
"host",
"host-context"
]);
exports.isTraversal = isTraversal;
var stripQuotesFromPseudos = new Set(["contains", "icontains"]);
exports.parse = parse;
});
// node_modules/css-what/lib/commonjs/stringify.js
var require_stringify = __commonJS((exports) => {
var stringify3 = function(selector) {
return selector.map(function(token) {
return token.map(stringifyToken).join("");
}).join(", ");
};
var stringifyToken = function(token, index, arr) {
switch (token.type) {
case types_1.SelectorType.Child:
return index === 0 ? "> " : " > ";
case types_1.SelectorType.Parent:
return index === 0 ? "< " : " < ";
case types_1.SelectorType.Sibling:
return index === 0 ? "~ " : " ~ ";
case types_1.SelectorType.Adjacent:
return index === 0 ? "+ " : " + ";
case types_1.SelectorType.Descendant:
return " ";
case types_1.SelectorType.ColumnCombinator:
return index === 0 ? "|| " : " || ";
case types_1.SelectorType.Universal:
return token.namespace === "*" && index + 1 < arr.length && "name" in arr[index + 1] ? "" : "".concat(getNamespace(token.namespace), "*");
case types_1.SelectorType.Tag:
return getNamespacedName(token);
case types_1.SelectorType.PseudoElement:
return "::".concat(escapeName(token.name, charsToEscapeInName)).concat(token.data === null ? "" : "(".concat(escapeName(token.data, charsToEscapeInPseudoValue), ")"));
case types_1.SelectorType.Pseudo:
return ":".concat(escapeName(token.name, charsToEscapeInName)).concat(token.data === null ? "" : "(".concat(typeof token.data === "string" ? escapeName(token.data, charsToEscapeInPseudoValue) : stringify3(token.data), ")"));
case types_1.SelectorType.Attribute: {
if (token.name === "id" && token.action === types_1.AttributeAction.Equals && token.ignoreCase === "quirks" && !token.namespace) {
return "#".concat(escapeName(token.value, charsToEscapeInName));
}
if (token.name === "class" && token.action === types_1.AttributeAction.Element && token.ignoreCase === "quirks" && !token.namespace) {
return ".".concat(escapeName(token.value, charsToEscapeInName));
}
var name_1 = getNamespacedName(token);
if (token.action === types_1.AttributeAction.Exists) {
return "[".concat(name_1, "]");
}
return "[".concat(name_1).concat(getActionValue(token.action), "=\"").concat(escapeName(token.value, charsToEscapeInAttributeValue), "\"").concat(token.ignoreCase === null ? "" : token.ignoreCase ? " i" : " s", "]");
}
}
};
var getActionValue = function(action) {
switch (action) {
case types_1.AttributeAction.Equals:
return "";
case types_1.AttributeAction.Element:
return "~";
case types_1.AttributeAction.Start:
return "^";
case types_1.AttributeAction.End:
return "$";
case types_1.AttributeAction.Any:
return "*";
case types_1.AttributeAction.Not:
return "!";
case types_1.AttributeAction.Hyphen:
return "|";
case types_1.AttributeAction.Exists:
throw new Error("Shouldn't be here");
}
};
var getNamespacedName = function(token) {
return "".concat(getNamespace(token.namespace)).concat(escapeName(token.name, charsToEscapeInName));
};
var getNamespace = function(namespace) {
return namespace !== null ? "".concat(namespace === "*" ? "*" : escapeName(namespace, charsToEscapeInName), "|") : "";
};
var escapeName = function(str, charsToEscape) {
var lastIdx = 0;
var ret = "";
for (var i = 0;i < str.length; i++) {
if (charsToEscape.has(str.charCodeAt(i))) {
ret += "".concat(str.slice(lastIdx, i), "\\").concat(str.charAt(i));
lastIdx = i + 1;
}
}
return ret.length > 0 ? ret + str.slice(lastIdx) : str;
};
var __spreadArray = exports && exports.__spreadArray || function(to, from, pack) {
if (pack || arguments.length === 2)
for (var i = 0, l = from.length, ar;i < l; i++) {
if (ar || !(i in from)) {
if (!ar)
ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.stringify = undefined;
var types_1 = require_types();
var attribValChars = ["\\", '"'];
var pseudoValChars = __spreadArray(__spreadArray([], attribValChars, true), ["(", ")"], false);
var charsToEscapeInAttributeValue = new Set(attribValChars.map(function(c) {
return c.charCodeAt(0);
}));
var charsToEscapeInPseudoValue = new Set(pseudoValChars.map(function(c) {
return c.charCodeAt(0);
}));
var charsToEscapeInName = new Set(__spreadArray(__spreadArray([], pseudoValChars, true), [
"~",
"^",
"$",
"*",
"+",
"!",
"|",
":",
"[",
"]",
" ",
"."
], false).map(function(c) {
return c.charCodeAt(0);
}));
exports.stringify = stringify3;
});
// node_modules/css-what/lib/commonjs/index.js
var require_commonjs = __commonJS((exports) => {
var __createBinding = exports && exports.__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 __exportStar = exports && exports.__exportStar || function(m, exports2) {
for (var p in m)
if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports2, p))
__createBinding(exports2, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.stringify = exports.parse = exports.isTraversal = undefined;
__exportStar(require_types(), exports);
var parse_1 = require_parse();
Object.defineProperty(exports, "isTraversal", { enumerable: true, get: function() {
return parse_1.isTraversal;
} });
Object.defineProperty(exports, "parse", { enumerable: true, get: function() {
return parse_1.parse;
} });
var stringify_1 = require_stringify();
Object.defineProperty(exports, "stringify", { enumerable: true, get: function() {
return stringify_1.stringify;
} });
});
// node_modules/boolbase/index.js
var require_boolbase = __commonJS((exports, module) => {
module.exports = {
trueFunc: function trueFunc() {
return true;
},
falseFunc: function falseFunc() {
return false;
}
};
});
// node_modules/safer-buffer/safer.js
var require_safer = __commonJS((exports, module) => {
var buffer = __require("buffer");
var Buffer2 = buffer.Buffer;
var safer = {};
var key;
for (key in buffer) {
if (!buffer.hasOwnProperty(key))
continue;
if (key === "SlowBuffer" || key === "Buffer")
continue;
safer[key] = buffer[key];
}
var Safer = safer.Buffer = {};
for (key in Buffer2) {
if (!Buffer2.hasOwnProperty(key))
continue;
if (key === "allocUnsafe" || key === "allocUnsafeSlow")
continue;
Safer[key] = Buffer2[key];
}
safer.Buffer.prototype = Buffer2.prototype;
if (!Safer.from || Safer.from === Uint8Array.from) {
Safer.from = function(value, encodingOrOffset, length) {
if (typeof value === "number") {
throw new TypeError('The "value" argument must not be of type number. Received type ' + typeof value);
}
if (value && typeof value.length === "undefined") {
throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type " + typeof value);
}
return Buffer2(value, encodingOrOffset, length);
};
}
if (!Safer.alloc) {
Safer.alloc = function(size, fill, encoding) {
if (typeof size !== "number") {
throw new TypeError('The "size" argument must be of type number. Received type ' + typeof size);
}
if (size < 0 || size >= 2 * (1 << 30)) {
throw new RangeError('The value "' + size + '" is invalid for option "size"');
}
var buf = Buffer2(size);
if (!fill || fill.length === 0) {
buf.fill(0);
} else if (typeof encoding === "string") {
buf.fill(fill, encoding);
} else {
buf.fill(fill);
}
return buf;
};
}
if (!safer.kStringMaxLength) {
try {
safer.kStringMaxLength = process.binding("buffer").kStringMaxLength;
} catch (e) {
}
}
if (!safer.constants) {
safer.constants = {
MAX_LENGTH: safer.kMaxLength
};
if (safer.kStringMaxLength) {
safer.constants.MAX_STRING_LENGTH = safer.kStringMaxLength;
}
}
module.exports = safer;
});
// node_modules/iconv-lite/lib/bom-handling.js
var require_bom_handling = __commonJS((exports) => {
var PrependBOMWrapper = function(encoder, options3) {
this.encoder = encoder;
this.addBOM = true;
};
var StripBOMWrapper = function(decoder, options3) {
this.decoder = decoder;
this.pass = false;
this.options = options3 || {};
};
var BOMChar = "\uFEFF";
exports.PrependBOM = PrependBOMWrapper;
PrependBOMWrapper.prototype.write = function(str) {
if (this.addBOM) {
str = BOMChar + str;
this.addBOM = false;
}
return this.encoder.write(str);
};
PrependBOMWrapper.prototype.end = function() {
return this.encoder.end();
};
exports.StripBOM = StripBOMWrapper;
StripBOMWrapper.prototype.write = function(buf) {
var res = this.decoder.write(buf);
if (this.pass || !res)
return res;
if (res[0] === BOMChar) {
res = res.slice(1);
if (typeof this.options.stripBOM === "function")
this.options.stripBOM();
}
this.pass = true;
return res;
};
StripBOMWrapper.prototype.end = function() {
return this.decoder.end();
};
});
// node_modules/iconv-lite/encodings/internal.js
var require_internal = __commonJS((exports, module) => {
var InternalCodec = function(codecOptions, iconv) {
this.enc = codecOptions.encodingName;
this.bomAware = codecOptions.bomAware;
if (this.enc === "base64")
this.encoder = InternalEncoderBase64;
else if (this.enc === "cesu8") {
this.enc = "utf8";
this.encoder = InternalEncoderCesu8;
if (Buffer2.from("eda0bdedb2a9", "hex").toString() !== "\uD83D\uDCA9") {
this.decoder = InternalDecoderCesu8;
this.defaultCharUnicode = iconv.defaultCharUnicode;
}
}
};
var InternalDecoder = function(options3, codec) {
this.decoder = new StringDecoder(codec.enc);
};
var InternalEncoder = function(options3, codec) {
this.enc = codec.enc;
};
var InternalEncoderBase64 = function(options3, codec) {
this.prevStr = "";
};
var InternalEncoderCesu8 = function(options3, codec) {
};
var InternalDecoderCesu8 = function(options3, codec) {
this.acc = 0;
this.contBytes = 0;
this.accBytes = 0;
this.defaultCharUnicode = codec.defaultCharUnicode;
};
var Buffer2 = require_safer().Buffer;
module.exports = {
utf8: { type: "_internal", bomAware: true },
cesu8: { type: "_internal", bomAware: true },
unicode11utf8: "utf8",
ucs2: { type: "_internal", bomAware: true },
utf16le: "ucs2",
binary: { type: "_internal" },
base64: { type: "_internal" },
hex: { type: "_internal" },
_internal: InternalCodec
};
InternalCodec.prototype.encoder = InternalEncoder;
InternalCodec.prototype.decoder = InternalDecoder;
var StringDecoder = __require("string_decoder").StringDecoder;
if (!StringDecoder.prototype.end)
StringDecoder.prototype.end = function() {
};
InternalDecoder.prototype.write = function(buf) {
if (!Buffer2.isBuffer(buf)) {
buf = Buffer2.from(buf);
}
return this.decoder.write(buf);
};
InternalDecoder.prototype.end = function() {
return this.decoder.end();
};
InternalEncoder.prototype.write = function(str) {
return Buffer2.from(str, this.enc);
};
InternalEncoder.prototype.end = function() {
};
InternalEncoderBase64.prototype.write = function(str) {
str = this.prevStr + str;
var completeQuads = str.length - str.length % 4;
this.prevStr = str.slice(completeQuads);
str = str.slice(0, completeQuads);
return Buffer2.from(str, "base64");
};
InternalEncoderBase64.prototype.end = function() {
return Buffer2.from(this.prevStr, "base64");
};
InternalEncoderCesu8.prototype.write = function(str) {
var buf = Buffer2.alloc(str.length * 3), bufIdx = 0;
for (var i = 0;i < str.length; i++) {
var charCode = str.charCodeAt(i);
if (charCode < 128)
buf[bufIdx++] = charCode;
else if (charCode < 2048) {
buf[bufIdx++] = 192 + (charCode >>> 6);
buf[bufIdx++] = 128 + (charCode & 63);
} else {
buf[bufIdx++] = 224 + (charCode >>> 12);
buf[bufIdx++] = 128 + (charCode >>> 6 & 63);
buf[bufIdx++] = 128 + (charCode & 63);
}
}
return buf.slice(0, bufIdx);
};
InternalEncoderCesu8.prototype.end = function() {
};
InternalDecoderCesu8.prototype.write = function(buf) {
var acc = this.acc, contBytes = this.contBytes, accBytes = this.accBytes, res = "";
for (var i = 0;i < buf.length; i++) {
var curByte = buf[i];
if ((curByte & 192) !== 128) {
if (contBytes > 0) {
res += this.defaultCharUnicode;
contBytes = 0;
}
if (curByte < 128) {
res += String.fromCharCode(curByte);
} else if (curByte < 224) {
acc = curByte & 31;
contBytes = 1;
accBytes = 1;
} else if (curByte < 240) {
acc = curByte & 15;
contBytes = 2;
accBytes = 1;
} else {
res += this.defaultCharUnicode;
}
} else {
if (contBytes > 0) {
acc = acc << 6 | curByte & 63;
contBytes--;
accBytes++;
if (contBytes === 0) {
if (accBytes === 2 && acc < 128 && acc > 0)
res += this.defaultCharUnicode;
else if (accBytes === 3 && acc < 2048)
res += this.defaultCharUnicode;
else
res += String.fromCharCode(acc);
}
} else {
res += this.defaultCharUnicode;
}
}
}
this.acc = acc;
this.contBytes = contBytes;
this.accBytes = accBytes;
return res;
};
InternalDecoderCesu8.prototype.end = function() {
var res = 0;
if (this.contBytes > 0)
res += this.defaultCharUnicode;
return res;
};
});
// node_modules/iconv-lite/encodings/utf32.js
var require_utf32 = __commonJS((exports) => {
var Utf32Codec = function(codecOptions, iconv) {
this.iconv = iconv;
this.bomAware = true;
this.isLE = codecOptions.isLE;
};
var Utf32Encoder = function(options3, codec) {
this.isLE = codec.isLE;
this.highSurrogate = 0;
};
var Utf32Decoder = function(options3, codec) {
this.isLE = codec.isLE;
this.badChar = codec.iconv.defaultCharUnicode.charCodeAt(0);
this.overflow = [];
};
var _writeCodepoint = function(dst, offset, codepoint, badChar) {
if (codepoint < 0 || codepoint > 1114111) {
codepoint = badChar;
}
if (codepoint >= 65536) {
codepoint -= 65536;
var high = 55296 | codepoint >> 10;
dst[offset++] = high & 255;
dst[offset++] = high >> 8;
var codepoint = 56320 | codepoint & 1023;
}
dst[offset++] = codepoint & 255;
dst[offset++] = codepoint >> 8;
return offset;
};
var Utf32AutoCodec = function(options3, iconv) {
this.iconv = iconv;
};
var Utf32AutoEncoder = function(options3, codec) {
options3 = options3 || {};
if (options3.addBOM === undefined)
options3.addBOM = true;
this.encoder = codec.iconv.getEncoder(options3.defaultEncoding || "utf-32le", options3);
};
var Utf32AutoDecoder = function(options3, codec) {
this.decoder = null;
this.initialBufs = [];
this.initialBufsLen = 0;
this.options = options3 || {};
this.iconv = codec.iconv;
};
var detectEncoding = function(bufs, defaultEncoding) {
var b = [];
var charsProcessed = 0;
var invalidLE = 0, invalidBE = 0;
var bmpCharsLE = 0, bmpCharsBE = 0;
outer_loop:
for (var i = 0;i < bufs.length; i++) {
var buf = bufs[i];
for (var j = 0;j < buf.length; j++) {
b.push(buf[j]);
if (b.length === 4) {
if (charsProcessed === 0) {
if (b[0] === 255 && b[1] === 254 && b[2] === 0 && b[3] === 0) {
return "utf-32le";
}
if (b[0] === 0 && b[1] === 0 && b[2] === 254 && b[3] === 255) {
return "utf-32be";
}
}
if (b[0] !== 0 || b[1] > 16)
invalidBE++;
if (b[3] !== 0 || b[2] > 16)
invalidLE++;
if (b[0] === 0 && b[1] === 0 && (b[2] !== 0 || b[3] !== 0))
bmpCharsBE++;
if ((b[0] !== 0 || b[1] !== 0) && b[2] === 0 && b[3] === 0)
bmpCharsLE++;
b.length = 0;
charsProcessed++;
if (charsProcessed >= 100) {
break outer_loop;
}
}
}
}
if (bmpCharsBE - invalidBE > bmpCharsLE - invalidLE)
return "utf-32be";
if (bmpCharsBE - invalidBE < bmpCharsLE - invalidLE)
return "utf-32le";
return defaultEncoding || "utf-32le";
};
var Buffer2 = require_safer().Buffer;
exports._utf32 = Utf32Codec;
exports.utf32le = { type: "_utf32", isLE: true };
exports.utf32be = { type: "_utf32", isLE: false };
exports.ucs4le = "utf32le";
exports.ucs4be = "utf32be";
Utf32Codec.prototype.encoder = Utf32Encoder;
Utf32Codec.prototype.decoder = Utf32Decoder;
Utf32Encoder.prototype.write = function(str) {
var src = Buffer2.from(str, "ucs2");
var dst = Buffer2.alloc(src.length * 2);
var write32 = this.isLE ? dst.writeUInt32LE : dst.writeUInt32BE;
var offset = 0;
for (var i = 0;i < src.length; i += 2) {
var code = src.readUInt16LE(i);
var isHighSurrogate = 55296 <= code && code < 56320;
var isLowSurrogate = 56320 <= code && code < 57344;
if (this.highSurrogate) {
if (isHighSurrogate || !isLowSurrogate) {
write32.call(dst, this.highSurrogate, offset);
offset += 4;
} else {
var codepoint = (this.highSurrogate - 55296 << 10 | code - 56320) + 65536;
write32.call(dst, codepoint, offset);
offset += 4;
this.highSurrogate = 0;
continue;
}
}
if (isHighSurrogate)
this.highSurrogate = code;
else {
write32.call(dst, code, offset);
offset += 4;
this.highSurrogate = 0;
}
}
if (offset < dst.length)
dst = dst.slice(0, offset);
return dst;
};
Utf32Encoder.prototype.end = function() {
if (!this.highSurrogate)
return;
var buf = Buffer2.alloc(4);
if (this.isLE)
buf.writeUInt32LE(this.highSurrogate, 0);
else
buf.writeUInt32BE(this.highSurrogate, 0);
this.highSurrogate = 0;
return buf;
};
Utf32Decoder.prototype.write = function(src) {
if (src.length === 0)
return "";
var i = 0;
var codepoint = 0;
var dst = Buffer2.alloc(src.length + 4);
var offset = 0;
var isLE = this.isLE;
var overflow = this.overflow;
var badChar = this.badChar;
if (overflow.length > 0) {
for (;i < src.length && overflow.length < 4; i++)
overflow.push(src[i]);
if (overflow.length === 4) {
if (isLE) {
codepoint = overflow[i] | overflow[i + 1] << 8 | overflow[i + 2] << 16 | overflow[i + 3] << 24;
} else {
codepoint = overflow[i + 3] | overflow[i + 2] << 8 | overflow[i + 1] << 16 | overflow[i] << 24;
}
overflow.length = 0;
offset = _writeCodepoint(dst, offset, codepoint, badChar);
}
}
for (;i < src.length - 3; i += 4) {
if (isLE) {
codepoint = src[i] | src[i + 1] << 8 | src[i + 2] << 16 | src[i + 3] << 24;
} else {
codepoint = src[i + 3] | src[i + 2] << 8 | src[i + 1] << 16 | src[i] << 24;
}
offset = _writeCodepoint(dst, offset, codepoint, badChar);
}
for (;i < src.length; i++) {
overflow.push(src[i]);
}
return dst.slice(0, offset).toString("ucs2");
};
Utf32Decoder.prototype.end = function() {
this.overflow.length = 0;
};
exports.utf32 = Utf32AutoCodec;
exports.ucs4 = "utf32";
Utf32AutoCodec.prototype.encoder = Utf32AutoEncoder;
Utf32AutoCodec.prototype.decoder = Utf32AutoDecoder;
Utf32AutoEncoder.prototype.write = function(str) {
return this.encoder.write(str);
};
Utf32AutoEncoder.prototype.end = function() {
return this.encoder.end();
};
Utf32AutoDecoder.prototype.write = function(buf) {
if (!this.decoder) {
this.initialBufs.push(buf);
this.initialBufsLen += buf.length;
if (this.initialBufsLen < 32)
return "";
var encoding = detectEncoding(this.initialBufs, this.options.defaultEncoding);
this.decoder = this.iconv.getDecoder(encoding, this.options);
var resStr = "";
for (var i = 0;i < this.initialBufs.length; i++)
resStr += this.decoder.write(this.initialBufs[i]);
this.initialBufs.length = this.initialBufsLen = 0;
return resStr;
}
return this.decoder.write(buf);
};
Utf32AutoDecoder.prototype.end = function() {
if (!this.decoder) {
var encoding = detectEncoding(this.initialBufs, this.options.defaultEncoding);
this.decoder = this.iconv.getDecoder(encoding, this.options);
var resStr = "";
for (var i = 0;i < this.initialBufs.length; i++)
resStr += this.decoder.write(this.initialBufs[i]);
var trail = this.decoder.end();
if (trail)
resStr += trail;
this.initialBufs.length = this.initialBufsLen = 0;
return resStr;
}
return this.decoder.end();
};
});
// node_modules/iconv-lite/encodings/utf16.js
var require_utf16 = __commonJS((exports) => {
var Utf16BECodec = function() {
};
var Utf16BEEncoder = function() {
};
var Utf16BEDecoder = function() {
this.overflowByte = -1;
};
var Utf16Codec = function(codecOptions, iconv) {
this.iconv = iconv;
};
var Utf16Encoder = function(options3, codec) {
options3 = options3 || {};
if (options3.addBOM === undefined)
options3.addBOM = true;
this.encoder = codec.iconv.getEncoder("utf-16le", options3);
};
var Utf16Decoder = function(options3, codec) {
this.decoder = null;
this.initialBufs = [];
this.initialBufsLen = 0;
this.options = options3 || {};
this.iconv = codec.iconv;
};
var detectEncoding = function(bufs, defaultEncoding) {
var b = [];
var charsProcessed = 0;
var asciiCharsLE = 0, asciiCharsBE = 0;
outer_loop:
for (var i = 0;i < bufs.length; i++) {
var buf = bufs[i];
for (var j = 0;j < buf.length; j++) {
b.push(buf[j]);
if (b.length === 2) {
if (charsProcessed === 0) {
if (b[0] === 255 && b[1] === 254)
return "utf-16le";
if (b[0] === 254 && b[1] === 255)
return "utf-16be";
}
if (b[0] === 0 && b[1] !== 0)
asciiCharsBE++;
if (b[0] !== 0 && b[1] === 0)
asciiCharsLE++;
b.length = 0;
charsProcessed++;
if (charsProcessed >= 100) {
break outer_loop;
}
}
}
}
if (asciiCharsBE > asciiCharsLE)
return "utf-16be";
if (asciiCharsBE < asciiCharsLE)
return "utf-16le";
return defaultEncoding || "utf-16le";
};
var Buffer2 = require_safer().Buffer;
exports.utf16be = Utf16BECodec;
Utf16BECodec.prototype.encoder = Utf16BEEncoder;
Utf16BECodec.prototype.decoder = Utf16BEDecoder;
Utf16BECodec.prototype.bomAware = true;
Utf16BEEncoder.prototype.write = function(str) {
var buf = Buffer2.from(str, "ucs2");
for (var i = 0;i < buf.length; i += 2) {
var tmp = buf[i];
buf[i] = buf[i + 1];
buf[i + 1] = tmp;
}
return buf;
};
Utf16BEEncoder.prototype.end = function() {
};
Utf16BEDecoder.prototype.write = function(buf) {
if (buf.length == 0)
return "";
var buf2 = Buffer2.alloc(buf.length + 1), i = 0, j = 0;
if (this.overflowByte !== -1) {
buf2[0] = buf[0];
buf2[1] = this.overflowByte;
i = 1;
j = 2;
}
for (;i < buf.length - 1; i += 2, j += 2) {
buf2[j] = buf[i + 1];
buf2[j + 1] = buf[i];
}
this.overflowByte = i == buf.length - 1 ? buf[buf.length - 1] : -1;
return buf2.slice(0, j).toString("ucs2");
};
Utf16BEDecoder.prototype.end = function() {
this.overflowByte = -1;
};
exports.utf16 = Utf16Codec;
Utf16Codec.prototype.encoder = Utf16Encoder;
Utf16Codec.prototype.decoder = Utf16Decoder;
Utf16Encoder.prototype.write = function(str) {
return this.encoder.write(str);
};
Utf16Encoder.prototype.end = function() {
return this.encoder.end();
};
Utf16Decoder.prototype.write = function(buf) {
if (!this.decoder) {
this.initialBufs.push(buf);
this.initialBufsLen += buf.length;
if (this.initialBufsLen < 16)
return "";
var encoding = detectEncoding(this.initialBufs, this.options.defaultEncoding);
this.decoder = this.iconv.getDecoder(encoding, this.options);
var resStr = "";
for (var i = 0;i < this.initialBufs.length; i++)
resStr += this.decoder.write(this.initialBufs[i]);
this.initialBufs.length = this.initialBufsLen = 0;
return resStr;
}
return this.decoder.write(buf);
};
Utf16Decoder.prototype.end = function() {
if (!this.decoder) {
var encoding = detectEncoding(this.initialBufs, this.options.defaultEncoding);
this.decoder = this.iconv.getDecoder(encoding, this.options);
var resStr = "";
for (var i = 0;i < this.initialBufs.length; i++)
resStr += this.decoder.write(this.initialBufs[i]);
var trail = this.decoder.end();
if (trail)
resStr += trail;
this.initialBufs.length = this.initialBufsLen = 0;
return resStr;
}
return this.decoder.end();
};
});
// node_modules/iconv-lite/encodings/utf7.js
var require_utf7 = __commonJS((exports) => {
var Utf7Codec = function(codecOptions, iconv) {
this.iconv = iconv;
};
var Utf7Encoder = function(options3, codec) {
this.iconv = codec.iconv;
};
var Utf7Decoder = function(options3, codec) {
this.iconv = codec.iconv;
this.inBase64 = false;
this.base64Accum = "";
};
var Utf7IMAPCodec = function(codecOptions, iconv) {
this.iconv = iconv;
};
var Utf7IMAPEncoder = function(options3, codec) {
this.iconv = codec.iconv;
this.inBase64 = false;
this.base64Accum = Buffer2.alloc(6);
this.base64AccumIdx = 0;
};
var Utf7IMAPDecoder = function(options3, codec) {
this.iconv = codec.iconv;
this.inBase64 = false;
this.base64Accum = "";
};
var Buffer2 = require_safer().Buffer;
exports.utf7 = Utf7Codec;
exports.unicode11utf7 = "utf7";
Utf7Codec.prototype.encoder = Utf7Encoder;
Utf7Codec.prototype.decoder = Utf7Decoder;
Utf7Codec.prototype.bomAware = true;
var nonDirectChars = /[^A-Za-z0-9'\(\),-\.\/:\? \n\r\t]+/g;
Utf7Encoder.prototype.write = function(str) {
return Buffer2.from(str.replace(nonDirectChars, function(chunk) {
return "+" + (chunk === "+" ? "" : this.iconv.encode(chunk, "utf16-be").toString("base64").replace(/=+$/, "")) + "-";
}.bind(this)));
};
Utf7Encoder.prototype.end = function() {
};
var base64Regex = /[A-Za-z0-9\/+]/;
var base64Chars = [];
for (i = 0;i < 256; i++)
base64Chars[i] = base64Regex.test(String.fromCharCode(i));
var i;
var plusChar = "+".charCodeAt(0);
var minusChar = "-".charCodeAt(0);
var andChar = "&".charCodeAt(0);
Utf7Decoder.prototype.write = function(buf) {
var res = "", lastI = 0, inBase64 = this.inBase64, base64Accum = this.base64Accum;
for (var i2 = 0;i2 < buf.length; i2++) {
if (!inBase64) {
if (buf[i2] == plusChar) {
res += this.iconv.decode(buf.slice(lastI, i2), "ascii");
lastI = i2 + 1;
inBase64 = true;
}
} else {
if (!base64Chars[buf[i2]]) {
if (i2 == lastI && buf[i2] == minusChar) {
res += "+";
} else {
var b64str = base64Accum + this.iconv.decode(buf.slice(lastI, i2), "ascii");
res += this.iconv.decode(Buffer2.from(b64str, "base64"), "utf16-be");
}
if (buf[i2] != minusChar)
i2--;
lastI = i2 + 1;
inBase64 = false;
base64Accum = "";
}
}
}
if (!inBase64) {
res += this.iconv.decode(buf.slice(lastI), "ascii");
} else {
var b64str = base64Accum + this.iconv.decode(buf.slice(lastI), "ascii");
var canBeDecoded = b64str.length - b64str.length % 8;
base64Accum = b64str.slice(canBeDecoded);
b64str = b64str.slice(0, canBeDecoded);
res += this.iconv.decode(Buffer2.from(b64str, "base64"), "utf16-be");
}
this.inBase64 = inBase64;
this.base64Accum = base64Accum;
return res;
};
Utf7Decoder.prototype.end = function() {
var res = "";
if (this.inBase64 && this.base64Accum.length > 0)
res = this.iconv.decode(Buffer2.from(this.base64Accum, "base64"), "utf16-be");
this.inBase64 = false;
this.base64Accum = "";
return res;
};
exports.utf7imap = Utf7IMAPCodec;
Utf7IMAPCodec.prototype.encoder = Utf7IMAPEncoder;
Utf7IMAPCodec.prototype.decoder = Utf7IMAPDecoder;
Utf7IMAPCodec.prototype.bomAware = true;
Utf7IMAPEncoder.prototype.write = function(str) {
var inBase64 = this.inBase64, base64Accum = this.base64Accum, base64AccumIdx = this.base64AccumIdx, buf = Buffer2.alloc(str.length * 5 + 10), bufIdx = 0;
for (var i2 = 0;i2 < str.length; i2++) {
var uChar = str.charCodeAt(i2);
if (32 <= uChar && uChar <= 126) {
if (inBase64) {
if (base64AccumIdx > 0) {
bufIdx += buf.write(base64Accum.slice(0, base64AccumIdx).toString("base64").replace(/\//g, ",").replace(/=+$/, ""), bufIdx);
base64AccumIdx = 0;
}
buf[bufIdx++] = minusChar;
inBase64 = false;
}
if (!inBase64) {
buf[bufIdx++] = uChar;
if (uChar === andChar)
buf[bufIdx++] = minusChar;
}
} else {
if (!inBase64) {
buf[bufIdx++] = andChar;
inBase64 = true;
}
if (inBase64) {
base64Accum[base64AccumIdx++] = uChar >> 8;
base64Accum[base64AccumIdx++] = uChar & 255;
if (base64AccumIdx == base64Accum.length) {
bufIdx += buf.write(base64Accum.toString("base64").replace(/\//g, ","), bufIdx);
base64AccumIdx = 0;
}
}
}
}
this.inBase64 = inBase64;
this.base64AccumIdx = base64AccumIdx;
return buf.slice(0, bufIdx);
};
Utf7IMAPEncoder.prototype.end = function() {
var buf = Buffer2.alloc(10), bufIdx = 0;
if (this.inBase64) {
if (this.base64AccumIdx > 0) {
bufIdx += buf.write(this.base64Accum.slice(0, this.base64AccumIdx).toString("base64").replace(/\//g, ",").replace(/=+$/, ""), bufIdx);
this.base64AccumIdx = 0;
}
buf[bufIdx++] = minusChar;
this.inBase64 = false;
}
return buf.slice(0, bufIdx);
};
var base64IMAPChars = base64Chars.slice();
base64IMAPChars[",".charCodeAt(0)] = true;
Utf7IMAPDecoder.prototype.write = function(buf) {
var res = "", lastI = 0, inBase64 = this.inBase64, base64Accum = this.base64Accum;
for (var i2 = 0;i2 < buf.length; i2++) {
if (!inBase64) {
if (buf[i2] == andChar) {
res += this.iconv.decode(buf.slice(lastI, i2), "ascii");
lastI = i2 + 1;
inBase64 = true;
}
} else {
if (!base64IMAPChars[buf[i2]]) {
if (i2 == lastI && buf[i2] == minusChar) {
res += "&";
} else {
var b64str = base64Accum + this.iconv.decode(buf.slice(lastI, i2), "ascii").replace(/,/g, "/");
res += this.iconv.decode(Buffer2.from(b64str, "base64"), "utf16-be");
}
if (buf[i2] != minusChar)
i2--;
lastI = i2 + 1;
inBase64 = false;
base64Accum = "";
}
}
}
if (!inBase64) {
res += this.iconv.decode(buf.slice(lastI), "ascii");
} else {
var b64str = base64Accum + this.iconv.decode(buf.slice(lastI), "ascii").replace(/,/g, "/");
var canBeDecoded = b64str.length - b64str.length % 8;
base64Accum = b64str.slice(canBeDecoded);
b64str = b64str.slice(0, canBeDecoded);
res += this.iconv.decode(Buffer2.from(b64str, "base64"), "utf16-be");
}
this.inBase64 = inBase64;
this.base64Accum = base64Accum;
return res;
};
Utf7IMAPDecoder.prototype.end = function() {
var res = "";
if (this.inBase64 && this.base64Accum.length > 0)
res = this.iconv.decode(Buffer2.from(this.base64Accum, "base64"), "utf16-be");
this.inBase64 = false;
this.base64Accum = "";
return res;
};
});
// node_modules/iconv-lite/encodings/sbcs-codec.js
var require_sbcs_codec = __commonJS((exports) => {
var SBCSCodec = function(codecOptions, iconv) {
if (!codecOptions)
throw new Error("SBCS codec is called without the data.");
if (!codecOptions.chars || codecOptions.chars.length !== 128 && codecOptions.chars.length !== 256)
throw new Error("Encoding '" + codecOptions.type + "' has incorrect 'chars' (must be of len 128 or 256)");
if (codecOptions.chars.length === 128) {
var asciiString = "";
for (var i = 0;i < 128; i++)
asciiString += String.fromCharCode(i);
codecOptions.chars = asciiString + codecOptions.chars;
}
this.decodeBuf = Buffer2.from(codecOptions.chars, "ucs2");
var encodeBuf = Buffer2.alloc(65536, iconv.defaultCharSingleByte.charCodeAt(0));
for (var i = 0;i < codecOptions.chars.length; i++)
encodeBuf[codecOptions.chars.charCodeAt(i)] = i;
this.encodeBuf = encodeBuf;
};
var SBCSEncoder = function(options3, codec) {
this.encodeBuf = codec.encodeBuf;
};
var SBCSDecoder = function(options3, codec) {
this.decodeBuf = codec.decodeBuf;
};
var Buffer2 = re