1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.htmlEncode = htmlEncode;
|
7 | exports.launcher = launcher;
|
8 | exports.pathRelativeBase = pathRelativeBase;
|
9 | exports.pathRelativeBaseMatch = pathRelativeBaseMatch;
|
10 | exports.trimDotSlash = trimDotSlash;
|
11 | exports.trimExtension = trimExtension;
|
12 | var _nodeZlib = require("node:zlib");
|
13 | var _launchers = require("./launchers.js");
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | function htmlEncode(s, dq = false, sq = false) {
|
23 | s = s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
24 | if (dq) {
|
25 | s = s.replace(/"/g, '"');
|
26 | }
|
27 | if (sq) {
|
28 | s = s.replace(/'/g, ''');
|
29 | }
|
30 | return s;
|
31 | }
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | function trimDotSlash(path) {
|
40 | return path.replace(/^(\.\/)+/, '');
|
41 | }
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 | function pathRelativeBase(path, start, nocase = false) {
|
52 | const p = trimDotSlash(nocase ? path.toLowerCase() : path);
|
53 | const s = trimDotSlash(nocase ? start.toLowerCase() : start);
|
54 | if (p === s) {
|
55 | return '';
|
56 | }
|
57 | if (p.startsWith(`${s}/`)) {
|
58 | return path.substring(s.length + 1);
|
59 | }
|
60 | return null;
|
61 | }
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 | function pathRelativeBaseMatch(path, start, nocase = false) {
|
72 | return pathRelativeBase(path, start, nocase) !== null;
|
73 | }
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 | function trimExtension(path, ext, nocase = false) {
|
84 | const p = nocase ? path.toLowerCase() : path;
|
85 | const e = nocase ? ext.toLowerCase() : ext;
|
86 | return p.endsWith(e) ? path.substring(0, p.length - e.length) : path;
|
87 | }
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 | async function launcher(id) {
|
96 | const b64 = _launchers.LAUNCHERS[id];
|
97 | if (typeof b64 !== 'string') {
|
98 | throw new Error(`Invalid launcher id: ${id}`);
|
99 | }
|
100 | return new Promise((resolve, reject) => {
|
101 | (0, _nodeZlib.inflateRaw)(Buffer.from(b64, 'base64'), (err, data) => {
|
102 | if (err) {
|
103 | reject(err);
|
104 | return;
|
105 | }
|
106 | resolve(new Uint8Array(data.buffer, data.byteOffset, data.byteLength));
|
107 | });
|
108 | });
|
109 | }
|
110 |
|
\ | No newline at end of file |