@etsoo/shared 1.2.69 → 1.2.70
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.md +11 -10
- package/__tests__/ArrayUtils.ts +9 -0
- package/lib/cjs/ArrayUtils.d.ts +7 -0
- package/lib/cjs/ArrayUtils.js +20 -0
- package/lib/mjs/ArrayUtils.d.ts +7 -0
- package/lib/mjs/ArrayUtils.js +20 -0
- package/package.json +3 -3
- package/src/ArrayUtils.ts +22 -0
package/README.md
CHANGED
|
@@ -112,16 +112,17 @@ ETSOO Extended abstract history class
|
|
|
112
112
|
|
|
113
113
|
Array related utilities
|
|
114
114
|
|
|
115
|
-
| Name | Description
|
|
116
|
-
| ----------: |
|
|
117
|
-
| differences | Array 1 items do not exist in Array 2 or reverse match
|
|
118
|
-
| max | Get max number item or number item property
|
|
119
|
-
| maxItem | Get max field value item
|
|
120
|
-
|
|
|
121
|
-
|
|
|
122
|
-
|
|
|
123
|
-
|
|
|
124
|
-
|
|
|
115
|
+
| Name | Description |
|
|
116
|
+
| ----------: | ------------------------------------------------------------ |
|
|
117
|
+
| differences | Array 1 items do not exist in Array 2 or reverse match |
|
|
118
|
+
| max | Get max number item or number item property |
|
|
119
|
+
| maxItem | Get max field value item |
|
|
120
|
+
| mergeArrays | Merge arrays, remove duplicates, and sort by the first array |
|
|
121
|
+
| min | Get min number item or number item property |
|
|
122
|
+
| minItem | Get min field value item |
|
|
123
|
+
| remove | Remove items by value or condition |
|
|
124
|
+
| sum | Sum number items or number item properties |
|
|
125
|
+
| toUnique | Make all items are unique |
|
|
125
126
|
|
|
126
127
|
## DataTypes
|
|
127
128
|
|
package/__tests__/ArrayUtils.ts
CHANGED
|
@@ -63,6 +63,15 @@ test("Tests for maxItem / minItem", () => {
|
|
|
63
63
|
expect(emptyItems.maxItem("amount")).toBeUndefined();
|
|
64
64
|
});
|
|
65
65
|
|
|
66
|
+
test("Tests for mergeArrays", () => {
|
|
67
|
+
const a1 = ["e", "a", "c"];
|
|
68
|
+
const a2 = ["a", "c", "d"];
|
|
69
|
+
const a3 = ["b", "c", "f"];
|
|
70
|
+
const result = ArrayUtils.mergeArrays(a1, a2, a3);
|
|
71
|
+
expect(result).toEqual(["e", "a", "c", "d", "b", "f"]);
|
|
72
|
+
expect(result.length).toBe(6);
|
|
73
|
+
});
|
|
74
|
+
|
|
66
75
|
test("Tests for remove simple", () => {
|
|
67
76
|
const items = [1, 2, 3, 4, 5];
|
|
68
77
|
const result = items.remove(1, 5, (item) => item % 2 === 0);
|
package/lib/cjs/ArrayUtils.d.ts
CHANGED
|
@@ -61,4 +61,11 @@ export declare namespace ArrayUtils {
|
|
|
61
61
|
* @param round A round for both matches
|
|
62
62
|
*/
|
|
63
63
|
function differences<T>(a1: T[], a2: T[], round?: boolean): T[];
|
|
64
|
+
/**
|
|
65
|
+
* Merge arrays, remove duplicates, and sort by the first array
|
|
66
|
+
* @param sort Array to sort
|
|
67
|
+
* @param param All arrays to merge
|
|
68
|
+
* @returns Result
|
|
69
|
+
*/
|
|
70
|
+
function mergeArrays<T>(sort: T[], ...param: T[][]): T[];
|
|
64
71
|
}
|
package/lib/cjs/ArrayUtils.js
CHANGED
|
@@ -99,4 +99,24 @@ var ArrayUtils;
|
|
|
99
99
|
return diff;
|
|
100
100
|
}
|
|
101
101
|
ArrayUtils.differences = differences;
|
|
102
|
+
/**
|
|
103
|
+
* Merge arrays, remove duplicates, and sort by the first array
|
|
104
|
+
* @param sort Array to sort
|
|
105
|
+
* @param param All arrays to merge
|
|
106
|
+
* @returns Result
|
|
107
|
+
*/
|
|
108
|
+
function mergeArrays(sort, ...param) {
|
|
109
|
+
const result = [...sort];
|
|
110
|
+
for (let i = 0; i < param.length; i++) {
|
|
111
|
+
const arr = param[i];
|
|
112
|
+
for (let j = 0; j < arr.length; j++) {
|
|
113
|
+
const item = arr[j];
|
|
114
|
+
if (!result.includes(item)) {
|
|
115
|
+
result.push(item);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return result;
|
|
120
|
+
}
|
|
121
|
+
ArrayUtils.mergeArrays = mergeArrays;
|
|
102
122
|
})(ArrayUtils || (exports.ArrayUtils = ArrayUtils = {}));
|
package/lib/mjs/ArrayUtils.d.ts
CHANGED
|
@@ -61,4 +61,11 @@ export declare namespace ArrayUtils {
|
|
|
61
61
|
* @param round A round for both matches
|
|
62
62
|
*/
|
|
63
63
|
function differences<T>(a1: T[], a2: T[], round?: boolean): T[];
|
|
64
|
+
/**
|
|
65
|
+
* Merge arrays, remove duplicates, and sort by the first array
|
|
66
|
+
* @param sort Array to sort
|
|
67
|
+
* @param param All arrays to merge
|
|
68
|
+
* @returns Result
|
|
69
|
+
*/
|
|
70
|
+
function mergeArrays<T>(sort: T[], ...param: T[][]): T[];
|
|
64
71
|
}
|
package/lib/mjs/ArrayUtils.js
CHANGED
|
@@ -93,4 +93,24 @@ export var ArrayUtils;
|
|
|
93
93
|
return diff;
|
|
94
94
|
}
|
|
95
95
|
ArrayUtils.differences = differences;
|
|
96
|
+
/**
|
|
97
|
+
* Merge arrays, remove duplicates, and sort by the first array
|
|
98
|
+
* @param sort Array to sort
|
|
99
|
+
* @param param All arrays to merge
|
|
100
|
+
* @returns Result
|
|
101
|
+
*/
|
|
102
|
+
function mergeArrays(sort, ...param) {
|
|
103
|
+
const result = [...sort];
|
|
104
|
+
for (let i = 0; i < param.length; i++) {
|
|
105
|
+
const arr = param[i];
|
|
106
|
+
for (let j = 0; j < arr.length; j++) {
|
|
107
|
+
const item = arr[j];
|
|
108
|
+
if (!result.includes(item)) {
|
|
109
|
+
result.push(item);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return result;
|
|
114
|
+
}
|
|
115
|
+
ArrayUtils.mergeArrays = mergeArrays;
|
|
96
116
|
})(ArrayUtils || (ArrayUtils = {}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/shared",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.70",
|
|
4
4
|
"description": "TypeScript shared utilities and functions",
|
|
5
5
|
"main": "lib/cjs/index.js",
|
|
6
6
|
"module": "lib/mjs/index.js",
|
|
@@ -37,10 +37,10 @@
|
|
|
37
37
|
"homepage": "https://github.com/ETSOO/Shared#readme",
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/lodash.isequal": "^4.5.8",
|
|
40
|
-
"@vitejs/plugin-react": "^4.4.
|
|
40
|
+
"@vitejs/plugin-react": "^4.4.1",
|
|
41
41
|
"jsdom": "^26.1.0",
|
|
42
42
|
"typescript": "^5.8.3",
|
|
43
|
-
"vitest": "^3.1.
|
|
43
|
+
"vitest": "^3.1.2"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"lodash.isequal": "^4.5.0"
|
package/src/ArrayUtils.ts
CHANGED
|
@@ -212,4 +212,26 @@ export namespace ArrayUtils {
|
|
|
212
212
|
if (round) return [...diff, ...a2.filter((x) => !a1.includes(x))];
|
|
213
213
|
return diff;
|
|
214
214
|
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Merge arrays, remove duplicates, and sort by the first array
|
|
218
|
+
* @param sort Array to sort
|
|
219
|
+
* @param param All arrays to merge
|
|
220
|
+
* @returns Result
|
|
221
|
+
*/
|
|
222
|
+
export function mergeArrays<T>(sort: T[], ...param: T[][]): T[] {
|
|
223
|
+
const result = [...sort];
|
|
224
|
+
|
|
225
|
+
for (let i = 0; i < param.length; i++) {
|
|
226
|
+
const arr = param[i];
|
|
227
|
+
for (let j = 0; j < arr.length; j++) {
|
|
228
|
+
const item = arr[j];
|
|
229
|
+
if (!result.includes(item)) {
|
|
230
|
+
result.push(item);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return result;
|
|
236
|
+
}
|
|
215
237
|
}
|