@etsoo/shared 1.2.14 → 1.2.15

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.
@@ -1,5 +1,6 @@
1
1
  import { DomUtils } from '../src/DomUtils';
2
2
  import { DataTypes } from '../src/DataTypes';
3
+ import { DateUtils } from '../src/DateUtils';
3
4
 
4
5
  // Implement for tests
5
6
  class Rect implements DOMRect {
@@ -308,3 +309,20 @@ test('Tests for setFocus', () => {
308
309
  DomUtils.setFocus({ test: 'No content' }, container);
309
310
  expect(focus).toBeCalledTimes(2);
310
311
  });
312
+
313
+ test('Tests for getInputValue', () => {
314
+ // Arrange
315
+ const input = document.createElement('input');
316
+ input.type = 'datetime-local';
317
+ input.value = DateUtils.formatForInput('2023-09-21T23:08', false) ?? '';
318
+
319
+ // Act
320
+ const result = DomUtils.getInputValue(input);
321
+
322
+ // Assert
323
+ expect(result).not.toBeUndefined();
324
+ expect(result instanceof Date).toBeTruthy();
325
+ if (result instanceof Date) {
326
+ expect(result.getDate()).toBe(21);
327
+ }
328
+ });
@@ -108,7 +108,7 @@ export declare namespace DomUtils {
108
108
  * @param input HTML input
109
109
  * @returns Result
110
110
  */
111
- function getInputValue(input: HTMLInputElement): string | number | Date | null;
111
+ function getInputValue(input: HTMLInputElement): string | number | Date | null | undefined;
112
112
  /**
113
113
  * Get an unique key combined with current URL
114
114
  * @param key Key
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DomUtils = void 0;
4
4
  /// <reference lib="dom" />
5
5
  const DataTypes_1 = require("./DataTypes");
6
+ const DateUtils_1 = require("./DateUtils");
6
7
  if (typeof navigator === 'undefined') {
7
8
  // Test mock only
8
9
  global.navigator = { language: 'en-US' };
@@ -381,6 +382,7 @@ var DomUtils;
381
382
  * @returns Result
382
383
  */
383
384
  function getInputValue(input) {
385
+ var _a;
384
386
  const type = input.type;
385
387
  if (type === 'number' || type === 'range') {
386
388
  const num = input.valueAsNumber;
@@ -389,7 +391,7 @@ var DomUtils;
389
391
  return num;
390
392
  }
391
393
  else if (type === 'date' || type === 'datetime-local')
392
- return input.valueAsDate;
394
+ return (_a = input.valueAsDate) !== null && _a !== void 0 ? _a : DateUtils_1.DateUtils.parse(input.value);
393
395
  return input.value;
394
396
  }
395
397
  DomUtils.getInputValue = getInputValue;
@@ -108,7 +108,7 @@ export declare namespace DomUtils {
108
108
  * @param input HTML input
109
109
  * @returns Result
110
110
  */
111
- function getInputValue(input: HTMLInputElement): string | number | Date | null;
111
+ function getInputValue(input: HTMLInputElement): string | number | Date | null | undefined;
112
112
  /**
113
113
  * Get an unique key combined with current URL
114
114
  * @param key Key
@@ -1,5 +1,6 @@
1
1
  /// <reference lib="dom" />
2
2
  import { DataTypes } from './DataTypes';
3
+ import { DateUtils } from './DateUtils';
3
4
  if (typeof navigator === 'undefined') {
4
5
  // Test mock only
5
6
  global.navigator = { language: 'en-US' };
@@ -378,6 +379,7 @@ export var DomUtils;
378
379
  * @returns Result
379
380
  */
380
381
  function getInputValue(input) {
382
+ var _a;
381
383
  const type = input.type;
382
384
  if (type === 'number' || type === 'range') {
383
385
  const num = input.valueAsNumber;
@@ -386,7 +388,7 @@ export var DomUtils;
386
388
  return num;
387
389
  }
388
390
  else if (type === 'date' || type === 'datetime-local')
389
- return input.valueAsDate;
391
+ return (_a = input.valueAsDate) !== null && _a !== void 0 ? _a : DateUtils.parse(input.value);
390
392
  return input.value;
391
393
  }
392
394
  DomUtils.getInputValue = getInputValue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/shared",
3
- "version": "1.2.14",
3
+ "version": "1.2.15",
4
4
  "description": "TypeScript shared utilities and functions",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
package/src/DomUtils.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  /// <reference lib="dom" />
2
2
  import { DataTypes } from './DataTypes';
3
+ import { DateUtils } from './DateUtils';
3
4
  import { FormDataFieldValue, IFormData } from './types/FormData';
4
5
 
5
6
  if (typeof navigator === 'undefined') {
@@ -469,7 +470,7 @@ export namespace DomUtils {
469
470
  if (isNaN(num)) return null;
470
471
  return num;
471
472
  } else if (type === 'date' || type === 'datetime-local')
472
- return input.valueAsDate;
473
+ return input.valueAsDate ?? DateUtils.parse(input.value);
473
474
  return input.value;
474
475
  }
475
476