@abp/utils 9.3.0-rc.3 → 9.3.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/dist/{fesm2015/abp-utils.js → fesm2022/abp-utils.mjs} +294 -291
- package/dist/fesm2022/abp-utils.mjs.map +1 -0
- package/dist/{lib/linked-list.d.ts → index.d.ts} +83 -80
- package/package.json +19 -23
- package/dist/abp-utils.d.ts +0 -4
- package/dist/abp-utils.metadata.json +0 -1
- package/dist/bundles/abp-utils.umd.js +0 -694
- package/dist/bundles/abp-utils.umd.js.map +0 -1
- package/dist/bundles/abp-utils.umd.min.js +0 -2
- package/dist/bundles/abp-utils.umd.min.js.map +0 -1
- package/dist/esm2015/abp-utils.js +0 -5
- package/dist/esm2015/lib/linked-list.js +0 -289
- package/dist/esm2015/public-api.js +0 -5
- package/dist/fesm2015/abp-utils.js.map +0 -1
- package/dist/package.json +0 -42
- package/dist/public-api.d.ts +0 -1
- package/ngcc.config.js +0 -6
|
@@ -1,300 +1,303 @@
|
|
|
1
1
|
import compare from 'just-compare';
|
|
2
2
|
|
|
3
|
-
/* tslint:disable:no-non-null-assertion */
|
|
4
|
-
class ListNode {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
get
|
|
17
|
-
return this.
|
|
18
|
-
}
|
|
19
|
-
get
|
|
20
|
-
return this.
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
node
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
list.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
node.next
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
this.
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
return
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
return
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
return this.
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
return
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
3
|
+
/* tslint:disable:no-non-null-assertion */
|
|
4
|
+
class ListNode {
|
|
5
|
+
value;
|
|
6
|
+
next;
|
|
7
|
+
previous;
|
|
8
|
+
constructor(value) {
|
|
9
|
+
this.value = value;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
class LinkedList {
|
|
13
|
+
first;
|
|
14
|
+
last;
|
|
15
|
+
size = 0;
|
|
16
|
+
get head() {
|
|
17
|
+
return this.first;
|
|
18
|
+
}
|
|
19
|
+
get tail() {
|
|
20
|
+
return this.last;
|
|
21
|
+
}
|
|
22
|
+
get length() {
|
|
23
|
+
return this.size;
|
|
24
|
+
}
|
|
25
|
+
attach(value, previousNode, nextNode) {
|
|
26
|
+
if (!previousNode)
|
|
27
|
+
return this.addHead(value);
|
|
28
|
+
if (!nextNode)
|
|
29
|
+
return this.addTail(value);
|
|
30
|
+
const node = new ListNode(value);
|
|
31
|
+
node.previous = previousNode;
|
|
32
|
+
previousNode.next = node;
|
|
33
|
+
node.next = nextNode;
|
|
34
|
+
nextNode.previous = node;
|
|
35
|
+
this.size++;
|
|
36
|
+
return node;
|
|
37
|
+
}
|
|
38
|
+
attachMany(values, previousNode, nextNode) {
|
|
39
|
+
if (!values.length)
|
|
40
|
+
return [];
|
|
41
|
+
if (!previousNode)
|
|
42
|
+
return this.addManyHead(values);
|
|
43
|
+
if (!nextNode)
|
|
44
|
+
return this.addManyTail(values);
|
|
45
|
+
const list = new LinkedList();
|
|
46
|
+
list.addManyTail(values);
|
|
47
|
+
list.first.previous = previousNode;
|
|
48
|
+
previousNode.next = list.first;
|
|
49
|
+
list.last.next = nextNode;
|
|
50
|
+
nextNode.previous = list.last;
|
|
51
|
+
this.size += values.length;
|
|
52
|
+
return list.toNodeArray();
|
|
53
|
+
}
|
|
54
|
+
detach(node) {
|
|
55
|
+
if (!node.previous)
|
|
56
|
+
return this.dropHead();
|
|
57
|
+
if (!node.next)
|
|
58
|
+
return this.dropTail();
|
|
59
|
+
node.previous.next = node.next;
|
|
60
|
+
node.next.previous = node.previous;
|
|
61
|
+
this.size--;
|
|
62
|
+
return node;
|
|
63
|
+
}
|
|
64
|
+
add(value) {
|
|
65
|
+
return {
|
|
66
|
+
after: (...params) => this.addAfter.call(this, value, ...params),
|
|
67
|
+
before: (...params) => this.addBefore.call(this, value, ...params),
|
|
68
|
+
byIndex: (position) => this.addByIndex(value, position),
|
|
69
|
+
head: () => this.addHead(value),
|
|
70
|
+
tail: () => this.addTail(value),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
addMany(values) {
|
|
74
|
+
return {
|
|
75
|
+
after: (...params) => this.addManyAfter.call(this, values, ...params),
|
|
76
|
+
before: (...params) => this.addManyBefore.call(this, values, ...params),
|
|
77
|
+
byIndex: (position) => this.addManyByIndex(values, position),
|
|
78
|
+
head: () => this.addManyHead(values),
|
|
79
|
+
tail: () => this.addManyTail(values),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
addAfter(value, previousValue, compareFn = compare) {
|
|
83
|
+
const previous = this.find(node => compareFn(node.value, previousValue));
|
|
84
|
+
return previous ? this.attach(value, previous, previous.next) : this.addTail(value);
|
|
85
|
+
}
|
|
86
|
+
addBefore(value, nextValue, compareFn = compare) {
|
|
87
|
+
const next = this.find(node => compareFn(node.value, nextValue));
|
|
88
|
+
return next ? this.attach(value, next.previous, next) : this.addHead(value);
|
|
89
|
+
}
|
|
90
|
+
addByIndex(value, position) {
|
|
91
|
+
if (position < 0)
|
|
92
|
+
position += this.size;
|
|
93
|
+
else if (position >= this.size)
|
|
94
|
+
return this.addTail(value);
|
|
95
|
+
if (position <= 0)
|
|
96
|
+
return this.addHead(value);
|
|
97
|
+
const next = this.get(position);
|
|
98
|
+
return this.attach(value, next.previous, next);
|
|
99
|
+
}
|
|
100
|
+
addHead(value) {
|
|
101
|
+
const node = new ListNode(value);
|
|
102
|
+
node.next = this.first;
|
|
103
|
+
if (this.first)
|
|
104
|
+
this.first.previous = node;
|
|
105
|
+
else
|
|
106
|
+
this.last = node;
|
|
107
|
+
this.first = node;
|
|
108
|
+
this.size++;
|
|
109
|
+
return node;
|
|
110
|
+
}
|
|
111
|
+
addTail(value) {
|
|
112
|
+
const node = new ListNode(value);
|
|
113
|
+
if (this.first) {
|
|
114
|
+
node.previous = this.last;
|
|
115
|
+
this.last.next = node;
|
|
116
|
+
this.last = node;
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
this.first = node;
|
|
120
|
+
this.last = node;
|
|
121
|
+
}
|
|
122
|
+
this.size++;
|
|
123
|
+
return node;
|
|
124
|
+
}
|
|
125
|
+
addManyAfter(values, previousValue, compareFn = compare) {
|
|
126
|
+
const previous = this.find(node => compareFn(node.value, previousValue));
|
|
127
|
+
return previous ? this.attachMany(values, previous, previous.next) : this.addManyTail(values);
|
|
128
|
+
}
|
|
129
|
+
addManyBefore(values, nextValue, compareFn = compare) {
|
|
130
|
+
const next = this.find(node => compareFn(node.value, nextValue));
|
|
131
|
+
return next ? this.attachMany(values, next.previous, next) : this.addManyHead(values);
|
|
132
|
+
}
|
|
133
|
+
addManyByIndex(values, position) {
|
|
134
|
+
if (position < 0)
|
|
135
|
+
position += this.size;
|
|
136
|
+
if (position <= 0)
|
|
137
|
+
return this.addManyHead(values);
|
|
138
|
+
if (position >= this.size)
|
|
139
|
+
return this.addManyTail(values);
|
|
140
|
+
const next = this.get(position);
|
|
141
|
+
return this.attachMany(values, next.previous, next);
|
|
142
|
+
}
|
|
143
|
+
addManyHead(values) {
|
|
144
|
+
return values.reduceRight((nodes, value) => {
|
|
145
|
+
nodes.unshift(this.addHead(value));
|
|
146
|
+
return nodes;
|
|
147
|
+
}, []);
|
|
148
|
+
}
|
|
149
|
+
addManyTail(values) {
|
|
150
|
+
return values.map(value => this.addTail(value));
|
|
151
|
+
}
|
|
152
|
+
drop() {
|
|
153
|
+
return {
|
|
154
|
+
byIndex: (position) => this.dropByIndex(position),
|
|
155
|
+
byValue: (...params) => this.dropByValue.apply(this, params),
|
|
156
|
+
byValueAll: (...params) => this.dropByValueAll.apply(this, params),
|
|
157
|
+
head: () => this.dropHead(),
|
|
158
|
+
tail: () => this.dropTail(),
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
dropMany(count) {
|
|
162
|
+
return {
|
|
163
|
+
byIndex: (position) => this.dropManyByIndex(count, position),
|
|
164
|
+
head: () => this.dropManyHead(count),
|
|
165
|
+
tail: () => this.dropManyTail(count),
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
dropByIndex(position) {
|
|
169
|
+
if (position < 0)
|
|
170
|
+
position += this.size;
|
|
171
|
+
const current = this.get(position);
|
|
172
|
+
return current ? this.detach(current) : undefined;
|
|
173
|
+
}
|
|
174
|
+
dropByValue(value, compareFn = compare) {
|
|
175
|
+
const position = this.findIndex(node => compareFn(node.value, value));
|
|
176
|
+
return position < 0 ? undefined : this.dropByIndex(position);
|
|
177
|
+
}
|
|
178
|
+
dropByValueAll(value, compareFn = compare) {
|
|
179
|
+
const dropped = [];
|
|
180
|
+
for (let current = this.first, position = 0; current; position++, current = current.next) {
|
|
181
|
+
if (compareFn(current.value, value)) {
|
|
182
|
+
dropped.push(this.dropByIndex(position - dropped.length));
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return dropped;
|
|
186
|
+
}
|
|
187
|
+
dropHead() {
|
|
188
|
+
const head = this.first;
|
|
189
|
+
if (head) {
|
|
190
|
+
this.first = head.next;
|
|
191
|
+
if (this.first)
|
|
192
|
+
this.first.previous = undefined;
|
|
193
|
+
else
|
|
194
|
+
this.last = undefined;
|
|
195
|
+
this.size--;
|
|
196
|
+
return head;
|
|
197
|
+
}
|
|
198
|
+
return undefined;
|
|
199
|
+
}
|
|
200
|
+
dropTail() {
|
|
201
|
+
const tail = this.last;
|
|
202
|
+
if (tail) {
|
|
203
|
+
this.last = tail.previous;
|
|
204
|
+
if (this.last)
|
|
205
|
+
this.last.next = undefined;
|
|
206
|
+
else
|
|
207
|
+
this.first = undefined;
|
|
208
|
+
this.size--;
|
|
209
|
+
return tail;
|
|
210
|
+
}
|
|
211
|
+
return undefined;
|
|
212
|
+
}
|
|
213
|
+
dropManyByIndex(count, position) {
|
|
214
|
+
if (count <= 0)
|
|
215
|
+
return [];
|
|
216
|
+
if (position < 0)
|
|
217
|
+
position = Math.max(position + this.size, 0);
|
|
218
|
+
else if (position >= this.size)
|
|
219
|
+
return [];
|
|
220
|
+
count = Math.min(count, this.size - position);
|
|
221
|
+
const dropped = [];
|
|
222
|
+
while (count--) {
|
|
223
|
+
const current = this.get(position);
|
|
224
|
+
dropped.push(this.detach(current));
|
|
225
|
+
}
|
|
226
|
+
return dropped;
|
|
227
|
+
}
|
|
228
|
+
dropManyHead(count) {
|
|
229
|
+
if (count <= 0)
|
|
230
|
+
return [];
|
|
231
|
+
count = Math.min(count, this.size);
|
|
232
|
+
const dropped = [];
|
|
233
|
+
while (count--)
|
|
234
|
+
dropped.unshift(this.dropHead());
|
|
235
|
+
return dropped;
|
|
236
|
+
}
|
|
237
|
+
dropManyTail(count) {
|
|
238
|
+
if (count <= 0)
|
|
239
|
+
return [];
|
|
240
|
+
count = Math.min(count, this.size);
|
|
241
|
+
const dropped = [];
|
|
242
|
+
while (count--)
|
|
243
|
+
dropped.push(this.dropTail());
|
|
244
|
+
return dropped;
|
|
245
|
+
}
|
|
246
|
+
find(predicate) {
|
|
247
|
+
for (let current = this.first, position = 0; current; position++, current = current.next) {
|
|
248
|
+
if (predicate(current, position, this))
|
|
249
|
+
return current;
|
|
250
|
+
}
|
|
251
|
+
return undefined;
|
|
252
|
+
}
|
|
253
|
+
findIndex(predicate) {
|
|
254
|
+
for (let current = this.first, position = 0; current; position++, current = current.next) {
|
|
255
|
+
if (predicate(current, position, this))
|
|
256
|
+
return position;
|
|
257
|
+
}
|
|
258
|
+
return -1;
|
|
259
|
+
}
|
|
260
|
+
forEach(iteratorFn) {
|
|
261
|
+
for (let node = this.first, position = 0; node; position++, node = node.next) {
|
|
262
|
+
iteratorFn(node, position, this);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
get(position) {
|
|
266
|
+
return this.find((_, index) => position === index);
|
|
267
|
+
}
|
|
268
|
+
indexOf(value, compareFn = compare) {
|
|
269
|
+
return this.findIndex(node => compareFn(node.value, value));
|
|
270
|
+
}
|
|
271
|
+
toArray() {
|
|
272
|
+
const array = new Array(this.size);
|
|
273
|
+
this.forEach((node, index) => (array[index] = node.value));
|
|
274
|
+
return array;
|
|
275
|
+
}
|
|
276
|
+
toNodeArray() {
|
|
277
|
+
const array = new Array(this.size);
|
|
278
|
+
this.forEach((node, index) => (array[index] = node));
|
|
279
|
+
return array;
|
|
280
|
+
}
|
|
281
|
+
toString(mapperFn = JSON.stringify) {
|
|
282
|
+
return this.toArray()
|
|
283
|
+
.map(value => mapperFn(value))
|
|
284
|
+
.join(' <-> ');
|
|
285
|
+
}
|
|
286
|
+
// Cannot use Generator type because of ng-packagr
|
|
287
|
+
*[Symbol.iterator]() {
|
|
288
|
+
for (let node = this.first, position = 0; node; position++, node = node.next) {
|
|
289
|
+
yield node.value;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
289
292
|
}
|
|
290
293
|
|
|
291
|
-
/*
|
|
292
|
-
* Public API Surface of utils
|
|
294
|
+
/*
|
|
295
|
+
* Public API Surface of utils
|
|
293
296
|
*/
|
|
294
297
|
|
|
295
|
-
/**
|
|
296
|
-
* Generated bundle index. Do not edit.
|
|
298
|
+
/**
|
|
299
|
+
* Generated bundle index. Do not edit.
|
|
297
300
|
*/
|
|
298
301
|
|
|
299
302
|
export { LinkedList, ListNode };
|
|
300
|
-
//# sourceMappingURL=abp-utils.
|
|
303
|
+
//# sourceMappingURL=abp-utils.mjs.map
|