@isopodlabs/vscode_utils 0.0.2 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/codicon.ttf +0 -0
- package/dist/debug.d.ts +130 -0
- package/dist/debug.js +276 -0
- package/dist/jsx-runtime.d.ts +53 -0
- package/dist/jsx-runtime.js +618 -0
- package/package.json +8 -2
- package/dist/utils.d.ts +0 -91
- package/dist/utils.js +0 -430
package/dist/utils.d.ts
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
export declare class Lazy<T> {
|
|
2
|
-
private factory;
|
|
3
|
-
private _value;
|
|
4
|
-
constructor(factory: () => T);
|
|
5
|
-
get value(): T;
|
|
6
|
-
}
|
|
7
|
-
export declare class AsyncLazy<T> {
|
|
8
|
-
private factory;
|
|
9
|
-
private _value;
|
|
10
|
-
constructor(factory: () => Promise<T>);
|
|
11
|
-
get value(): (T & {}) | null;
|
|
12
|
-
}
|
|
13
|
-
export declare class CallCombiner0 {
|
|
14
|
-
private timeout;
|
|
15
|
-
combine(delay: number, func: () => void): void;
|
|
16
|
-
pending(): boolean;
|
|
17
|
-
}
|
|
18
|
-
export declare class CallCombiner extends CallCombiner0 {
|
|
19
|
-
private func;
|
|
20
|
-
private delay;
|
|
21
|
-
constructor(func: () => void, delay: number);
|
|
22
|
-
trigger(): void;
|
|
23
|
-
}
|
|
24
|
-
export declare function makeCache<T>(load: (key: string) => T): {
|
|
25
|
-
get: (fullpath: string) => T;
|
|
26
|
-
remove: (fullpath: string) => void;
|
|
27
|
-
};
|
|
28
|
-
export declare function compare<T>(a: T, b: T): number;
|
|
29
|
-
export declare function reverse_compare<T>(a: T, b: T): number;
|
|
30
|
-
export declare function reverse<T, R>(func: (a: T, b: T) => R): (a: T, b: T) => R;
|
|
31
|
-
export declare function merge(...list: Record<string, any>[]): Record<string, any>;
|
|
32
|
-
type PartitionIndex<U> = U extends boolean ? 'true' | 'false' : U;
|
|
33
|
-
export declare function partition<T, U extends keyof any | boolean>(array: Iterable<T>, func: (v: T) => U): Record<PartitionIndex<U>, T[]>;
|
|
34
|
-
export declare function isEmpty(obj: object): boolean;
|
|
35
|
-
export declare function clone<T extends object>(obj: T): T;
|
|
36
|
-
export declare function lowerBound<T>(array: T[], value: T, func: (a: T, b: T, i: number) => boolean): number;
|
|
37
|
-
export declare function argmin<T>(array: T[], fn?: (i: T) => number): number;
|
|
38
|
-
type Constructor<T, D, O = void> = new (arg: T, opt: O) => D;
|
|
39
|
-
type Factory<T, D, O = void> = (arg: T, opt: O) => D;
|
|
40
|
-
export type ClassOrFactory<T, D, O = void> = Constructor<T, D, O> | Factory<T, D, O>;
|
|
41
|
-
export declare function make<T, D, O>(maker: ClassOrFactory<T, D, O>, arg: T, opt?: O): D;
|
|
42
|
-
export type SpreadType<T> = T extends Iterable<infer U> ? U[] : never;
|
|
43
|
-
export declare function arrayAppend<T, U extends Iterable<T>>(array: T[], items: U): void;
|
|
44
|
-
export declare function arrayRemove<T>(array: T[], item: T): boolean;
|
|
45
|
-
export declare function arrayCompare<T>(arr1: T[], arr2: T[]): number;
|
|
46
|
-
export declare function arrayEqual<T>(arr1: T[], arr2: T[]): boolean;
|
|
47
|
-
export declare function arrayRotate<T>(array: T[], start: number, end: number, shift: number): void;
|
|
48
|
-
export declare function arrayReverse<T>(array: T[], start: number, end: number): void;
|
|
49
|
-
export declare function array_make<T>(n: number, constructor: new () => T): T[];
|
|
50
|
-
export declare function eachIterable<T>(iterable: Iterable<T> | undefined, func: (v: T, i: number) => void): void;
|
|
51
|
-
export declare function findIterable<T>(iterable: Iterable<T> | undefined, func: (v: T) => boolean): T | undefined;
|
|
52
|
-
export declare function mapIterable<T, U>(iterable: Iterable<T> | undefined, func: (v: T, i: number) => U): U[];
|
|
53
|
-
export declare function asyncMap<T, U>(iterable: Iterable<T> | undefined, func: (v: T, i: number) => Promise<U>): Promise<U[]>;
|
|
54
|
-
export declare function asyncReduce<T, U>(array: T[], func: (acc: U, v: T, i: number, array: T[]) => Promise<U>, initialValue: U): Promise<U>;
|
|
55
|
-
export declare function parallel(...fns: (() => any)[]): Promise<any[]>;
|
|
56
|
-
export declare function serial(...fns: (() => any)[]): Promise<any[]>;
|
|
57
|
-
export declare function filterIterable<T>(iterable: Iterable<T>, func: (v: T, i: number) => boolean): T[];
|
|
58
|
-
export declare function asyncFilter<T>(iterable: Iterable<T>, func: (v: T) => Promise<boolean>): Promise<T[]>;
|
|
59
|
-
export declare function mapObject<T, U>(obj: Record<string, T>, func: (x: [k: string, v: T]) => [k: string, v: U]): Record<string, U>;
|
|
60
|
-
export declare function filterObject<T>(obj: Record<string, T>, func: (x: [k: string, v: T]) => boolean): Record<string, T>;
|
|
61
|
-
export declare function firstOf(value: string, find: string): number;
|
|
62
|
-
export declare function lastOf(value: string, find: string): number;
|
|
63
|
-
export declare function splitFirstOf(value: string, find: string): (string | undefined)[];
|
|
64
|
-
export declare function splitLastOf(value: string, find: string): (string | undefined)[];
|
|
65
|
-
export declare function trim0(value: string): string;
|
|
66
|
-
export declare function replace(value: string, re: RegExp, process: (match: RegExpExecArray) => string): string;
|
|
67
|
-
export declare function async_replace(value: string, re: RegExp, process: (match: RegExpExecArray) => Promise<string>): Promise<string>;
|
|
68
|
-
export declare function replace_back(value: string, re: RegExp, process: (match: RegExpExecArray, right: string) => string): string;
|
|
69
|
-
export declare function async_replace_back(value: string, re: RegExp, process: (match: RegExpExecArray, right: string) => Promise<string>): Promise<string>;
|
|
70
|
-
export declare function splitEvery(s: string, n: number): string[];
|
|
71
|
-
export declare function tag(strings: TemplateStringsArray, ...keys: any[]): (...values: any[]) => string;
|
|
72
|
-
export declare function stringCode(s: string): number;
|
|
73
|
-
export declare function stringCodeBig(s: string): bigint;
|
|
74
|
-
export declare function previousChar(str: string, pos: number): string;
|
|
75
|
-
export declare function hasCustomToString(value: any): boolean;
|
|
76
|
-
export declare class StringParser {
|
|
77
|
-
subject: string;
|
|
78
|
-
pos: number;
|
|
79
|
-
constructor(subject: string, pos?: number);
|
|
80
|
-
remaining(): number;
|
|
81
|
-
remainder(): string;
|
|
82
|
-
processed(): string;
|
|
83
|
-
peek(): string;
|
|
84
|
-
peekn(n: number): string;
|
|
85
|
-
get(n: number): string;
|
|
86
|
-
skip(c: string): boolean;
|
|
87
|
-
expect(c: string): void;
|
|
88
|
-
match(re: RegExp): string | undefined;
|
|
89
|
-
exec(re: RegExp): RegExpExecArray | undefined;
|
|
90
|
-
}
|
|
91
|
-
export {};
|
package/dist/utils.js
DELETED
|
@@ -1,430 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.StringParser = exports.CallCombiner = exports.CallCombiner0 = exports.AsyncLazy = exports.Lazy = void 0;
|
|
4
|
-
exports.makeCache = makeCache;
|
|
5
|
-
exports.compare = compare;
|
|
6
|
-
exports.reverse_compare = reverse_compare;
|
|
7
|
-
exports.reverse = reverse;
|
|
8
|
-
exports.merge = merge;
|
|
9
|
-
exports.partition = partition;
|
|
10
|
-
exports.isEmpty = isEmpty;
|
|
11
|
-
exports.clone = clone;
|
|
12
|
-
exports.lowerBound = lowerBound;
|
|
13
|
-
exports.argmin = argmin;
|
|
14
|
-
exports.make = make;
|
|
15
|
-
exports.arrayAppend = arrayAppend;
|
|
16
|
-
exports.arrayRemove = arrayRemove;
|
|
17
|
-
exports.arrayCompare = arrayCompare;
|
|
18
|
-
exports.arrayEqual = arrayEqual;
|
|
19
|
-
exports.arrayRotate = arrayRotate;
|
|
20
|
-
exports.arrayReverse = arrayReverse;
|
|
21
|
-
exports.array_make = array_make;
|
|
22
|
-
exports.eachIterable = eachIterable;
|
|
23
|
-
exports.findIterable = findIterable;
|
|
24
|
-
exports.mapIterable = mapIterable;
|
|
25
|
-
exports.asyncMap = asyncMap;
|
|
26
|
-
exports.asyncReduce = asyncReduce;
|
|
27
|
-
exports.parallel = parallel;
|
|
28
|
-
exports.serial = serial;
|
|
29
|
-
exports.filterIterable = filterIterable;
|
|
30
|
-
exports.asyncFilter = asyncFilter;
|
|
31
|
-
exports.mapObject = mapObject;
|
|
32
|
-
exports.filterObject = filterObject;
|
|
33
|
-
exports.firstOf = firstOf;
|
|
34
|
-
exports.lastOf = lastOf;
|
|
35
|
-
exports.splitFirstOf = splitFirstOf;
|
|
36
|
-
exports.splitLastOf = splitLastOf;
|
|
37
|
-
exports.trim0 = trim0;
|
|
38
|
-
exports.replace = replace;
|
|
39
|
-
exports.async_replace = async_replace;
|
|
40
|
-
exports.replace_back = replace_back;
|
|
41
|
-
exports.async_replace_back = async_replace_back;
|
|
42
|
-
exports.splitEvery = splitEvery;
|
|
43
|
-
exports.tag = tag;
|
|
44
|
-
exports.stringCode = stringCode;
|
|
45
|
-
exports.stringCodeBig = stringCodeBig;
|
|
46
|
-
exports.previousChar = previousChar;
|
|
47
|
-
exports.hasCustomToString = hasCustomToString;
|
|
48
|
-
class Lazy {
|
|
49
|
-
factory;
|
|
50
|
-
_value;
|
|
51
|
-
constructor(factory) {
|
|
52
|
-
this.factory = factory;
|
|
53
|
-
}
|
|
54
|
-
get value() {
|
|
55
|
-
if (this._value === undefined)
|
|
56
|
-
this._value = this.factory();
|
|
57
|
-
return this._value;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
exports.Lazy = Lazy;
|
|
61
|
-
class AsyncLazy {
|
|
62
|
-
factory;
|
|
63
|
-
_value;
|
|
64
|
-
constructor(factory) {
|
|
65
|
-
this.factory = factory;
|
|
66
|
-
}
|
|
67
|
-
get value() {
|
|
68
|
-
if (this._value === undefined) {
|
|
69
|
-
this._value = null;
|
|
70
|
-
this.factory().then(v => this._value = v);
|
|
71
|
-
}
|
|
72
|
-
return this._value;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
exports.AsyncLazy = AsyncLazy;
|
|
76
|
-
class CallCombiner0 {
|
|
77
|
-
timeout = null;
|
|
78
|
-
combine(delay, func) {
|
|
79
|
-
if (this.timeout)
|
|
80
|
-
clearTimeout(this.timeout);
|
|
81
|
-
this.timeout = setTimeout(() => {
|
|
82
|
-
this.timeout = null;
|
|
83
|
-
func();
|
|
84
|
-
}, delay);
|
|
85
|
-
}
|
|
86
|
-
pending() {
|
|
87
|
-
return !!this.timeout;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
exports.CallCombiner0 = CallCombiner0;
|
|
91
|
-
class CallCombiner extends CallCombiner0 {
|
|
92
|
-
func;
|
|
93
|
-
delay;
|
|
94
|
-
constructor(func, delay) {
|
|
95
|
-
super();
|
|
96
|
-
this.func = func;
|
|
97
|
-
this.delay = delay;
|
|
98
|
-
}
|
|
99
|
-
trigger() {
|
|
100
|
-
super.combine(this.delay, this.func);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
exports.CallCombiner = CallCombiner;
|
|
104
|
-
function makeCache(load) {
|
|
105
|
-
const cache = {};
|
|
106
|
-
return {
|
|
107
|
-
get: (fullpath) => {
|
|
108
|
-
if (!cache[fullpath])
|
|
109
|
-
cache[fullpath] = load(fullpath);
|
|
110
|
-
return cache[fullpath];
|
|
111
|
-
},
|
|
112
|
-
remove: (fullpath) => {
|
|
113
|
-
delete cache[fullpath];
|
|
114
|
-
},
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
function compare(a, b) {
|
|
118
|
-
return a < b ? -1 : a > b ? 1 : 0;
|
|
119
|
-
}
|
|
120
|
-
function reverse_compare(a, b) {
|
|
121
|
-
return compare(b, a);
|
|
122
|
-
}
|
|
123
|
-
function reverse(func) {
|
|
124
|
-
return (a, b) => func(b, a);
|
|
125
|
-
}
|
|
126
|
-
function merge(...list) {
|
|
127
|
-
function isT(value) {
|
|
128
|
-
return typeof value === 'object' && value !== null;
|
|
129
|
-
}
|
|
130
|
-
function recurse(target, source) {
|
|
131
|
-
for (const key in source) {
|
|
132
|
-
if (isT(source[key]) && isT(target[key]))
|
|
133
|
-
recurse(target[key], source[key]);
|
|
134
|
-
else
|
|
135
|
-
target[key] = source[key];
|
|
136
|
-
}
|
|
137
|
-
return target;
|
|
138
|
-
}
|
|
139
|
-
return list.reduce((merged, r) => recurse(merged, r), {});
|
|
140
|
-
}
|
|
141
|
-
function partition(array, func) {
|
|
142
|
-
const partitions = {};
|
|
143
|
-
for (const i of array)
|
|
144
|
-
(partitions[func(i)] ??= []).push(i);
|
|
145
|
-
return partitions;
|
|
146
|
-
}
|
|
147
|
-
function isEmpty(obj) {
|
|
148
|
-
return Object.keys(obj).length === 0;
|
|
149
|
-
}
|
|
150
|
-
function clone(obj) {
|
|
151
|
-
return Object.assign(Object.create(Object.getPrototypeOf(obj)), obj);
|
|
152
|
-
}
|
|
153
|
-
function lowerBound(array, value, func) {
|
|
154
|
-
let i = 0;
|
|
155
|
-
for (let n = array.length; n; n >>= 1) {
|
|
156
|
-
const mid = i + (n >> 1);
|
|
157
|
-
if (func(array[mid], value, mid)) {
|
|
158
|
-
i = mid + 1;
|
|
159
|
-
--n;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
return i;
|
|
163
|
-
}
|
|
164
|
-
function argmin(array, fn) {
|
|
165
|
-
let mini = 0;
|
|
166
|
-
let minv = fn ? fn(array[0]) : array[0];
|
|
167
|
-
for (let i = 1; i < array.length; i++) {
|
|
168
|
-
const v = fn ? fn(array[i]) : array[i];
|
|
169
|
-
if (v < minv) {
|
|
170
|
-
mini = i;
|
|
171
|
-
minv = v;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
return mini;
|
|
175
|
-
}
|
|
176
|
-
function isConstructor(maker) {
|
|
177
|
-
return maker.prototype?.constructor.name;
|
|
178
|
-
// return typeof maker === 'function' && maker.prototype && !!maker.prototype.constructor;
|
|
179
|
-
}
|
|
180
|
-
function make(maker, arg, opt) {
|
|
181
|
-
return isConstructor(maker) ? new maker(arg, opt) : maker(arg, opt);
|
|
182
|
-
}
|
|
183
|
-
function arrayAppend(array, items) {
|
|
184
|
-
for (const i of items)
|
|
185
|
-
array.push(i);
|
|
186
|
-
}
|
|
187
|
-
function arrayRemove(array, item) {
|
|
188
|
-
const index = array.indexOf(item);
|
|
189
|
-
if (index === -1)
|
|
190
|
-
return false;
|
|
191
|
-
array.splice(index, 1);
|
|
192
|
-
return true;
|
|
193
|
-
}
|
|
194
|
-
function arrayCompare(arr1, arr2) {
|
|
195
|
-
const length = Math.min(arr1.length, arr2.length);
|
|
196
|
-
for (let i = 0; i < length; i++) {
|
|
197
|
-
const r = compare(arr1[i], arr2[i]);
|
|
198
|
-
if (r)
|
|
199
|
-
return r;
|
|
200
|
-
}
|
|
201
|
-
return arr1.length - arr2.length;
|
|
202
|
-
}
|
|
203
|
-
function arrayEqual(arr1, arr2) {
|
|
204
|
-
if (arr1.length !== arr2.length)
|
|
205
|
-
return false;
|
|
206
|
-
for (let i = 0; i < arr1.length; i++) {
|
|
207
|
-
if (arr1[i] !== arr2[i])
|
|
208
|
-
return false;
|
|
209
|
-
}
|
|
210
|
-
return true;
|
|
211
|
-
}
|
|
212
|
-
function arrayRotate(array, start, end, shift) {
|
|
213
|
-
const length = end - start;
|
|
214
|
-
if (length > 1 && shift % length) {
|
|
215
|
-
shift = ((shift % length) + length) % length;
|
|
216
|
-
arrayReverse(array, start, end - 1);
|
|
217
|
-
arrayReverse(array, start, start + shift - 1);
|
|
218
|
-
arrayReverse(array, start + shift, end - 1);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
function arrayReverse(array, start, end) {
|
|
222
|
-
while (start < end) {
|
|
223
|
-
[array[start], array[end]] = [array[end], array[start]];
|
|
224
|
-
start++;
|
|
225
|
-
end--;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
function array_make(n, constructor) {
|
|
229
|
-
return Array.from({ length: n }, () => new constructor);
|
|
230
|
-
}
|
|
231
|
-
function eachIterable(iterable, func) {
|
|
232
|
-
if (iterable) {
|
|
233
|
-
let i = 0;
|
|
234
|
-
for (const v of iterable)
|
|
235
|
-
func(v, i++);
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
function findIterable(iterable, func) {
|
|
239
|
-
if (iterable) {
|
|
240
|
-
for (const v of iterable) {
|
|
241
|
-
if (func(v))
|
|
242
|
-
return v;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
function mapIterable(iterable, func) {
|
|
247
|
-
return iterable ? Array.from(iterable, func) : [];
|
|
248
|
-
}
|
|
249
|
-
async function asyncMap(iterable, func) {
|
|
250
|
-
return Promise.all(mapIterable(iterable, func));
|
|
251
|
-
}
|
|
252
|
-
async function asyncReduce(array, func, initialValue) {
|
|
253
|
-
return array.reduce(async (promise, v, i, array) => func(await promise, v, i, array), Promise.resolve(initialValue));
|
|
254
|
-
}
|
|
255
|
-
async function parallel(...fns) {
|
|
256
|
-
return asyncMap(fns, f => f());
|
|
257
|
-
}
|
|
258
|
-
async function serial(...fns) {
|
|
259
|
-
const results = [];
|
|
260
|
-
for (const f of fns)
|
|
261
|
-
results.push(await f());
|
|
262
|
-
return results;
|
|
263
|
-
}
|
|
264
|
-
function filterIterable(iterable, func) {
|
|
265
|
-
const array = [];
|
|
266
|
-
let i = 0;
|
|
267
|
-
for (const v of iterable)
|
|
268
|
-
if (func(v, i++))
|
|
269
|
-
array.push(v);
|
|
270
|
-
return array;
|
|
271
|
-
}
|
|
272
|
-
async function asyncFilter(iterable, func) {
|
|
273
|
-
const filters = await Promise.all(mapIterable(iterable, func));
|
|
274
|
-
return filterIterable(iterable, (_, i) => filters[i]);
|
|
275
|
-
}
|
|
276
|
-
function mapObject(obj, func) {
|
|
277
|
-
return Object.fromEntries(Object.entries(obj).map(x => func(x)));
|
|
278
|
-
}
|
|
279
|
-
function filterObject(obj, func) {
|
|
280
|
-
return Object.fromEntries(Object.entries(obj).filter(x => func(x)));
|
|
281
|
-
}
|
|
282
|
-
//-----------------------------------------------------------------------------
|
|
283
|
-
// strings
|
|
284
|
-
//-----------------------------------------------------------------------------
|
|
285
|
-
function firstOf(value, find) {
|
|
286
|
-
let index = value.length;
|
|
287
|
-
for (const c of find) {
|
|
288
|
-
const i = value.indexOf(c);
|
|
289
|
-
if (i >= 0)
|
|
290
|
-
index = Math.min(i);
|
|
291
|
-
}
|
|
292
|
-
return index;
|
|
293
|
-
}
|
|
294
|
-
function lastOf(value, find) {
|
|
295
|
-
let index = -1;
|
|
296
|
-
for (const c of find)
|
|
297
|
-
index = Math.max(value.indexOf(c));
|
|
298
|
-
return index;
|
|
299
|
-
}
|
|
300
|
-
function splitFirstOf(value, find) {
|
|
301
|
-
const index = firstOf(value, find);
|
|
302
|
-
return index === -1 ? [undefined, value] : [value.substring(0, index), value.substring(index + 1)];
|
|
303
|
-
}
|
|
304
|
-
function splitLastOf(value, find) {
|
|
305
|
-
const index = lastOf(value, find);
|
|
306
|
-
return index === -1 ? [value, undefined] : [value.substring(0, index), value.substring(index + 1)];
|
|
307
|
-
}
|
|
308
|
-
function trim0(value) {
|
|
309
|
-
const index = value.indexOf('\0');
|
|
310
|
-
return index === -1 ? value : value.substring(0, index);
|
|
311
|
-
}
|
|
312
|
-
function replace(value, re, process) {
|
|
313
|
-
let m;
|
|
314
|
-
let result = "";
|
|
315
|
-
let i = 0;
|
|
316
|
-
while ((m = re.exec(value))) {
|
|
317
|
-
result += value.substring(i, m.index) + process(m);
|
|
318
|
-
i = re.lastIndex;
|
|
319
|
-
}
|
|
320
|
-
return result + value.substring(i);
|
|
321
|
-
}
|
|
322
|
-
async function async_replace(value, re, process) {
|
|
323
|
-
let m;
|
|
324
|
-
let result = "";
|
|
325
|
-
let i = 0;
|
|
326
|
-
while ((m = re.exec(value))) {
|
|
327
|
-
result += value.substring(i, m.index) + await process(m);
|
|
328
|
-
i = re.lastIndex;
|
|
329
|
-
}
|
|
330
|
-
return result + value.substring(i);
|
|
331
|
-
}
|
|
332
|
-
function replace_back(value, re, process) {
|
|
333
|
-
const start = re.lastIndex;
|
|
334
|
-
const m = re.exec(value);
|
|
335
|
-
if (m) {
|
|
336
|
-
const right = replace_back(value, re, process);
|
|
337
|
-
return value.substring(start, m.index) + process(m, right);
|
|
338
|
-
}
|
|
339
|
-
re.lastIndex = value.length;
|
|
340
|
-
return value.substring(start);
|
|
341
|
-
}
|
|
342
|
-
async function async_replace_back(value, re, process) {
|
|
343
|
-
const start = re.lastIndex;
|
|
344
|
-
const m = re.exec(value);
|
|
345
|
-
if (m) {
|
|
346
|
-
const right = await async_replace_back(value, re, process);
|
|
347
|
-
return value.substring(start, m.index) + await process(m, right);
|
|
348
|
-
}
|
|
349
|
-
re.lastIndex = value.length;
|
|
350
|
-
return value.substring(start);
|
|
351
|
-
}
|
|
352
|
-
function splitEvery(s, n) {
|
|
353
|
-
return Array.from({ length: Math.ceil(s.length / n) }, (_, i) => s.slice(i * n, (i + 1) * n));
|
|
354
|
-
}
|
|
355
|
-
function tag(strings, ...keys) {
|
|
356
|
-
return ((...values) => {
|
|
357
|
-
const dict = values.at(-1) || {};
|
|
358
|
-
return keys.map((key, i) => (Number.isInteger(key) ? values[key] : dict[key]) + strings[i + 1]).join('');
|
|
359
|
-
});
|
|
360
|
-
}
|
|
361
|
-
function stringCode(s) {
|
|
362
|
-
let r = 0;
|
|
363
|
-
for (let i = 0; i < s.length; i++)
|
|
364
|
-
r += s.charCodeAt(i) << (i * 8);
|
|
365
|
-
return r;
|
|
366
|
-
}
|
|
367
|
-
function stringCodeBig(s) {
|
|
368
|
-
let r = 0n;
|
|
369
|
-
for (let i = 0; i < s.length; i++)
|
|
370
|
-
r += BigInt(s.charCodeAt(i)) << BigInt(i * 8);
|
|
371
|
-
return r;
|
|
372
|
-
}
|
|
373
|
-
function previousChar(str, pos) {
|
|
374
|
-
return pos === 0
|
|
375
|
-
? "\n"
|
|
376
|
-
// check for low surrogate (BMP)
|
|
377
|
-
: (str.charCodeAt(pos - 1) & 0xfc00) === 0xdc00 && (str.charCodeAt(pos - 2) & 0xfc00) === 0xd800
|
|
378
|
-
? str.slice(pos - 2, pos) : str.charAt(pos - 1);
|
|
379
|
-
}
|
|
380
|
-
function hasCustomToString(value) {
|
|
381
|
-
return value && value.toString !== Object.prototype.toString;
|
|
382
|
-
}
|
|
383
|
-
class StringParser {
|
|
384
|
-
subject;
|
|
385
|
-
pos;
|
|
386
|
-
constructor(subject, pos = 0) {
|
|
387
|
-
this.subject = subject;
|
|
388
|
-
this.pos = pos;
|
|
389
|
-
}
|
|
390
|
-
remaining() { return this.subject.length - this.pos; }
|
|
391
|
-
remainder() { return this.subject.slice(this.pos); }
|
|
392
|
-
processed() { return this.subject.slice(0, this.pos); }
|
|
393
|
-
peek() {
|
|
394
|
-
return this.subject[this.pos];
|
|
395
|
-
}
|
|
396
|
-
peekn(n) {
|
|
397
|
-
return this.subject.slice(this.pos, this.pos + n);
|
|
398
|
-
}
|
|
399
|
-
get(n) {
|
|
400
|
-
const pos = this.pos;
|
|
401
|
-
this.pos = Math.min(pos + n, this.subject.length);
|
|
402
|
-
return this.subject.slice(pos, this.pos);
|
|
403
|
-
}
|
|
404
|
-
skip(c) {
|
|
405
|
-
if (this.remainder().startsWith(c)) {
|
|
406
|
-
this.pos += c.length;
|
|
407
|
-
return true;
|
|
408
|
-
}
|
|
409
|
-
return false;
|
|
410
|
-
}
|
|
411
|
-
expect(c) {
|
|
412
|
-
if (!this.skip(c))
|
|
413
|
-
throw new Error(`Expected '${c}'`);
|
|
414
|
-
}
|
|
415
|
-
match(re) {
|
|
416
|
-
const m = re.exec(this.remainder());
|
|
417
|
-
if (m) {
|
|
418
|
-
this.pos += m.index + m[0].length;
|
|
419
|
-
return m[0];
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
exec(re) {
|
|
423
|
-
const m = re.exec(this.remainder());
|
|
424
|
-
if (m) {
|
|
425
|
-
this.pos += m.index + m[0].length;
|
|
426
|
-
return m;
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
exports.StringParser = StringParser;
|