@etsoo/shared 1.1.71 → 1.1.73

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
@@ -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|
@@ -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
@@ -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
@@ -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
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/shared",
3
- "version": "1.1.71",
3
+ "version": "1.1.73",
4
4
  "description": "TypeScript shared utilities and functions",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -54,14 +54,14 @@
54
54
  },
55
55
  "homepage": "https://github.com/ETSOO/Shared#readme",
56
56
  "devDependencies": {
57
- "@types/jest": "^29.2.1",
58
- "@typescript-eslint/eslint-plugin": "^5.42.0",
59
- "@typescript-eslint/parser": "^5.42.0",
60
- "eslint": "^8.26.0",
57
+ "@types/jest": "^29.2.2",
58
+ "@typescript-eslint/eslint-plugin": "^5.42.1",
59
+ "@typescript-eslint/parser": "^5.42.1",
60
+ "eslint": "^8.27.0",
61
61
  "eslint-config-airbnb-base": "^15.0.0",
62
62
  "eslint-plugin-import": "^2.26.0",
63
- "jest": "^29.2.2",
64
- "jest-environment-jsdom": "^29.2.2",
63
+ "jest": "^29.3.0",
64
+ "jest-environment-jsdom": "^29.3.0",
65
65
  "ts-jest": "^29.0.3",
66
66
  "typescript": "^4.8.4"
67
67
  }
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