@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/soa_codec.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
export class SOA_CODEC {
|
|
2
|
-
maxPids;
|
|
3
|
-
// SoA Memory Layout (Typed Arrays for Cache Locality)
|
|
4
|
-
channelMap;
|
|
5
|
-
subChannelMap;
|
|
6
|
-
tripChannelMap;
|
|
7
|
-
keyMap;
|
|
8
|
-
listeners;
|
|
9
|
-
nextPid = 1;
|
|
10
|
-
constructor(maxPids = 8192) {
|
|
11
|
-
this.maxPids = maxPids;
|
|
12
|
-
this.channelMap = new Int32Array(maxPids);
|
|
13
|
-
this.subChannelMap = new Int32Array(maxPids);
|
|
14
|
-
this.tripChannelMap = new Int32Array(maxPids);
|
|
15
|
-
this.keyMap = new Int32Array(maxPids);
|
|
16
|
-
this.listeners = new Array(maxPids);
|
|
17
|
-
} // Hot path lookup or allocation: O(1) inline integer assignment
|
|
18
|
-
allocatePid(rId, mId, sId, kId) {
|
|
19
|
-
const pid = this.nextPid++;
|
|
20
|
-
if (pid >= this.maxPids)
|
|
21
|
-
throw new Error("PID capacity exceeded");
|
|
22
|
-
this.channelMap[pid] = rId;
|
|
23
|
-
this.subChannelMap[pid] = mId;
|
|
24
|
-
this.tripChannelMap[pid] = sId;
|
|
25
|
-
this.keyMap[pid] = kId;
|
|
26
|
-
return pid;
|
|
27
|
-
}
|
|
28
|
-
}
|
package/src/soa_codec.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export class SOA_CODEC {// HIGH_PERFORMANCE_SOA_CODEC
|
|
2
|
-
public readonly maxPids: number;
|
|
3
|
-
// SoA Memory Layout (Typed Arrays for Cache Locality)
|
|
4
|
-
public readonly channelMap: Int32Array;
|
|
5
|
-
public readonly subChannelMap: Int32Array;
|
|
6
|
-
public readonly tripChannelMap: Int32Array;
|
|
7
|
-
public readonly keyMap: Int32Array;
|
|
8
|
-
public readonly listeners: Array<((pid: number, val?: number) => void) | undefined>;
|
|
9
|
-
public nextPid = 1;
|
|
10
|
-
constructor( maxPids = 8192) {
|
|
11
|
-
this.maxPids = maxPids;
|
|
12
|
-
this.channelMap = new Int32Array(maxPids);
|
|
13
|
-
this.subChannelMap = new Int32Array(maxPids);
|
|
14
|
-
this.tripChannelMap = new Int32Array(maxPids);
|
|
15
|
-
this.keyMap = new Int32Array(maxPids);
|
|
16
|
-
this.listeners = new Array(maxPids);
|
|
17
|
-
}// Hot path lookup or allocation: O(1) inline integer assignment
|
|
18
|
-
public allocatePid(rId: number, mId: number, sId: number, kId: number): number {
|
|
19
|
-
const pid = this.nextPid++;
|
|
20
|
-
if (pid >= this.maxPids) throw new Error("PID capacity exceeded");
|
|
21
|
-
this.channelMap[pid] = rId;
|
|
22
|
-
this.subChannelMap[pid] = mId;
|
|
23
|
-
this.tripChannelMap[pid] = sId;
|
|
24
|
-
this.keyMap[pid] = kId;
|
|
25
|
-
return pid;
|
|
26
|
-
}
|
|
27
|
-
}
|
package/src/string.js
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
export class S2I extends String {
|
|
2
|
-
constructor(value = "") {
|
|
3
|
-
super(value);
|
|
4
|
-
}
|
|
5
|
-
empty() {
|
|
6
|
-
return this.length === 0;
|
|
7
|
-
}
|
|
8
|
-
notEmpty() {
|
|
9
|
-
return this.length > 0;
|
|
10
|
-
}
|
|
11
|
-
blank() {
|
|
12
|
-
return this.trim().length === 0;
|
|
13
|
-
}
|
|
14
|
-
notBlank() {
|
|
15
|
-
return !this.blank();
|
|
16
|
-
}
|
|
17
|
-
equals(value) {
|
|
18
|
-
return this.toString() === value;
|
|
19
|
-
}
|
|
20
|
-
equalsIgnoreCase(value) {
|
|
21
|
-
return this.toLowerCase() === value.toLowerCase();
|
|
22
|
-
}
|
|
23
|
-
contains(value) {
|
|
24
|
-
return this.includes(value);
|
|
25
|
-
}
|
|
26
|
-
starts(value) {
|
|
27
|
-
return this.startsWith(value);
|
|
28
|
-
}
|
|
29
|
-
ends(value) {
|
|
30
|
-
return this.endsWith(value);
|
|
31
|
-
}
|
|
32
|
-
first() {
|
|
33
|
-
return this.charAt(0);
|
|
34
|
-
}
|
|
35
|
-
last() {
|
|
36
|
-
return this.charAt(this.length - 1);
|
|
37
|
-
}
|
|
38
|
-
reverse() {
|
|
39
|
-
return Array.from(this.toString()).reverse().join("");
|
|
40
|
-
}
|
|
41
|
-
capitalize() {
|
|
42
|
-
return this.length ? this.charAt(0).toUpperCase() + this.slice(1) : "";
|
|
43
|
-
}
|
|
44
|
-
uncapitalize() {
|
|
45
|
-
return this.length ? this.charAt(0).toLowerCase() + this.slice(1) : "";
|
|
46
|
-
}
|
|
47
|
-
titleCase() {
|
|
48
|
-
return this.toLowerCase().replace(/\b\w/g, char => char.toUpperCase());
|
|
49
|
-
}
|
|
50
|
-
camelCase() {
|
|
51
|
-
return this.toString()
|
|
52
|
-
.replace(/([a-z\d])([A-Z])/g, "$1 $2")
|
|
53
|
-
.split(/[^a-zA-Z\d]+/)
|
|
54
|
-
.filter(Boolean)
|
|
55
|
-
.map((word, index) => index === 0
|
|
56
|
-
? word.toLowerCase()
|
|
57
|
-
: word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
|
|
58
|
-
.join("");
|
|
59
|
-
}
|
|
60
|
-
kebabCase() {
|
|
61
|
-
return this.toString()
|
|
62
|
-
.replace(/([a-z\d])([A-Z])/g, "$1-$2")
|
|
63
|
-
.replace(/[^a-zA-Z\d]+/g, "-")
|
|
64
|
-
.replace(/^-+|-+$/g, "")
|
|
65
|
-
.toLowerCase();
|
|
66
|
-
}
|
|
67
|
-
snakeCase() {
|
|
68
|
-
return this.kebabCase().replace(/-/g, "_");
|
|
69
|
-
}
|
|
70
|
-
pascalCase() {
|
|
71
|
-
return this.toString()
|
|
72
|
-
.replace(/([a-z\d])([A-Z])/g, "$1 $2")
|
|
73
|
-
.split(/[^a-zA-Z\d]+/)
|
|
74
|
-
.filter(Boolean)
|
|
75
|
-
.map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
|
|
76
|
-
.join("");
|
|
77
|
-
}
|
|
78
|
-
words() {
|
|
79
|
-
return this.toString().match(/[\p{L}\p{N}]+/gu) ?? [];
|
|
80
|
-
}
|
|
81
|
-
lines() {
|
|
82
|
-
return this.split(/\r\n|\r|\n/);
|
|
83
|
-
}
|
|
84
|
-
chars() {
|
|
85
|
-
return Array.from(this.toString());
|
|
86
|
-
}
|
|
87
|
-
unique() {
|
|
88
|
-
return Array.from(new Set(this.chars())).join("");
|
|
89
|
-
}
|
|
90
|
-
escapeRegExp() {
|
|
91
|
-
return this.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
92
|
-
}
|
|
93
|
-
stripHtml() {
|
|
94
|
-
return this.replace(/<[^>]*>/g, "");
|
|
95
|
-
}
|
|
96
|
-
stripWhitespace() {
|
|
97
|
-
return this.replace(/\s+/g, "");
|
|
98
|
-
}
|
|
99
|
-
truncate(length, suffix = "...") {
|
|
100
|
-
if (this.length <= length)
|
|
101
|
-
return this.toString();
|
|
102
|
-
return this.slice(0, Math.max(0, length - suffix.length)) + suffix;
|
|
103
|
-
}
|
|
104
|
-
limit(length, suffix = "...") {
|
|
105
|
-
return this.truncate(length, suffix);
|
|
106
|
-
}
|
|
107
|
-
toNumber() {
|
|
108
|
-
return Number(this.toString());
|
|
109
|
-
}
|
|
110
|
-
toInt(radix) {
|
|
111
|
-
return Number.parseInt(this.toString(), radix);
|
|
112
|
-
}
|
|
113
|
-
toFloat() {
|
|
114
|
-
return Number.parseFloat(this.toString());
|
|
115
|
-
}
|
|
116
|
-
toBoolean() {
|
|
117
|
-
const value = this.trim().toLowerCase();
|
|
118
|
-
return value === "true" || value === "1" || value === "yes" || value === "on";
|
|
119
|
-
}
|
|
120
|
-
toArray() {
|
|
121
|
-
return this.chars();
|
|
122
|
-
}
|
|
123
|
-
toJSON() {
|
|
124
|
-
return JSON.stringify(this.toString());
|
|
125
|
-
}
|
|
126
|
-
isWellFormed() {
|
|
127
|
-
return !/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/u.test(this.toString());
|
|
128
|
-
}
|
|
129
|
-
toWellFormed() {
|
|
130
|
-
return this.toString().replace(/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/gu, "\uFFFD");
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
globalThis.S2 = S2I;
|
package/src/string.ts
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export class S2I extends String implements S2 {
|
|
4
|
-
constructor(value: A = "") {
|
|
5
|
-
super(value);
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
empty(): boolean {
|
|
9
|
-
return this.length === 0;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
notEmpty(): boolean {
|
|
13
|
-
return this.length > 0;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
blank(): boolean {
|
|
17
|
-
return this.trim().length === 0;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
notBlank(): boolean {
|
|
21
|
-
return !this.blank();
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
equals(value: string): boolean {
|
|
25
|
-
return this.toString() === value;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
equalsIgnoreCase(value: string): boolean {
|
|
29
|
-
return this.toLowerCase() === value.toLowerCase();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
contains(value: string): boolean {
|
|
33
|
-
return this.includes(value);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
starts(value: string): boolean {
|
|
37
|
-
return this.startsWith(value);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
ends(value: string): boolean {
|
|
41
|
-
return this.endsWith(value);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
first(): string {
|
|
45
|
-
return this.charAt(0);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
last(): string {
|
|
49
|
-
return this.charAt(this.length - 1);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
reverse(): string {
|
|
53
|
-
return Array.from(this.toString()).reverse().join("");
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
capitalize(): string {
|
|
57
|
-
return this.length ? this.charAt(0).toUpperCase() + this.slice(1) : "";
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
uncapitalize(): string {
|
|
61
|
-
return this.length ? this.charAt(0).toLowerCase() + this.slice(1) : "";
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
titleCase(): string {
|
|
65
|
-
return this.toLowerCase().replace(/\b\w/g, char => char.toUpperCase());
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
camelCase(): string {
|
|
69
|
-
return this.toString()
|
|
70
|
-
.replace(/([a-z\d])([A-Z])/g, "$1 $2")
|
|
71
|
-
.split(/[^a-zA-Z\d]+/)
|
|
72
|
-
.filter(Boolean)
|
|
73
|
-
.map((word, index) =>
|
|
74
|
-
index === 0
|
|
75
|
-
? word.toLowerCase()
|
|
76
|
-
: word.charAt(0).toUpperCase() + word.slice(1).toLowerCase(),
|
|
77
|
-
)
|
|
78
|
-
.join("");
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
kebabCase(): string {
|
|
82
|
-
return this.toString()
|
|
83
|
-
.replace(/([a-z\d])([A-Z])/g, "$1-$2")
|
|
84
|
-
.replace(/[^a-zA-Z\d]+/g, "-")
|
|
85
|
-
.replace(/^-+|-+$/g, "")
|
|
86
|
-
.toLowerCase();
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
snakeCase(): string {
|
|
90
|
-
return this.kebabCase().replace(/-/g, "_");
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
pascalCase(): string {
|
|
94
|
-
return this.toString()
|
|
95
|
-
.replace(/([a-z\d])([A-Z])/g, "$1 $2")
|
|
96
|
-
.split(/[^a-zA-Z\d]+/)
|
|
97
|
-
.filter(Boolean)
|
|
98
|
-
.map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
|
|
99
|
-
.join("");
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
words(): string[] {
|
|
103
|
-
return this.toString().match(/[\p{L}\p{N}]+/gu) ?? [];
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
lines(): string[] {
|
|
107
|
-
return this.split(/\r\n|\r|\n/);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
chars(): string[] {
|
|
111
|
-
return Array.from(this.toString());
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
unique(): string {
|
|
115
|
-
return Array.from(new Set(this.chars())).join("");
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
escapeRegExp(): string {
|
|
119
|
-
return this.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
stripHtml(): string {
|
|
123
|
-
return this.replace(/<[^>]*>/g, "");
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
stripWhitespace(): string {
|
|
127
|
-
return this.replace(/\s+/g, "");
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
truncate(length: N, suffix = "..."): string {
|
|
131
|
-
if (this.length <= length) return this.toString();
|
|
132
|
-
return this.slice(0, Math.max(0, length - suffix.length)) + suffix;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
limit(length: N, suffix = "..."): string {
|
|
136
|
-
return this.truncate(length, suffix);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
toNumber(): number {
|
|
140
|
-
return Number(this.toString());
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
toInt(radix?: N): number {
|
|
144
|
-
return Number.parseInt(this.toString(), radix);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
toFloat(): number {
|
|
148
|
-
return Number.parseFloat(this.toString());
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
toBoolean(): boolean {
|
|
152
|
-
const value = this.trim().toLowerCase();
|
|
153
|
-
return value === "true" || value === "1" || value === "yes" || value === "on";
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
toArray(): string[] {
|
|
157
|
-
return this.chars();
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
toJSON(): string {
|
|
161
|
-
return JSON.stringify(this.toString());
|
|
162
|
-
}
|
|
163
|
-
isWellFormed(): boolean {
|
|
164
|
-
return !/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/u.test(this.toString());
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
toWellFormed(): string {
|
|
168
|
-
return this.toString().replace(
|
|
169
|
-
/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/gu,
|
|
170
|
-
"\uFFFD",
|
|
171
|
-
);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
globalThis.S2 = S2I ;
|
package/src/unit8array.js
DELETED
|
@@ -1,272 +0,0 @@
|
|
|
1
|
-
export class U82I extends Array {
|
|
2
|
-
constructor(...items) {
|
|
3
|
-
super(...items);
|
|
4
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
5
|
-
}
|
|
6
|
-
static get [Symbol.species]() {
|
|
7
|
-
return Array;
|
|
8
|
-
}
|
|
9
|
-
static from(iterable, mapFn, thisArg) {
|
|
10
|
-
const values = Symbol.iterator in Object(iterable)
|
|
11
|
-
? Array.from(iterable)
|
|
12
|
-
: Array.from(iterable);
|
|
13
|
-
const result = mapFn
|
|
14
|
-
? values.map((value, index) => mapFn.call(thisArg, value, index))
|
|
15
|
-
: values;
|
|
16
|
-
return new U82I(...result);
|
|
17
|
-
}
|
|
18
|
-
static of(...items) {
|
|
19
|
-
return new U82I(...items);
|
|
20
|
-
}
|
|
21
|
-
first() {
|
|
22
|
-
return this[0];
|
|
23
|
-
}
|
|
24
|
-
last() {
|
|
25
|
-
return this[this.length - 1];
|
|
26
|
-
}
|
|
27
|
-
second() {
|
|
28
|
-
return this[1];
|
|
29
|
-
}
|
|
30
|
-
third() {
|
|
31
|
-
return this[2];
|
|
32
|
-
}
|
|
33
|
-
random() {
|
|
34
|
-
return this.length ? this[Math.floor(Math.random() * this.length)] : undefined;
|
|
35
|
-
}
|
|
36
|
-
isEmpty() {
|
|
37
|
-
return this.length === 0;
|
|
38
|
-
}
|
|
39
|
-
isNotEmpty() {
|
|
40
|
-
return this.length > 0;
|
|
41
|
-
}
|
|
42
|
-
isNotEmptyAndDefined() {
|
|
43
|
-
return this.some(value => value !== undefined && value !== null);
|
|
44
|
-
}
|
|
45
|
-
clear() {
|
|
46
|
-
this.length = 0;
|
|
47
|
-
return this;
|
|
48
|
-
}
|
|
49
|
-
clone() {
|
|
50
|
-
return new U82I(...this);
|
|
51
|
-
}
|
|
52
|
-
unique() {
|
|
53
|
-
return new U82I(...new Set(this));
|
|
54
|
-
}
|
|
55
|
-
compact() {
|
|
56
|
-
return new U82I(...this.filter((value) => value != null));
|
|
57
|
-
}
|
|
58
|
-
chunk(size) {
|
|
59
|
-
if (size <= 0)
|
|
60
|
-
throw new RangeError("Chunk size must be greater than zero");
|
|
61
|
-
const result = new U82I();
|
|
62
|
-
for (let i = 0; i < this.length; i += size) {
|
|
63
|
-
result.push(new U82I(...this.slice(i, i + size)));
|
|
64
|
-
}
|
|
65
|
-
return result;
|
|
66
|
-
}
|
|
67
|
-
flatten(depth) {
|
|
68
|
-
return new U82I(...this.flat(depth));
|
|
69
|
-
}
|
|
70
|
-
shuffle() {
|
|
71
|
-
return this.shuffleInPlace();
|
|
72
|
-
}
|
|
73
|
-
sample(count = 1) {
|
|
74
|
-
return this.pick(count);
|
|
75
|
-
}
|
|
76
|
-
count(predicate) {
|
|
77
|
-
return (predicate ? this.filter(predicate).length : this.length);
|
|
78
|
-
}
|
|
79
|
-
sum() {
|
|
80
|
-
return this.reduce((total, value) => total + value, 0);
|
|
81
|
-
}
|
|
82
|
-
average() {
|
|
83
|
-
return this.length ? this.sum() / this.length : 0;
|
|
84
|
-
}
|
|
85
|
-
min() {
|
|
86
|
-
return this.length ? Math.min(...this) : undefined;
|
|
87
|
-
}
|
|
88
|
-
max() {
|
|
89
|
-
return this.length ? Math.max(...this) : undefined;
|
|
90
|
-
}
|
|
91
|
-
groupBy(keyFn) {
|
|
92
|
-
const result = new Map();
|
|
93
|
-
this.forEach((value, index) => {
|
|
94
|
-
const key = keyFn(value, index);
|
|
95
|
-
if (!result.has(key))
|
|
96
|
-
result.set(key, new U82I());
|
|
97
|
-
result.get(key).push(value);
|
|
98
|
-
});
|
|
99
|
-
return result;
|
|
100
|
-
}
|
|
101
|
-
keyBy(keyFn) {
|
|
102
|
-
const result = new Map();
|
|
103
|
-
this.forEach((value, index) => result.set(keyFn(value, index), value));
|
|
104
|
-
return result;
|
|
105
|
-
}
|
|
106
|
-
partition(predicate) {
|
|
107
|
-
const yes = new U82I();
|
|
108
|
-
const no = new U82I();
|
|
109
|
-
this.forEach((value, index, array) => {
|
|
110
|
-
(predicate(value, index, array) ? yes : no).push(value);
|
|
111
|
-
});
|
|
112
|
-
return [yes, no];
|
|
113
|
-
}
|
|
114
|
-
difference(other) {
|
|
115
|
-
const values = new Set(other);
|
|
116
|
-
return new U82I(...this.filter(value => !values.has(value)));
|
|
117
|
-
}
|
|
118
|
-
intersection(other) {
|
|
119
|
-
const values = new Set(other);
|
|
120
|
-
return new U82I(...this.filter(value => values.has(value)));
|
|
121
|
-
}
|
|
122
|
-
union(other) {
|
|
123
|
-
return new U82I(...new Set([...this, ...other]));
|
|
124
|
-
}
|
|
125
|
-
symmetricDifference(other) {
|
|
126
|
-
const values = new Set(other);
|
|
127
|
-
const own = new Set(this);
|
|
128
|
-
return new U82I(...[...this.filter(value => !values.has(value)), ...Array.from(values).filter(value => !own.has(value))]);
|
|
129
|
-
}
|
|
130
|
-
take(count) {
|
|
131
|
-
return new U82I(...this.slice(0, Math.max(0, count)));
|
|
132
|
-
}
|
|
133
|
-
takeLast(count) {
|
|
134
|
-
return new U82I(...this.slice(-Math.max(0, count)));
|
|
135
|
-
}
|
|
136
|
-
drop(count) {
|
|
137
|
-
return new U82I(...this.slice(Math.max(0, count)));
|
|
138
|
-
}
|
|
139
|
-
dropLast(count) {
|
|
140
|
-
return new U82I(...this.slice(0, Math.max(0, this.length - count)));
|
|
141
|
-
}
|
|
142
|
-
pluck(key) {
|
|
143
|
-
return new U82I(...this.map(value => value[key]));
|
|
144
|
-
}
|
|
145
|
-
flattenDeep() {
|
|
146
|
-
return new U82I(...this.flat(Infinity));
|
|
147
|
-
}
|
|
148
|
-
insert(index, ...items) {
|
|
149
|
-
this.splice(index, 0, ...items);
|
|
150
|
-
return this;
|
|
151
|
-
}
|
|
152
|
-
removeAt(index) {
|
|
153
|
-
if (index < 0 || index >= this.length)
|
|
154
|
-
return undefined;
|
|
155
|
-
return this.splice(index, 1)[0];
|
|
156
|
-
}
|
|
157
|
-
remove(value) {
|
|
158
|
-
const index = this.indexOf(value);
|
|
159
|
-
if (index === -1)
|
|
160
|
-
return false;
|
|
161
|
-
this.splice(index, 1);
|
|
162
|
-
return true;
|
|
163
|
-
}
|
|
164
|
-
removeWhere(predicate) {
|
|
165
|
-
for (let i = this.length - 1; i >= 0; i--) {
|
|
166
|
-
if (predicate(this[i], i, this))
|
|
167
|
-
this.splice(i, 1);
|
|
168
|
-
}
|
|
169
|
-
return this;
|
|
170
|
-
}
|
|
171
|
-
replace(oldValue, newValue) {
|
|
172
|
-
const index = this.indexOf(oldValue);
|
|
173
|
-
if (index === -1)
|
|
174
|
-
return false;
|
|
175
|
-
this[index] = newValue;
|
|
176
|
-
return true;
|
|
177
|
-
}
|
|
178
|
-
move(from, to) {
|
|
179
|
-
if (from < 0 || from >= this.length || to < 0 || to >= this.length)
|
|
180
|
-
return this;
|
|
181
|
-
const [value] = this.splice(from, 1);
|
|
182
|
-
this.splice(to, 0, value);
|
|
183
|
-
return this;
|
|
184
|
-
}
|
|
185
|
-
swap(i, j) {
|
|
186
|
-
if (i < 0 || j < 0 || i >= this.length || j >= this.length)
|
|
187
|
-
return this;
|
|
188
|
-
[this[i], this[j]] = [this[j], this[i]];
|
|
189
|
-
return this;
|
|
190
|
-
}
|
|
191
|
-
shuffleInPlace() {
|
|
192
|
-
for (let i = this.length - 1; i > 0; i--) {
|
|
193
|
-
const j = Math.floor(Math.random() * (i + 1));
|
|
194
|
-
[this[i], this[j]] = [this[j], this[i]];
|
|
195
|
-
}
|
|
196
|
-
return this;
|
|
197
|
-
}
|
|
198
|
-
pick(count = 1) {
|
|
199
|
-
const values = [...this];
|
|
200
|
-
const result = new U82I();
|
|
201
|
-
for (let i = 0; i < Math.min(Math.max(0, count), values.length); i++) {
|
|
202
|
-
const j = Math.floor(Math.random() * values.length);
|
|
203
|
-
result.push(values.splice(j, 1)[0]);
|
|
204
|
-
}
|
|
205
|
-
return result;
|
|
206
|
-
}
|
|
207
|
-
toSet() {
|
|
208
|
-
return new Set(this);
|
|
209
|
-
}
|
|
210
|
-
toMap(keyFn) {
|
|
211
|
-
return this.keyBy(keyFn);
|
|
212
|
-
}
|
|
213
|
-
equals(other) {
|
|
214
|
-
return this.length === other.length && this.every((value, index) => Object.is(value, other[index]));
|
|
215
|
-
}
|
|
216
|
-
startsWith(other) {
|
|
217
|
-
return other.length <= this.length && other.every((value, index) => Object.is(this[index], value));
|
|
218
|
-
}
|
|
219
|
-
endsWith(other) {
|
|
220
|
-
return (other.length <= this.length &&
|
|
221
|
-
other.every((value, index) => Object.is(this[this.length - other.length + index], value)));
|
|
222
|
-
}
|
|
223
|
-
isSorted(compareFn = ((a, b) => (a < b ? -1 : a > b ? 1 : 0))) {
|
|
224
|
-
for (let i = 1; i < this.length; i++) {
|
|
225
|
-
if (compareFn(this[i - 1], this[i]) > 0)
|
|
226
|
-
return false;
|
|
227
|
-
}
|
|
228
|
-
return true;
|
|
229
|
-
}
|
|
230
|
-
frequencies() {
|
|
231
|
-
const result = new Map();
|
|
232
|
-
for (const value of this) {
|
|
233
|
-
result.set(value, ((result.get(value) ?? 0) + 1));
|
|
234
|
-
}
|
|
235
|
-
return result;
|
|
236
|
-
}
|
|
237
|
-
findLast(predicate, thisArg) {
|
|
238
|
-
for (let i = this.length - 1; i >= 0; i--) {
|
|
239
|
-
if (predicate.call(thisArg, this[i], i, this))
|
|
240
|
-
return this[i];
|
|
241
|
-
}
|
|
242
|
-
return undefined;
|
|
243
|
-
}
|
|
244
|
-
findLastIndex(predicate, thisArg) {
|
|
245
|
-
for (let i = this.length - 1; i >= 0; i--) {
|
|
246
|
-
if (predicate.call(thisArg, this[i], i, this))
|
|
247
|
-
return i;
|
|
248
|
-
}
|
|
249
|
-
return -1;
|
|
250
|
-
}
|
|
251
|
-
toReversed() {
|
|
252
|
-
return [...this].reverse();
|
|
253
|
-
}
|
|
254
|
-
toSorted(compareFn) {
|
|
255
|
-
return [...this].sort(compareFn);
|
|
256
|
-
}
|
|
257
|
-
toSpliced(start, deleteCount, ...items) {
|
|
258
|
-
const result = [...this];
|
|
259
|
-
result.splice(start, deleteCount, ...items);
|
|
260
|
-
return result;
|
|
261
|
-
}
|
|
262
|
-
with(index, value) {
|
|
263
|
-
const result = [...this];
|
|
264
|
-
const actualIndex = index < 0 ? result.length + index : index;
|
|
265
|
-
if (actualIndex < 0 || actualIndex >= result.length) {
|
|
266
|
-
throw new RangeError("Invalid index");
|
|
267
|
-
}
|
|
268
|
-
result[actualIndex] = value;
|
|
269
|
-
return result;
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
globalThis.U82 = U82I;
|