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