@the-w1zard/dx 1.0.7 → 1.0.9
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/README.html +823 -121
- package/README.md +288 -107
- package/dist/index.js +12967 -0
- package/package.json +22 -7
- package/src/dx.d.ts +2 -10
- package/src/array.js +0 -221
- package/src/array.ts +0 -301
- package/src/boolean_byte.js +0 -22
- package/src/boolean_byte.ts +0 -23
- package/src/class.js +0 -1
- package/src/class.ts +0 -0
- package/src/date.js +0 -649
- package/src/date.ts +0 -660
- package/src/error.js +0 -60
- package/src/error.ts +0 -81
- package/src/index.js +0 -18
- package/src/index.ts +0 -18
- package/src/iterator.js +0 -386
- package/src/iterator.ts +0 -407
- package/src/map.js +0 -495
- package/src/map.ts +0 -513
- package/src/map_byte.js +0 -483
- package/src/map_byte.ts +0 -422
- package/src/number.js +0 -178
- package/src/number.ts +0 -212
- package/src/object.js +0 -217
- package/src/object.ts +0 -291
- package/src/promise.js +0 -206
- package/src/promise.ts +0 -309
- package/src/reg_ex.js +0 -479
- package/src/reg_ex.ts +0 -423
- package/src/set.js +0 -227
- package/src/set.ts +0 -198
- package/src/set_byte.js +0 -261
- package/src/set_byte.ts +0 -223
- package/src/soa_codec.js +0 -28
- package/src/soa_codec.ts +0 -27
- package/src/string.js +0 -133
- package/src/string.ts +0 -175
- package/src/unit8array.js +0 -272
- package/src/unit8array.ts +0 -374
- package/src/url_search_params.js +0 -172
- package/src/url_search_params.ts +0 -187
- package/src/weak_map.js +0 -136
- package/src/weak_map.ts +0 -155
- package/src/weak_set.js +0 -92
- package/src/weak_set.ts +0 -101
package/src/unit8array.ts
DELETED
|
@@ -1,374 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
export class U82I<T = A> extends Array<T> implements U82<T> {
|
|
3
|
-
constructor(...items: T[]) {
|
|
4
|
-
super(...items);
|
|
5
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
static get [Symbol.species](): ArrayConstructor {
|
|
9
|
-
return Array;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
static override from<T>(arrayLike: ArrayLike<T>): U82I<T>;
|
|
13
|
-
static override from<T, U>(
|
|
14
|
-
arrayLike: ArrayLike<T>,
|
|
15
|
-
mapFn: (value: T, index: number) => U,
|
|
16
|
-
thisArg?: A,
|
|
17
|
-
): U82I<U>;
|
|
18
|
-
static override from<T>(iterable: Iterable<T> | ArrayLike<T>): U82I<T>;
|
|
19
|
-
static override from<T, U>(
|
|
20
|
-
iterable: Iterable<T> | ArrayLike<T>,
|
|
21
|
-
mapFn?: (value: T, index: number) => U,
|
|
22
|
-
thisArg?: A,
|
|
23
|
-
): U82I<T | U> {
|
|
24
|
-
const values: T[] =
|
|
25
|
-
Symbol.iterator in Object(iterable)
|
|
26
|
-
? Array.from(iterable as Iterable<T>)
|
|
27
|
-
: Array.from(iterable as ArrayLike<T>);
|
|
28
|
-
|
|
29
|
-
const result: (T | U)[] = mapFn
|
|
30
|
-
? values.map((value, index) => mapFn.call(thisArg, value, index))
|
|
31
|
-
: values;
|
|
32
|
-
|
|
33
|
-
return new U82I<T | U>(...result);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
static override of<T>(...items: T[]): U82I<T> {
|
|
37
|
-
return new U82I(...items);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
first(): T | undefined {
|
|
41
|
-
return this[0];
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
last(): T | undefined {
|
|
45
|
-
return this[this.length - 1];
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
second(): T | undefined {
|
|
49
|
-
return this[1];
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
third(): T | undefined {
|
|
53
|
-
return this[2];
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
random(): T | undefined {
|
|
57
|
-
return this.length ? this[Math.floor(Math.random() * this.length)] : undefined;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
isEmpty(): boolean {
|
|
61
|
-
return this.length === 0;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
isNotEmpty(): boolean {
|
|
65
|
-
return this.length > 0;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
isNotEmptyAndDefined(): boolean {
|
|
69
|
-
return this.some(value => value !== undefined && value !== null);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
clear(): this {
|
|
73
|
-
this.length = 0;
|
|
74
|
-
return this;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
clone(): U82I<T> {
|
|
78
|
-
return new U82I(...this);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
unique(): U82I<T> {
|
|
82
|
-
return new U82I(...new Set(this));
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
compact(): U82I<NonNullable<T>> {
|
|
86
|
-
return new U82I(...this.filter((value): value is NonNullable<T> => value != null));
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
chunk(size: N): U82I<U82I<T>> {
|
|
90
|
-
if (size <= 0) throw new RangeError("Chunk size must be greater than zero");
|
|
91
|
-
|
|
92
|
-
const result = new U82I<U82I<T>>();
|
|
93
|
-
|
|
94
|
-
for (let i = 0; i < this.length; i += size) {
|
|
95
|
-
result.push(new U82I(...this.slice(i, i + size)));
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return result;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
flatten<D extends N = 1>(depth?: D): U82I<A> {
|
|
102
|
-
return new U82I(...(this.flat(depth) as A[]));
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
shuffle(): this {
|
|
106
|
-
return this.shuffleInPlace();
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
sample(count = 1 as N): U82I<T> {
|
|
110
|
-
return this.pick(count);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
count(predicate?: (value: T, index: N, array: T[]) => unknown): N {
|
|
114
|
-
return (predicate ? this.filter(predicate).length : this.length) as N;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
sum(this: U82I<number>): number {
|
|
118
|
-
return this.reduce((total, value) => total + value, 0);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
average(this: U82I<number>): number {
|
|
122
|
-
return this.length ? this.sum() / this.length : 0;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
min(this: U82I<number>): number | undefined {
|
|
126
|
-
return this.length ? Math.min(...this) : undefined;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
max(this: U82I<number>): number | undefined {
|
|
130
|
-
return this.length ? Math.max(...this) : undefined;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
groupBy<K extends PropertyKey>(keyFn: (value: T, index: N) => K): Map<K, U82I<T>> {
|
|
134
|
-
const result = new Map<K, U82I<T>>();
|
|
135
|
-
|
|
136
|
-
this.forEach((value, index) => {
|
|
137
|
-
const key = keyFn(value, index as N);
|
|
138
|
-
|
|
139
|
-
if (!result.has(key)) result.set(key, new U82I<T>());
|
|
140
|
-
result.get(key)!.push(value);
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
return result;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
keyBy<K extends PropertyKey>(keyFn: (value: T, index: N) => K): Map<K, T> {
|
|
147
|
-
const result = new Map<K, T>();
|
|
148
|
-
|
|
149
|
-
this.forEach((value, index) => result.set(keyFn(value, index as N), value));
|
|
150
|
-
|
|
151
|
-
return result;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
partition(predicate: (value: T, index: N, array: T[]) => unknown): [U82I<T>, U82I<T>] {
|
|
155
|
-
const yes = new U82I<T>();
|
|
156
|
-
const no = new U82I<T>();
|
|
157
|
-
|
|
158
|
-
this.forEach((value, index, array) => {
|
|
159
|
-
(predicate(value, index as N, array) ? yes : no).push(value);
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
return [yes, no];
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
difference(other: Iterable<T>): U82I<T> {
|
|
166
|
-
const values = new Set(other);
|
|
167
|
-
return new U82I(...this.filter(value => !values.has(value)));
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
intersection(other: Iterable<T>): U82I<T> {
|
|
171
|
-
const values = new Set(other);
|
|
172
|
-
return new U82I(...this.filter(value => values.has(value)));
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
union(other: Iterable<T>): U82I<T> {
|
|
176
|
-
return new U82I(...new Set([...this, ...other]));
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
symmetricDifference(other: Iterable<T>): U82I<T> {
|
|
180
|
-
const values = new Set(other);
|
|
181
|
-
const own = new Set(this);
|
|
182
|
-
|
|
183
|
-
return new U82I(
|
|
184
|
-
...[...this.filter(value => !values.has(value)), ...Array.from(values).filter(value => !own.has(value))],
|
|
185
|
-
);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
take(count: N): U82I<T> {
|
|
189
|
-
return new U82I(...this.slice(0, Math.max(0, count)));
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
takeLast(count: N): U82I<T> {
|
|
193
|
-
return new U82I(...this.slice(-Math.max(0, count)));
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
drop(count: N): U82I<T> {
|
|
197
|
-
return new U82I(...this.slice(Math.max(0, count)));
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
dropLast(count: N): U82I<T> {
|
|
201
|
-
return new U82I(...this.slice(0, Math.max(0, this.length - count)));
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
pluck<K extends keyof T>(key: K): U82I<T[K]> {
|
|
205
|
-
return new U82I(...this.map(value => value[key]));
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
flattenDeep(): U82I<A> {
|
|
209
|
-
return new U82I(...(this.flat(Infinity) as A[]));
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
insert(index: N, ...items: T[]): this {
|
|
213
|
-
this.splice(index, 0, ...items);
|
|
214
|
-
return this;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
removeAt(index: N): T | undefined {
|
|
218
|
-
if (index < 0 || index >= this.length) return undefined;
|
|
219
|
-
return this.splice(index, 1)[0];
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
remove(value: T): boolean {
|
|
223
|
-
const index = this.indexOf(value);
|
|
224
|
-
|
|
225
|
-
if (index === -1) return false;
|
|
226
|
-
|
|
227
|
-
this.splice(index, 1);
|
|
228
|
-
return true;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
removeWhere(predicate: (value: T, index: N, array: T[]) => unknown): this {
|
|
232
|
-
for (let i = this.length - 1; i >= 0; i--) {
|
|
233
|
-
if (predicate(this[i], i as N, this)) this.splice(i, 1);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
return this;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
replace(oldValue: T, newValue: T): boolean {
|
|
240
|
-
const index = this.indexOf(oldValue);
|
|
241
|
-
|
|
242
|
-
if (index === -1) return false;
|
|
243
|
-
|
|
244
|
-
this[index] = newValue;
|
|
245
|
-
return true;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
move(from: N, to: N): this {
|
|
249
|
-
if (from < 0 || from >= this.length || to < 0 || to >= this.length) return this;
|
|
250
|
-
|
|
251
|
-
const [value] = this.splice(from, 1);
|
|
252
|
-
this.splice(to, 0, value);
|
|
253
|
-
|
|
254
|
-
return this;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
swap(i: N, j: N): this {
|
|
258
|
-
if (i < 0 || j < 0 || i >= this.length || j >= this.length) return this;
|
|
259
|
-
|
|
260
|
-
[this[i], this[j]] = [this[j], this[i]];
|
|
261
|
-
|
|
262
|
-
return this;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
shuffleInPlace(): this {
|
|
266
|
-
for (let i = this.length - 1; i > 0; i--) {
|
|
267
|
-
const j = Math.floor(Math.random() * (i + 1));
|
|
268
|
-
[this[i], this[j]] = [this[j], this[i]];
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
return this;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
pick(count = 1 as N): U82I<T> {
|
|
275
|
-
const values = [...this];
|
|
276
|
-
const result = new U82I<T>();
|
|
277
|
-
|
|
278
|
-
for (let i = 0; i < Math.min(Math.max(0, count), values.length); i++) {
|
|
279
|
-
const j = Math.floor(Math.random() * values.length);
|
|
280
|
-
result.push(values.splice(j, 1)[0]);
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
return result;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
toSet(): Set<T> {
|
|
287
|
-
return new Set(this);
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
toMap<K extends PropertyKey>(keyFn: (value: T, index: N) => K): Map<K, T> {
|
|
291
|
-
return this.keyBy(keyFn);
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
equals(other: readonly T[]): boolean {
|
|
295
|
-
return this.length === other.length && this.every((value, index) => Object.is(value, other[index]));
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
startsWith(other: readonly T[]): boolean {
|
|
299
|
-
return other.length <= this.length && other.every((value, index) => Object.is(this[index], value));
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
endsWith(other: readonly T[]): boolean {
|
|
303
|
-
return (
|
|
304
|
-
other.length <= this.length &&
|
|
305
|
-
other.every((value, index) => Object.is(this[this.length - other.length + index], value))
|
|
306
|
-
);
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
isSorted(compareFn: (a: T, b: T) => N = ((a, b) => (a < b ? -1 : a > b ? 1 : 0) as N)): boolean {
|
|
310
|
-
for (let i = 1; i < this.length; i++) {
|
|
311
|
-
if (compareFn(this[i - 1], this[i]) > 0) return false;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
return true;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
frequencies(): Map<T, N> {
|
|
318
|
-
const result = new Map<T, N>();
|
|
319
|
-
|
|
320
|
-
for (const value of this) {
|
|
321
|
-
result.set(value, ((result.get(value) ?? 0) + 1) as N);
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
return result;
|
|
325
|
-
}
|
|
326
|
-
findLast<S extends T>(
|
|
327
|
-
predicate: (value: T, index: N, obj: T[]) => value is S,
|
|
328
|
-
thisArg?: A,
|
|
329
|
-
): S | undefined;
|
|
330
|
-
findLast(
|
|
331
|
-
predicate: (value: T, index: N, obj: T[]) => unknown,
|
|
332
|
-
thisArg?: A,
|
|
333
|
-
): T | undefined {
|
|
334
|
-
for (let i = this.length - 1; i >= 0; i--) {
|
|
335
|
-
if (predicate.call(thisArg, this[i], i as N, this)) return this[i];
|
|
336
|
-
}
|
|
337
|
-
return undefined;
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
findLastIndex(predicate: (value: T, index: N, obj: T[]) => unknown, thisArg?: A): N {
|
|
341
|
-
for (let i = this.length - 1; i >= 0; i--) {
|
|
342
|
-
if (predicate.call(thisArg, this[i], i as N, this)) return i as N;
|
|
343
|
-
}
|
|
344
|
-
return -1 as N;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
toReversed(): T[] {
|
|
348
|
-
return [...this].reverse();
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
toSorted(compareFn?: (a: T, b: T) => N): T[] {
|
|
352
|
-
return [...this].sort(compareFn);
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
toSpliced(start: N, deleteCount: N, ...items: T[]): T[] {
|
|
356
|
-
const result = [...this];
|
|
357
|
-
result.splice(start, deleteCount, ...items);
|
|
358
|
-
return result;
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
with(index: N, value: T): T[] {
|
|
362
|
-
const result = [...this];
|
|
363
|
-
const actualIndex = index < 0 ? result.length + index : index;
|
|
364
|
-
|
|
365
|
-
if (actualIndex < 0 || actualIndex >= result.length) {
|
|
366
|
-
throw new RangeError("Invalid index");
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
result[actualIndex] = value;
|
|
370
|
-
return result;
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
globalThis.U82 = U82I;
|
package/src/url_search_params.js
DELETED
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
export class USP2I extends URLSearchParams {
|
|
2
|
-
constructor(init) {
|
|
3
|
-
super(init);
|
|
4
|
-
}
|
|
5
|
-
get size() {
|
|
6
|
-
return Array.from(this).length;
|
|
7
|
-
}
|
|
8
|
-
getOr(name, fallback) {
|
|
9
|
-
return this.get(name) ?? fallback;
|
|
10
|
-
}
|
|
11
|
-
getOrNull(name) {
|
|
12
|
-
return this.get(name);
|
|
13
|
-
}
|
|
14
|
-
getOrThrow(name, error = new Error(`Missing URL parameter: ${name}`)) {
|
|
15
|
-
const value = this.get(name);
|
|
16
|
-
if (value === null)
|
|
17
|
-
throw error;
|
|
18
|
-
return value;
|
|
19
|
-
}
|
|
20
|
-
getNumber(name, fallback) {
|
|
21
|
-
const value = this.get(name);
|
|
22
|
-
if (value === null || value.trim() === "")
|
|
23
|
-
return fallback;
|
|
24
|
-
const number = Number(value);
|
|
25
|
-
return Number.isFinite(number) ? number : fallback;
|
|
26
|
-
}
|
|
27
|
-
getInt(name, radix = 10) {
|
|
28
|
-
const value = this.get(name);
|
|
29
|
-
if (value === null || value.trim() === "")
|
|
30
|
-
return undefined;
|
|
31
|
-
const number = Number.parseInt(value, radix);
|
|
32
|
-
return Number.isNaN(number) ? undefined : number;
|
|
33
|
-
}
|
|
34
|
-
getFloat(name) {
|
|
35
|
-
const value = this.get(name);
|
|
36
|
-
if (value === null || value.trim() === "")
|
|
37
|
-
return undefined;
|
|
38
|
-
const number = Number.parseFloat(value);
|
|
39
|
-
return Number.isNaN(number) ? undefined : number;
|
|
40
|
-
}
|
|
41
|
-
getBoolean(name, fallback = false) {
|
|
42
|
-
const value = this.get(name);
|
|
43
|
-
if (value === null)
|
|
44
|
-
return fallback;
|
|
45
|
-
switch (value.trim().toLowerCase()) {
|
|
46
|
-
case "true":
|
|
47
|
-
case "1":
|
|
48
|
-
case "yes":
|
|
49
|
-
case "on":
|
|
50
|
-
return true;
|
|
51
|
-
case "false":
|
|
52
|
-
case "0":
|
|
53
|
-
case "no":
|
|
54
|
-
case "off":
|
|
55
|
-
return false;
|
|
56
|
-
default:
|
|
57
|
-
return fallback;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
getJSON(name) {
|
|
61
|
-
const value = this.get(name);
|
|
62
|
-
if (value === null)
|
|
63
|
-
return undefined;
|
|
64
|
-
try {
|
|
65
|
-
return JSON.parse(value);
|
|
66
|
-
}
|
|
67
|
-
catch {
|
|
68
|
-
return undefined;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
getArray(name, separator = ",") {
|
|
72
|
-
const value = this.get(name);
|
|
73
|
-
return value === null || value === "" ? [] : value.split(separator);
|
|
74
|
-
}
|
|
75
|
-
getObject() {
|
|
76
|
-
const result = {};
|
|
77
|
-
for (const key of new Set(this.keys())) {
|
|
78
|
-
const values = this.getAll(key);
|
|
79
|
-
result[key] = values.length > 1 ? values : values[0];
|
|
80
|
-
}
|
|
81
|
-
return result;
|
|
82
|
-
}
|
|
83
|
-
setNumber(name, value) {
|
|
84
|
-
this.set(name, String(value));
|
|
85
|
-
return this;
|
|
86
|
-
}
|
|
87
|
-
setBoolean(name, value) {
|
|
88
|
-
this.set(name, String(value));
|
|
89
|
-
return this;
|
|
90
|
-
}
|
|
91
|
-
setJSON(name, value) {
|
|
92
|
-
this.set(name, JSON.stringify(value));
|
|
93
|
-
return this;
|
|
94
|
-
}
|
|
95
|
-
setArray(name, values, separator = ",") {
|
|
96
|
-
this.set(name, Array.from(values, String).join(separator));
|
|
97
|
-
return this;
|
|
98
|
-
}
|
|
99
|
-
setIfAbsent(name, value) {
|
|
100
|
-
if (!this.has(name))
|
|
101
|
-
this.set(name, value);
|
|
102
|
-
return this;
|
|
103
|
-
}
|
|
104
|
-
setIfPresent(name, value) {
|
|
105
|
-
if (this.has(name))
|
|
106
|
-
this.set(name, value);
|
|
107
|
-
return this;
|
|
108
|
-
}
|
|
109
|
-
appendAll(params) {
|
|
110
|
-
if (params instanceof URLSearchParams) {
|
|
111
|
-
params.forEach((value, key) => this.append(key, value));
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
for (const [key, value] of Object.entries(params)) {
|
|
115
|
-
if (value != null) {
|
|
116
|
-
if (Array.isArray(value)) {
|
|
117
|
-
for (const item of value)
|
|
118
|
-
this.append(key, String(item));
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
this.append(key, String(value));
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
return this;
|
|
127
|
-
}
|
|
128
|
-
merge(params, overwrite = true) {
|
|
129
|
-
if (params instanceof URLSearchParams) {
|
|
130
|
-
params.forEach((value, key) => {
|
|
131
|
-
if (overwrite || !this.has(key))
|
|
132
|
-
this.set(key, value);
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
for (const [key, value] of Object.entries(params)) {
|
|
137
|
-
if (value != null && (overwrite || !this.has(key))) {
|
|
138
|
-
this.set(key, String(value));
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
return this;
|
|
143
|
-
}
|
|
144
|
-
clone() {
|
|
145
|
-
return new USP2I(this);
|
|
146
|
-
}
|
|
147
|
-
clear() {
|
|
148
|
-
for (const key of new Set(this.keys()))
|
|
149
|
-
this.delete(key);
|
|
150
|
-
}
|
|
151
|
-
isEmpty() {
|
|
152
|
-
return this.size === 0;
|
|
153
|
-
}
|
|
154
|
-
isNotEmpty() {
|
|
155
|
-
return this.size > 0;
|
|
156
|
-
}
|
|
157
|
-
toObject() {
|
|
158
|
-
return this.getObject();
|
|
159
|
-
}
|
|
160
|
-
toJSON() {
|
|
161
|
-
return this.toObject();
|
|
162
|
-
}
|
|
163
|
-
toURLSearchParams() {
|
|
164
|
-
return new URLSearchParams(this);
|
|
165
|
-
}
|
|
166
|
-
toURL(url) {
|
|
167
|
-
const result = new URL(url);
|
|
168
|
-
this.forEach((value, key) => result.searchParams.append(key, value));
|
|
169
|
-
return result;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
globalThis.USP2 = USP2I;
|