@etsoo/shared 1.1.70 → 1.1.72
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 +2 -0
- package/__tests__/Utils.ts +7 -0
- package/lib/cjs/DomUtils.d.ts +6 -0
- package/lib/cjs/DomUtils.js +18 -0
- package/lib/cjs/Utils.d.ts +7 -0
- package/lib/cjs/Utils.js +13 -0
- package/lib/mjs/DomUtils.d.ts +6 -0
- package/lib/mjs/DomUtils.js +18 -0
- package/lib/mjs/Utils.d.ts +7 -0
- package/lib/mjs/Utils.js +13 -0
- package/package.json +5 -5
- package/src/DomUtils.ts +16 -0
- package/src/Utils.ts +12 -0
package/README.md
CHANGED
|
@@ -169,6 +169,7 @@ DOM/window related utilities
|
|
|
169
169
|
|formDataToObject|Form data to object|
|
|
170
170
|
|getCulture|Get the available culture definition|
|
|
171
171
|
|getDataChanges|Get data changed fields with input data updated|
|
|
172
|
+
|getInputValue|Get input value depending on its type|
|
|
172
173
|
|getLocationKey|Get an unique key combined with current URL|
|
|
173
174
|
|headersToObject|Convert headers to object|
|
|
174
175
|
|isFormData|Is IFormData type guard|
|
|
@@ -215,6 +216,7 @@ String and other related utilities
|
|
|
215
216
|
|Name|Description|
|
|
216
217
|
|---:|---|
|
|
217
218
|
|addBlankItem|Add blank item to collection|
|
|
219
|
+
|arrayDifferences|Array 1 items do not exist in Array 2 or reverse match|
|
|
218
220
|
|charsToNumber|Base64 chars to number|
|
|
219
221
|
|correctTypes|Correct object's property value type|
|
|
220
222
|
|equals|Two values equal|
|
package/__tests__/Utils.ts
CHANGED
|
@@ -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',
|
package/lib/cjs/DomUtils.d.ts
CHANGED
|
@@ -82,6 +82,12 @@ export declare namespace DomUtils {
|
|
|
82
82
|
*/
|
|
83
83
|
compatibleName?: string[] | undefined;
|
|
84
84
|
}> | undefined;
|
|
85
|
+
/**
|
|
86
|
+
* Get input value depending on its type
|
|
87
|
+
* @param input HTML input
|
|
88
|
+
* @returns Result
|
|
89
|
+
*/
|
|
90
|
+
function getInputValue(input: HTMLInputElement): string | number | Date | null;
|
|
85
91
|
/**
|
|
86
92
|
* Get an unique key combined with current URL
|
|
87
93
|
* @param key Key
|
package/lib/cjs/DomUtils.js
CHANGED
|
@@ -293,6 +293,24 @@ var DomUtils;
|
|
|
293
293
|
// Default
|
|
294
294
|
return items[0];
|
|
295
295
|
};
|
|
296
|
+
/**
|
|
297
|
+
* Get input value depending on its type
|
|
298
|
+
* @param input HTML input
|
|
299
|
+
* @returns Result
|
|
300
|
+
*/
|
|
301
|
+
function getInputValue(input) {
|
|
302
|
+
const type = input.type;
|
|
303
|
+
if (type === 'number' || type === 'range') {
|
|
304
|
+
const num = input.valueAsNumber;
|
|
305
|
+
if (isNaN(num))
|
|
306
|
+
return null;
|
|
307
|
+
return num;
|
|
308
|
+
}
|
|
309
|
+
else if (type === 'date' || type === 'datetime-local')
|
|
310
|
+
return input.valueAsDate;
|
|
311
|
+
return input.value;
|
|
312
|
+
}
|
|
313
|
+
DomUtils.getInputValue = getInputValue;
|
|
296
314
|
/**
|
|
297
315
|
* Get an unique key combined with current URL
|
|
298
316
|
* @param key Key
|
package/lib/cjs/Utils.d.ts
CHANGED
|
@@ -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
|
package/lib/mjs/DomUtils.d.ts
CHANGED
|
@@ -82,6 +82,12 @@ export declare namespace DomUtils {
|
|
|
82
82
|
*/
|
|
83
83
|
compatibleName?: string[] | undefined;
|
|
84
84
|
}> | undefined;
|
|
85
|
+
/**
|
|
86
|
+
* Get input value depending on its type
|
|
87
|
+
* @param input HTML input
|
|
88
|
+
* @returns Result
|
|
89
|
+
*/
|
|
90
|
+
function getInputValue(input: HTMLInputElement): string | number | Date | null;
|
|
85
91
|
/**
|
|
86
92
|
* Get an unique key combined with current URL
|
|
87
93
|
* @param key Key
|
package/lib/mjs/DomUtils.js
CHANGED
|
@@ -290,6 +290,24 @@ export var DomUtils;
|
|
|
290
290
|
// Default
|
|
291
291
|
return items[0];
|
|
292
292
|
};
|
|
293
|
+
/**
|
|
294
|
+
* Get input value depending on its type
|
|
295
|
+
* @param input HTML input
|
|
296
|
+
* @returns Result
|
|
297
|
+
*/
|
|
298
|
+
function getInputValue(input) {
|
|
299
|
+
const type = input.type;
|
|
300
|
+
if (type === 'number' || type === 'range') {
|
|
301
|
+
const num = input.valueAsNumber;
|
|
302
|
+
if (isNaN(num))
|
|
303
|
+
return null;
|
|
304
|
+
return num;
|
|
305
|
+
}
|
|
306
|
+
else if (type === 'date' || type === 'datetime-local')
|
|
307
|
+
return input.valueAsDate;
|
|
308
|
+
return input.value;
|
|
309
|
+
}
|
|
310
|
+
DomUtils.getInputValue = getInputValue;
|
|
293
311
|
/**
|
|
294
312
|
* Get an unique key combined with current URL
|
|
295
313
|
* @param key Key
|
package/lib/mjs/Utils.d.ts
CHANGED
|
@@ -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
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/shared",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.72",
|
|
4
4
|
"description": "TypeScript shared utilities and functions",
|
|
5
5
|
"main": "lib/cjs/index.js",
|
|
6
6
|
"module": "lib/mjs/index.js",
|
|
@@ -54,10 +54,10 @@
|
|
|
54
54
|
},
|
|
55
55
|
"homepage": "https://github.com/ETSOO/Shared#readme",
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@types/jest": "^29.2.
|
|
58
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
59
|
-
"@typescript-eslint/parser": "^5.
|
|
60
|
-
"eslint": "^8.
|
|
57
|
+
"@types/jest": "^29.2.2",
|
|
58
|
+
"@typescript-eslint/eslint-plugin": "^5.42.0",
|
|
59
|
+
"@typescript-eslint/parser": "^5.42.0",
|
|
60
|
+
"eslint": "^8.27.0",
|
|
61
61
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
62
62
|
"eslint-plugin-import": "^2.26.0",
|
|
63
63
|
"jest": "^29.2.2",
|
package/src/DomUtils.ts
CHANGED
|
@@ -341,6 +341,22 @@ export namespace DomUtils {
|
|
|
341
341
|
return items[0];
|
|
342
342
|
};
|
|
343
343
|
|
|
344
|
+
/**
|
|
345
|
+
* Get input value depending on its type
|
|
346
|
+
* @param input HTML input
|
|
347
|
+
* @returns Result
|
|
348
|
+
*/
|
|
349
|
+
export function getInputValue(input: HTMLInputElement) {
|
|
350
|
+
const type = input.type;
|
|
351
|
+
if (type === 'number' || type === 'range') {
|
|
352
|
+
const num = input.valueAsNumber;
|
|
353
|
+
if (isNaN(num)) return null;
|
|
354
|
+
return num;
|
|
355
|
+
} else if (type === 'date' || type === 'datetime-local')
|
|
356
|
+
return input.valueAsDate;
|
|
357
|
+
return input.value;
|
|
358
|
+
}
|
|
359
|
+
|
|
344
360
|
/**
|
|
345
361
|
* Get an unique key combined with current URL
|
|
346
362
|
* @param key Key
|
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
|