@etsoo/shared 1.2.50 → 1.2.51
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/__tests__/ArrayUtils.ts
CHANGED
|
@@ -65,8 +65,9 @@ test('Tests for maxItem / minItem', () => {
|
|
|
65
65
|
|
|
66
66
|
test('Tests for remove simple', () => {
|
|
67
67
|
const items = [1, 2, 3, 4, 5];
|
|
68
|
-
items.remove(1, 5, (item) => item % 2 === 0);
|
|
68
|
+
const result = items.remove(1, 5, (item) => item % 2 === 0);
|
|
69
69
|
expect(items).toStrictEqual([3]);
|
|
70
|
+
expect(result.length).toBe(4);
|
|
70
71
|
});
|
|
71
72
|
|
|
72
73
|
test('Tests for remove object', () => {
|
|
@@ -78,7 +79,7 @@ test('Tests for remove object', () => {
|
|
|
78
79
|
item
|
|
79
80
|
];
|
|
80
81
|
|
|
81
|
-
items.remove(
|
|
82
|
+
const result = items.remove(
|
|
82
83
|
item,
|
|
83
84
|
(item) => item.id === 2,
|
|
84
85
|
(item) => item.amount <= 2
|
|
@@ -86,6 +87,7 @@ test('Tests for remove object', () => {
|
|
|
86
87
|
|
|
87
88
|
expect(items.length).toBe(1);
|
|
88
89
|
expect(items[0].id).toBe(1);
|
|
90
|
+
expect(result.length).toBe(3);
|
|
89
91
|
});
|
|
90
92
|
|
|
91
93
|
test('Tests for sortIds 1', () => {
|
package/lib/cjs/ArrayUtils.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ declare global {
|
|
|
31
31
|
* Remove items by value or condition
|
|
32
32
|
* @param items Items to remove
|
|
33
33
|
*/
|
|
34
|
-
remove(...items: ((T & (DataTypes.Basic | object)) | ((item: T) => boolean))[]):
|
|
34
|
+
remove(...items: ((T & (DataTypes.Basic | object)) | ((item: T) => boolean))[]): T[];
|
|
35
35
|
/**
|
|
36
36
|
* Sort by property
|
|
37
37
|
* @param property Property
|
package/lib/cjs/ArrayUtils.js
CHANGED
|
@@ -43,6 +43,7 @@ Array.prototype.minItem = function (field) {
|
|
|
43
43
|
};
|
|
44
44
|
Array.prototype.remove = function (...items) {
|
|
45
45
|
const funs = [];
|
|
46
|
+
const results = [];
|
|
46
47
|
items.forEach((item) => {
|
|
47
48
|
if (typeof item === 'function') {
|
|
48
49
|
funs.push(item);
|
|
@@ -51,16 +52,17 @@ Array.prototype.remove = function (...items) {
|
|
|
51
52
|
// For object items, should be removed by reference, not by value
|
|
52
53
|
const index = this.indexOf(item);
|
|
53
54
|
if (index >= 0)
|
|
54
|
-
this.splice(index, 1);
|
|
55
|
+
results.push(...this.splice(index, 1));
|
|
55
56
|
}
|
|
56
57
|
});
|
|
57
58
|
if (funs.length > 0) {
|
|
58
59
|
// Reduce check loops for performance
|
|
59
60
|
for (let i = this.length - 1; i >= 0; i--) {
|
|
60
61
|
if (funs.some((fun) => fun(this[i])))
|
|
61
|
-
this.splice(i, 1);
|
|
62
|
+
results.push(...this.splice(i, 1));
|
|
62
63
|
}
|
|
63
64
|
}
|
|
65
|
+
return results;
|
|
64
66
|
};
|
|
65
67
|
Array.prototype.sortByProperty = function (property, values) {
|
|
66
68
|
return this.sort((a, b) => {
|
package/lib/mjs/ArrayUtils.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ declare global {
|
|
|
31
31
|
* Remove items by value or condition
|
|
32
32
|
* @param items Items to remove
|
|
33
33
|
*/
|
|
34
|
-
remove(...items: ((T & (DataTypes.Basic | object)) | ((item: T) => boolean))[]):
|
|
34
|
+
remove(...items: ((T & (DataTypes.Basic | object)) | ((item: T) => boolean))[]): T[];
|
|
35
35
|
/**
|
|
36
36
|
* Sort by property
|
|
37
37
|
* @param property Property
|
package/lib/mjs/ArrayUtils.js
CHANGED
|
@@ -37,6 +37,7 @@ Array.prototype.minItem = function (field) {
|
|
|
37
37
|
};
|
|
38
38
|
Array.prototype.remove = function (...items) {
|
|
39
39
|
const funs = [];
|
|
40
|
+
const results = [];
|
|
40
41
|
items.forEach((item) => {
|
|
41
42
|
if (typeof item === 'function') {
|
|
42
43
|
funs.push(item);
|
|
@@ -45,16 +46,17 @@ Array.prototype.remove = function (...items) {
|
|
|
45
46
|
// For object items, should be removed by reference, not by value
|
|
46
47
|
const index = this.indexOf(item);
|
|
47
48
|
if (index >= 0)
|
|
48
|
-
this.splice(index, 1);
|
|
49
|
+
results.push(...this.splice(index, 1));
|
|
49
50
|
}
|
|
50
51
|
});
|
|
51
52
|
if (funs.length > 0) {
|
|
52
53
|
// Reduce check loops for performance
|
|
53
54
|
for (let i = this.length - 1; i >= 0; i--) {
|
|
54
55
|
if (funs.some((fun) => fun(this[i])))
|
|
55
|
-
this.splice(i, 1);
|
|
56
|
+
results.push(...this.splice(i, 1));
|
|
56
57
|
}
|
|
57
58
|
}
|
|
59
|
+
return results;
|
|
58
60
|
};
|
|
59
61
|
Array.prototype.sortByProperty = function (property, values) {
|
|
60
62
|
return this.sort((a, b) => {
|
package/package.json
CHANGED
package/src/ArrayUtils.ts
CHANGED
|
@@ -59,7 +59,7 @@ declare global {
|
|
|
59
59
|
| (T & (DataTypes.Basic | object))
|
|
60
60
|
| ((item: T) => boolean)
|
|
61
61
|
)[]
|
|
62
|
-
):
|
|
62
|
+
): T[];
|
|
63
63
|
|
|
64
64
|
/**
|
|
65
65
|
* Sort by property
|
|
@@ -157,22 +157,26 @@ Array.prototype.remove = function <T>(
|
|
|
157
157
|
...items: ((T & (DataTypes.Basic | object)) | ((item: T) => boolean))[]
|
|
158
158
|
) {
|
|
159
159
|
const funs: ((item: T) => boolean)[] = [];
|
|
160
|
+
const results: T[] = [];
|
|
160
161
|
items.forEach((item) => {
|
|
161
162
|
if (typeof item === 'function') {
|
|
162
163
|
funs.push(item);
|
|
163
164
|
} else {
|
|
164
165
|
// For object items, should be removed by reference, not by value
|
|
165
166
|
const index = this.indexOf(item);
|
|
166
|
-
if (index >= 0) this.splice(index, 1);
|
|
167
|
+
if (index >= 0) results.push(...this.splice(index, 1));
|
|
167
168
|
}
|
|
168
169
|
});
|
|
169
170
|
|
|
170
171
|
if (funs.length > 0) {
|
|
171
172
|
// Reduce check loops for performance
|
|
172
173
|
for (let i = this.length - 1; i >= 0; i--) {
|
|
173
|
-
if (funs.some((fun) => fun(this[i])))
|
|
174
|
+
if (funs.some((fun) => fun(this[i])))
|
|
175
|
+
results.push(...this.splice(i, 1));
|
|
174
176
|
}
|
|
175
177
|
}
|
|
178
|
+
|
|
179
|
+
return results;
|
|
176
180
|
};
|
|
177
181
|
|
|
178
182
|
Array.prototype.sortByProperty = function <T, P extends keyof T>(
|