@etsoo/shared 1.1.69 → 1.1.71

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 CHANGED
@@ -215,6 +215,7 @@ String and other related utilities
215
215
  |Name|Description|
216
216
  |---:|---|
217
217
  |addBlankItem|Add blank item to collection|
218
+ |arrayDifferences|Array 1 items do not exist in Array 2 or reverse match|
218
219
  |charsToNumber|Base64 chars to number|
219
220
  |correctTypes|Correct object's property value type|
220
221
  |equals|Two values equal|
@@ -13,6 +13,13 @@ test('Tests for addBlankItem', () => {
13
13
  expect(options.length).toBe(3);
14
14
  });
15
15
 
16
+ test('Tests for arrayDifferences', () => {
17
+ const a1 = ['a', 'b', 'c', 'e'];
18
+ const a2 = ['a', 'c', 'd'];
19
+ expect(Utils.arrayDifferences(a1, a2)).toEqual(['b', 'e']);
20
+ expect(Utils.arrayDifferences(a1, a2, true)).toEqual(['b', 'e', 'd']);
21
+ });
22
+
16
23
  test('Tests for correctTypes', () => {
17
24
  const input = {
18
25
  id: '1',
@@ -54,6 +54,13 @@ export declare namespace Utils {
54
54
  * @param blankLabel Blank label, default is ---
55
55
  */
56
56
  function addBlankItem<T extends object>(options: T[], idField?: string | keyof T, labelField?: unknown, blankLabel?: string): T[];
57
+ /**
58
+ * Array 1 items do not exist in Array 2 or reverse match
59
+ * @param a1 Array 1
60
+ * @param a2 Array 2
61
+ * @param round A round for both matches
62
+ */
63
+ function arrayDifferences<T>(a1: T[], a2: T[], round?: boolean): T[];
57
64
  /**
58
65
  * Base64 chars to number
59
66
  * @param base64Chars Base64 chars
package/lib/cjs/Utils.js CHANGED
@@ -81,6 +81,19 @@ var Utils;
81
81
  return options;
82
82
  }
83
83
  Utils.addBlankItem = addBlankItem;
84
+ /**
85
+ * Array 1 items do not exist in Array 2 or reverse match
86
+ * @param a1 Array 1
87
+ * @param a2 Array 2
88
+ * @param round A round for both matches
89
+ */
90
+ function arrayDifferences(a1, a2, round) {
91
+ const diff = a1.filter((x) => !a2.includes(x));
92
+ if (round)
93
+ return [...diff, ...a2.filter((x) => !a1.includes(x))];
94
+ return diff;
95
+ }
96
+ Utils.arrayDifferences = arrayDifferences;
84
97
  /**
85
98
  * Base64 chars to number
86
99
  * @param base64Chars Base64 chars
@@ -1,4 +1,4 @@
1
- export declare type DelayedExecutorType<P extends any[]> = {
1
+ export declare type DelayedExecutorType<P extends any[] = []> = {
2
2
  /**
3
3
  * Call the function
4
4
  * @param miliseconds Delayed miliseconds for this call
@@ -54,6 +54,13 @@ export declare namespace Utils {
54
54
  * @param blankLabel Blank label, default is ---
55
55
  */
56
56
  function addBlankItem<T extends object>(options: T[], idField?: string | keyof T, labelField?: unknown, blankLabel?: string): T[];
57
+ /**
58
+ * Array 1 items do not exist in Array 2 or reverse match
59
+ * @param a1 Array 1
60
+ * @param a2 Array 2
61
+ * @param round A round for both matches
62
+ */
63
+ function arrayDifferences<T>(a1: T[], a2: T[], round?: boolean): T[];
57
64
  /**
58
65
  * Base64 chars to number
59
66
  * @param base64Chars Base64 chars
package/lib/mjs/Utils.js CHANGED
@@ -78,6 +78,19 @@ export var Utils;
78
78
  return options;
79
79
  }
80
80
  Utils.addBlankItem = addBlankItem;
81
+ /**
82
+ * Array 1 items do not exist in Array 2 or reverse match
83
+ * @param a1 Array 1
84
+ * @param a2 Array 2
85
+ * @param round A round for both matches
86
+ */
87
+ function arrayDifferences(a1, a2, round) {
88
+ const diff = a1.filter((x) => !a2.includes(x));
89
+ if (round)
90
+ return [...diff, ...a2.filter((x) => !a1.includes(x))];
91
+ return diff;
92
+ }
93
+ Utils.arrayDifferences = arrayDifferences;
81
94
  /**
82
95
  * Base64 chars to number
83
96
  * @param base64Chars Base64 chars
@@ -1,4 +1,4 @@
1
- export declare type DelayedExecutorType<P extends any[]> = {
1
+ export declare type DelayedExecutorType<P extends any[] = []> = {
2
2
  /**
3
3
  * Call the function
4
4
  * @param miliseconds Delayed miliseconds for this call
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/shared",
3
- "version": "1.1.69",
3
+ "version": "1.1.71",
4
4
  "description": "TypeScript shared utilities and functions",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -54,9 +54,9 @@
54
54
  },
55
55
  "homepage": "https://github.com/ETSOO/Shared#readme",
56
56
  "devDependencies": {
57
- "@types/jest": "^29.2.0",
58
- "@typescript-eslint/eslint-plugin": "^5.41.0",
59
- "@typescript-eslint/parser": "^5.41.0",
57
+ "@types/jest": "^29.2.1",
58
+ "@typescript-eslint/eslint-plugin": "^5.42.0",
59
+ "@typescript-eslint/parser": "^5.42.0",
60
60
  "eslint": "^8.26.0",
61
61
  "eslint-config-airbnb-base": "^15.0.0",
62
62
  "eslint-plugin-import": "^2.26.0",
package/src/Utils.ts CHANGED
@@ -139,6 +139,18 @@ export namespace Utils {
139
139
  return options;
140
140
  }
141
141
 
142
+ /**
143
+ * Array 1 items do not exist in Array 2 or reverse match
144
+ * @param a1 Array 1
145
+ * @param a2 Array 2
146
+ * @param round A round for both matches
147
+ */
148
+ export function arrayDifferences<T>(a1: T[], a2: T[], round?: boolean) {
149
+ const diff = a1.filter((x) => !a2.includes(x));
150
+ if (round) return [...diff, ...a2.filter((x) => !a1.includes(x))];
151
+ return diff;
152
+ }
153
+
142
154
  /**
143
155
  * Base64 chars to number
144
156
  * @param base64Chars Base64 chars
@@ -1,4 +1,4 @@
1
- export type DelayedExecutorType<P extends any[]> = {
1
+ export type DelayedExecutorType<P extends any[] = []> = {
2
2
  /**
3
3
  * Call the function
4
4
  * @param miliseconds Delayed miliseconds for this call