@etsoo/shared 1.2.26 → 1.2.28

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.
@@ -98,6 +98,11 @@ test('Tests for substract', () => {
98
98
  test('Tests for parse', () => {
99
99
  const d1 = DateUtils.parse('2014-01-01T13:13:34.441Z')?.toJSON();
100
100
  expect(d1).toBe('2014-01-01T13:13:34.441Z');
101
+
102
+ const d2 = DateUtils.parse('2024-03-01T11:41');
103
+ expect(d2?.getDate()).toBe(1);
104
+ expect(d2?.getHours()).toBe(11);
105
+ expect(d2?.getSeconds()).toBe(0);
101
106
  });
102
107
 
103
108
  test('Tests for sameDay', () => {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "target": "ES2019",
3
+ "target": "ES2020",
4
4
  "module": "ESNext",
5
5
  "allowJs": true,
6
6
  "skipLibCheck": true,
@@ -27,9 +27,8 @@ var ColorUtils;
27
27
  * @returns Result
28
28
  */
29
29
  function getEColors(init = '#000', factor = 51, adjustOrder = true) {
30
- var _a;
31
30
  // Init color
32
- const initColor = (_a = EColor_1.EColor.parse(init)) !== null && _a !== void 0 ? _a : new EColor_1.EColor(0, 0, 0);
31
+ const initColor = EColor_1.EColor.parse(init) ?? new EColor_1.EColor(0, 0, 0);
33
32
  // Factors elements
34
33
  // 51 = '00', '33', '66', '99', 'cc', 'ff'
35
34
  const factors = [];
@@ -74,7 +74,7 @@ var DateUtils;
74
74
  if (parsed == null)
75
75
  return undefined;
76
76
  // Default options
77
- options !== null && options !== void 0 ? options : (options = DateUtils.DayFormat);
77
+ options ?? (options = DateUtils.DayFormat);
78
78
  // Default options
79
79
  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat
80
80
  let opt;
@@ -7,8 +7,8 @@ const DateUtils_1 = require("./DateUtils");
7
7
  const Utils_1 = require("./Utils");
8
8
  if (typeof navigator === 'undefined') {
9
9
  // Test mock only
10
- global.navigator = { language: 'en-US' };
11
- global.location = { href: 'http://localhost/' };
10
+ globalThis.navigator = { language: 'en-US' };
11
+ globalThis.location = { href: 'http://localhost/' };
12
12
  }
13
13
  /**
14
14
  * Dom Utilities
@@ -93,15 +93,14 @@ var DomUtils;
93
93
  }
94
94
  DomUtils.clearFormData = clearFormData;
95
95
  function dataAsTraveller(source, data, template, keepSource, isValue) {
96
- var _a;
97
96
  // Properties
98
97
  const properties = Object.keys(template);
99
98
  // Entries
100
99
  const entries = Object.entries(isFormData(source) ? formDataToObject(source) : source);
101
100
  for (const [key, value] of entries) {
102
101
  // Is included or keepSource
103
- const property = (_a = properties.find((p) => p.localeCompare(key, 'en', { sensitivity: 'base' }) ===
104
- 0)) !== null && _a !== void 0 ? _a : (keepSource ? key : undefined);
102
+ const property = properties.find((p) => p.localeCompare(key, 'en', { sensitivity: 'base' }) ===
103
+ 0) ?? (keepSource ? key : undefined);
105
104
  if (property == null)
106
105
  continue;
107
106
  // Template value
@@ -168,12 +167,13 @@ var DomUtils;
168
167
  * Current detected country
169
168
  */
170
169
  DomUtils.detectedCountry = (() => {
171
- var _a, _b;
172
170
  // URL first, then local storage
173
171
  let country;
174
172
  try {
175
173
  country =
176
- (_b = (_a = new URL(location.href).searchParams.get(DomUtils.CountryField)) !== null && _a !== void 0 ? _a : sessionStorage.getItem(DomUtils.CountryField)) !== null && _b !== void 0 ? _b : localStorage.getItem(DomUtils.CountryField);
174
+ new URL(location.href).searchParams.get(DomUtils.CountryField) ??
175
+ sessionStorage.getItem(DomUtils.CountryField) ??
176
+ localStorage.getItem(DomUtils.CountryField);
177
177
  }
178
178
  catch {
179
179
  country = null;
@@ -185,12 +185,13 @@ var DomUtils;
185
185
  * Current detected culture
186
186
  */
187
187
  DomUtils.detectedCulture = (() => {
188
- var _a, _b;
189
188
  // URL first, then local storage
190
189
  let culture;
191
190
  try {
192
191
  culture =
193
- (_b = (_a = new URL(location.href).searchParams.get(DomUtils.CultureField)) !== null && _a !== void 0 ? _a : sessionStorage.getItem(DomUtils.CultureField)) !== null && _b !== void 0 ? _b : localStorage.getItem(DomUtils.CultureField);
192
+ new URL(location.href).searchParams.get(DomUtils.CultureField) ??
193
+ sessionStorage.getItem(DomUtils.CultureField) ??
194
+ localStorage.getItem(DomUtils.CultureField);
194
195
  }
195
196
  catch {
196
197
  culture = null;
@@ -362,11 +363,8 @@ var DomUtils;
362
363
  if (exactMatch)
363
364
  return [exactMatch, CultureMatch.Exact];
364
365
  // Compatible match
365
- const compatibleMatch = items.find((item) => {
366
- var _a;
367
- return ((_a = item.compatibleNames) === null || _a === void 0 ? void 0 : _a.includes(culture)) ||
368
- culture.startsWith(item + '-');
369
- });
366
+ const compatibleMatch = items.find((item) => item.compatibleNames?.includes(culture) ||
367
+ culture.startsWith(item + '-'));
370
368
  if (compatibleMatch)
371
369
  return [compatibleMatch, CultureMatch.Compatible];
372
370
  // Same part, like zh-CN and zh-HK
@@ -383,7 +381,6 @@ var DomUtils;
383
381
  * @returns Result
384
382
  */
385
383
  function getInputValue(input) {
386
- var _a;
387
384
  const type = input.type;
388
385
  if (type === 'number' || type === 'range') {
389
386
  const num = input.valueAsNumber;
@@ -392,7 +389,7 @@ var DomUtils;
392
389
  return num;
393
390
  }
394
391
  else if (type === 'date' || type === 'datetime-local')
395
- return (_a = input.valueAsDate) !== null && _a !== void 0 ? _a : DateUtils_1.DateUtils.parse(input.value);
392
+ return input.valueAsDate ?? DateUtils_1.DateUtils.parse(input.value);
396
393
  return input.value;
397
394
  }
398
395
  DomUtils.getInputValue = getInputValue;
@@ -493,7 +490,7 @@ var DomUtils;
493
490
  */
494
491
  function setFocus(name, container) {
495
492
  const elementName = typeof name === 'string' ? name : Object.keys(name)[0];
496
- container !== null && container !== void 0 ? container : (container = document.body);
493
+ container ?? (container = document.body);
497
494
  const element = container.querySelector(`[name="${elementName}"]`);
498
495
  if (element != null)
499
496
  element.focus();
@@ -505,13 +502,11 @@ var DomUtils;
505
502
  * @param preventDefault Is prevent default action
506
503
  */
507
504
  function setupLogging(action, preventDefault) {
508
- var _a, _b;
509
505
  // Avoid multiple setup, if there is already a handler, please set "globalThis.onunhandledrejection = null" first
510
506
  if (globalThis.onunhandledrejection)
511
507
  return;
512
- const errorPD = (_a = Utils_1.Utils.getResult(preventDefault, 'error')) !== null && _a !== void 0 ? _a : true;
508
+ const errorPD = Utils_1.Utils.getResult(preventDefault, 'error') ?? true;
513
509
  globalThis.onerror = (message, source, lineNo, colNo, error) => {
514
- var _a;
515
510
  // Default source
516
511
  source || (source = globalThis.location.href);
517
512
  let data;
@@ -522,25 +517,26 @@ var DomUtils;
522
517
  source,
523
518
  lineNo,
524
519
  colNo,
525
- stack: error === null || error === void 0 ? void 0 : error.stack
520
+ stack: error?.stack
526
521
  };
527
522
  }
528
523
  else {
529
524
  data = {
530
525
  type: 'error',
531
526
  eventType: message.type,
532
- message: (_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : `${message.currentTarget} event error`,
527
+ message: error?.message ??
528
+ `${message.currentTarget} event error`,
533
529
  source,
534
530
  lineNo,
535
531
  colNo,
536
- stack: error === null || error === void 0 ? void 0 : error.stack
532
+ stack: error?.stack
537
533
  };
538
534
  }
539
535
  action(data);
540
536
  // Return true to suppress error alert
541
537
  return errorPD;
542
538
  };
543
- const rejectionPD = (_b = Utils_1.Utils.getResult(preventDefault, 'error')) !== null && _b !== void 0 ? _b : true;
539
+ const rejectionPD = Utils_1.Utils.getResult(preventDefault, 'error') ?? true;
544
540
  globalThis.onunhandledrejection = (event) => {
545
541
  if (rejectionPD)
546
542
  event.preventDefault();
@@ -556,8 +552,7 @@ var DomUtils;
556
552
  action(data);
557
553
  };
558
554
  const localConsole = (type, orgin) => {
559
- var _a;
560
- const consolePD = (_a = Utils_1.Utils.getResult(preventDefault, type)) !== null && _a !== void 0 ? _a : false;
555
+ const consolePD = Utils_1.Utils.getResult(preventDefault, type) ?? false;
561
556
  return (...args) => {
562
557
  // Keep original action
563
558
  if (!consolePD)
@@ -42,7 +42,7 @@ var ExtendUtils;
42
42
  cancel = waitFor(() => {
43
43
  func(...args);
44
44
  cancel = undefined;
45
- }, miliseconds !== null && miliseconds !== void 0 ? miliseconds : delayMiliseconds);
45
+ }, miliseconds ?? delayMiliseconds);
46
46
  },
47
47
  /**
48
48
  * Clear
@@ -34,19 +34,18 @@ var NumberUtils;
34
34
  * @returns Result
35
35
  */
36
36
  function formatMoney(input, currency, locale, isInteger = false, options = {}) {
37
- var _a, _b, _c, _d;
38
37
  if (currency) {
39
38
  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat
40
39
  options.style = 'currency';
41
40
  options.currency = currency;
42
- (_a = options.currencyDisplay) !== null && _a !== void 0 ? _a : (options.currencyDisplay = 'narrowSymbol');
41
+ options.currencyDisplay ?? (options.currencyDisplay = 'narrowSymbol');
43
42
  }
44
43
  if (isInteger) {
45
- (_b = options.minimumFractionDigits) !== null && _b !== void 0 ? _b : (options.minimumFractionDigits = 0);
46
- (_c = options.maximumFractionDigits) !== null && _c !== void 0 ? _c : (options.maximumFractionDigits = 0);
44
+ options.minimumFractionDigits ?? (options.minimumFractionDigits = 0);
45
+ options.maximumFractionDigits ?? (options.maximumFractionDigits = 0);
47
46
  }
48
47
  else
49
- (_d = options.minimumFractionDigits) !== null && _d !== void 0 ? _d : (options.minimumFractionDigits = 2);
48
+ options.minimumFractionDigits ?? (options.minimumFractionDigits = 2);
50
49
  return format(input, locale, options);
51
50
  }
52
51
  NumberUtils.formatMoney = formatMoney;
@@ -71,14 +70,13 @@ var NumberUtils;
71
70
  * @returns Result
72
71
  */
73
72
  function getCurrencySymbol(code, display = 'narrowSymbol', locale) {
74
- var _a;
75
73
  const formatter = new Intl.NumberFormat(locale, {
76
74
  style: 'currency',
77
75
  currency: code,
78
76
  currencyDisplay: display
79
77
  });
80
78
  const parts = formatter.formatToParts();
81
- const symbol = (_a = parts.find((part) => part.type === 'currency')) === null || _a === void 0 ? void 0 : _a.value;
79
+ const symbol = parts.find((part) => part.type === 'currency')?.value;
82
80
  return symbol;
83
81
  }
84
82
  NumberUtils.getCurrencySymbol = getCurrencySymbol;
@@ -1,12 +1,11 @@
1
1
  "use strict";
2
- var _a, _b;
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  exports.StorageUtils = void 0;
5
4
  const Storage_1 = require("./node/Storage");
6
5
  const Utils_1 = require("./Utils");
7
6
  // Mock node
8
- (_a = globalThis.localStorage) !== null && _a !== void 0 ? _a : (globalThis.localStorage = new Storage_1.NodeStorage());
9
- (_b = globalThis.sessionStorage) !== null && _b !== void 0 ? _b : (globalThis.sessionStorage = new Storage_1.NodeStorage());
7
+ globalThis.localStorage ?? (globalThis.localStorage = new Storage_1.NodeStorage());
8
+ globalThis.sessionStorage ?? (globalThis.sessionStorage = new Storage_1.NodeStorage());
10
9
  /**
11
10
  * Storage utilities
12
11
  * NodeStorage needs data persistance
package/lib/cjs/Utils.js CHANGED
@@ -55,7 +55,7 @@ String.prototype.hideEmail = function () {
55
55
  return this.hideData('@');
56
56
  };
57
57
  String.prototype.isDigits = function (minLength) {
58
- return this.length >= (minLength !== null && minLength !== void 0 ? minLength : 0) && /^\d+$/.test(this);
58
+ return this.length >= (minLength ?? 0) && /^\d+$/.test(this);
59
59
  };
60
60
  String.prototype.isEmail = function () {
61
61
  const re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
@@ -78,11 +78,11 @@ var Utils;
78
78
  */
79
79
  function addBlankItem(options, idField, labelField, blankLabel) {
80
80
  // Avoid duplicate blank items
81
- idField !== null && idField !== void 0 ? idField : (idField = 'id');
81
+ idField ?? (idField = 'id');
82
82
  if (options.length === 0 || Reflect.get(options[0], idField) !== '') {
83
83
  const blankItem = {
84
84
  [idField]: '',
85
- [typeof labelField === 'string' ? labelField : 'label']: blankLabel !== null && blankLabel !== void 0 ? blankLabel : '---'
85
+ [typeof labelField === 'string' ? labelField : 'label']: blankLabel ?? '---'
86
86
  };
87
87
  options.unshift(blankItem);
88
88
  }
@@ -199,7 +199,6 @@ var Utils;
199
199
  // Changed fields
200
200
  const changes = [];
201
201
  Object.entries(input).forEach(([key, value]) => {
202
- var _a;
203
202
  // Ignore fields, no process
204
203
  if (ignoreFields.includes(key))
205
204
  return;
@@ -214,7 +213,7 @@ var Utils;
214
213
  // Date when meets string
215
214
  if (value instanceof Date) {
216
215
  if (value.valueOf() ===
217
- ((_a = DateUtils_1.DateUtils.parse(initValue)) === null || _a === void 0 ? void 0 : _a.valueOf())) {
216
+ DateUtils_1.DateUtils.parse(initValue)?.valueOf()) {
218
217
  Reflect.deleteProperty(input, key);
219
218
  return;
220
219
  }
@@ -484,7 +483,7 @@ var Utils;
484
483
  * @returns Result
485
484
  */
486
485
  Utils.removeNonLetters = (input) => {
487
- return input === null || input === void 0 ? void 0 : input.removeNonLetters();
486
+ return input?.removeNonLetters();
488
487
  };
489
488
  /**
490
489
  * Replace null or empty with default value
@@ -505,9 +504,8 @@ var Utils;
505
504
  */
506
505
  Utils.setLabels = (source, labels, reference) => {
507
506
  Object.keys(source).forEach((key) => {
508
- var _a;
509
507
  // Reference key
510
- const labelKey = reference == null ? key : (_a = reference[key]) !== null && _a !== void 0 ? _a : key;
508
+ const labelKey = reference == null ? key : reference[key] ?? key;
511
509
  // Label
512
510
  const label = labels[labelKey];
513
511
  if (label != null) {
@@ -64,7 +64,7 @@ class ContentDisposition {
64
64
  }
65
65
  }
66
66
  if (type === 'form-data') {
67
- return new ContentDisposition(type, filename, name !== null && name !== void 0 ? name : 'file');
67
+ return new ContentDisposition(type, filename, name ?? 'file');
68
68
  }
69
69
  if (type === 'inline' || type === 'attachment') {
70
70
  return new ContentDisposition(type, filename);
@@ -217,7 +217,7 @@ class EColor {
217
217
  includeAlpha = alpha;
218
218
  }
219
219
  if (includeAlpha)
220
- return `RGBA(${this.r}, ${this.g}, ${this.b}, ${alphaValue !== null && alphaValue !== void 0 ? alphaValue : 1})`;
220
+ return `RGBA(${this.r}, ${this.g}, ${this.b}, ${alphaValue ?? 1})`;
221
221
  return `RGB(${this.r}, ${this.g}, ${this.b})`;
222
222
  }
223
223
  }
@@ -89,11 +89,10 @@ class EventClass {
89
89
  * @param options Options
90
90
  */
91
91
  on(type, callback, options) {
92
- var _a, _b;
93
92
  if (typeof type === 'object') {
94
93
  for (const key in type) {
95
94
  const item = key;
96
- const itemCallback = (_a = type[item]) !== null && _a !== void 0 ? _a : callback;
95
+ const itemCallback = type[item] ?? callback;
97
96
  if (itemCallback)
98
97
  this.on(item, itemCallback, options);
99
98
  }
@@ -104,7 +103,7 @@ class EventClass {
104
103
  this.listeners.has(type) || this.listeners.set(type, []);
105
104
  // String to T conversion problem
106
105
  // "keyofStringsOnly": true could solve part of it
107
- (_b = this.listeners.get(type)) === null || _b === void 0 ? void 0 : _b.push([callback, options]);
106
+ this.listeners.get(type)?.push([callback, options]);
108
107
  }
109
108
  /**
110
109
  * Trigger event
@@ -140,10 +139,10 @@ class EventClass {
140
139
  for (let c = 0; c < len; c++) {
141
140
  const item = items[c];
142
141
  const [callback, options] = item;
143
- if (options === null || options === void 0 ? void 0 : options.capture)
142
+ if (options?.capture)
144
143
  continue;
145
144
  callback(event);
146
- if (options === null || options === void 0 ? void 0 : options.once) {
145
+ if (options?.once) {
147
146
  indicies.push(c);
148
147
  }
149
148
  if (event.propagationStopped) {
@@ -24,9 +24,8 @@ export var ColorUtils;
24
24
  * @returns Result
25
25
  */
26
26
  function getEColors(init = '#000', factor = 51, adjustOrder = true) {
27
- var _a;
28
27
  // Init color
29
- const initColor = (_a = EColor.parse(init)) !== null && _a !== void 0 ? _a : new EColor(0, 0, 0);
28
+ const initColor = EColor.parse(init) ?? new EColor(0, 0, 0);
30
29
  // Factors elements
31
30
  // 51 = '00', '33', '66', '99', 'cc', 'ff'
32
31
  const factors = [];
@@ -71,7 +71,7 @@ export var DateUtils;
71
71
  if (parsed == null)
72
72
  return undefined;
73
73
  // Default options
74
- options !== null && options !== void 0 ? options : (options = DateUtils.DayFormat);
74
+ options ?? (options = DateUtils.DayFormat);
75
75
  // Default options
76
76
  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat
77
77
  let opt;
@@ -4,8 +4,8 @@ import { DateUtils } from './DateUtils';
4
4
  import { Utils } from './Utils';
5
5
  if (typeof navigator === 'undefined') {
6
6
  // Test mock only
7
- global.navigator = { language: 'en-US' };
8
- global.location = { href: 'http://localhost/' };
7
+ globalThis.navigator = { language: 'en-US' };
8
+ globalThis.location = { href: 'http://localhost/' };
9
9
  }
10
10
  /**
11
11
  * Dom Utilities
@@ -90,15 +90,14 @@ export var DomUtils;
90
90
  }
91
91
  DomUtils.clearFormData = clearFormData;
92
92
  function dataAsTraveller(source, data, template, keepSource, isValue) {
93
- var _a;
94
93
  // Properties
95
94
  const properties = Object.keys(template);
96
95
  // Entries
97
96
  const entries = Object.entries(isFormData(source) ? formDataToObject(source) : source);
98
97
  for (const [key, value] of entries) {
99
98
  // Is included or keepSource
100
- const property = (_a = properties.find((p) => p.localeCompare(key, 'en', { sensitivity: 'base' }) ===
101
- 0)) !== null && _a !== void 0 ? _a : (keepSource ? key : undefined);
99
+ const property = properties.find((p) => p.localeCompare(key, 'en', { sensitivity: 'base' }) ===
100
+ 0) ?? (keepSource ? key : undefined);
102
101
  if (property == null)
103
102
  continue;
104
103
  // Template value
@@ -165,12 +164,13 @@ export var DomUtils;
165
164
  * Current detected country
166
165
  */
167
166
  DomUtils.detectedCountry = (() => {
168
- var _a, _b;
169
167
  // URL first, then local storage
170
168
  let country;
171
169
  try {
172
170
  country =
173
- (_b = (_a = new URL(location.href).searchParams.get(DomUtils.CountryField)) !== null && _a !== void 0 ? _a : sessionStorage.getItem(DomUtils.CountryField)) !== null && _b !== void 0 ? _b : localStorage.getItem(DomUtils.CountryField);
171
+ new URL(location.href).searchParams.get(DomUtils.CountryField) ??
172
+ sessionStorage.getItem(DomUtils.CountryField) ??
173
+ localStorage.getItem(DomUtils.CountryField);
174
174
  }
175
175
  catch {
176
176
  country = null;
@@ -182,12 +182,13 @@ export var DomUtils;
182
182
  * Current detected culture
183
183
  */
184
184
  DomUtils.detectedCulture = (() => {
185
- var _a, _b;
186
185
  // URL first, then local storage
187
186
  let culture;
188
187
  try {
189
188
  culture =
190
- (_b = (_a = new URL(location.href).searchParams.get(DomUtils.CultureField)) !== null && _a !== void 0 ? _a : sessionStorage.getItem(DomUtils.CultureField)) !== null && _b !== void 0 ? _b : localStorage.getItem(DomUtils.CultureField);
189
+ new URL(location.href).searchParams.get(DomUtils.CultureField) ??
190
+ sessionStorage.getItem(DomUtils.CultureField) ??
191
+ localStorage.getItem(DomUtils.CultureField);
191
192
  }
192
193
  catch {
193
194
  culture = null;
@@ -359,11 +360,8 @@ export var DomUtils;
359
360
  if (exactMatch)
360
361
  return [exactMatch, CultureMatch.Exact];
361
362
  // Compatible match
362
- const compatibleMatch = items.find((item) => {
363
- var _a;
364
- return ((_a = item.compatibleNames) === null || _a === void 0 ? void 0 : _a.includes(culture)) ||
365
- culture.startsWith(item + '-');
366
- });
363
+ const compatibleMatch = items.find((item) => item.compatibleNames?.includes(culture) ||
364
+ culture.startsWith(item + '-'));
367
365
  if (compatibleMatch)
368
366
  return [compatibleMatch, CultureMatch.Compatible];
369
367
  // Same part, like zh-CN and zh-HK
@@ -380,7 +378,6 @@ export var DomUtils;
380
378
  * @returns Result
381
379
  */
382
380
  function getInputValue(input) {
383
- var _a;
384
381
  const type = input.type;
385
382
  if (type === 'number' || type === 'range') {
386
383
  const num = input.valueAsNumber;
@@ -389,7 +386,7 @@ export var DomUtils;
389
386
  return num;
390
387
  }
391
388
  else if (type === 'date' || type === 'datetime-local')
392
- return (_a = input.valueAsDate) !== null && _a !== void 0 ? _a : DateUtils.parse(input.value);
389
+ return input.valueAsDate ?? DateUtils.parse(input.value);
393
390
  return input.value;
394
391
  }
395
392
  DomUtils.getInputValue = getInputValue;
@@ -490,7 +487,7 @@ export var DomUtils;
490
487
  */
491
488
  function setFocus(name, container) {
492
489
  const elementName = typeof name === 'string' ? name : Object.keys(name)[0];
493
- container !== null && container !== void 0 ? container : (container = document.body);
490
+ container ?? (container = document.body);
494
491
  const element = container.querySelector(`[name="${elementName}"]`);
495
492
  if (element != null)
496
493
  element.focus();
@@ -502,13 +499,11 @@ export var DomUtils;
502
499
  * @param preventDefault Is prevent default action
503
500
  */
504
501
  function setupLogging(action, preventDefault) {
505
- var _a, _b;
506
502
  // Avoid multiple setup, if there is already a handler, please set "globalThis.onunhandledrejection = null" first
507
503
  if (globalThis.onunhandledrejection)
508
504
  return;
509
- const errorPD = (_a = Utils.getResult(preventDefault, 'error')) !== null && _a !== void 0 ? _a : true;
505
+ const errorPD = Utils.getResult(preventDefault, 'error') ?? true;
510
506
  globalThis.onerror = (message, source, lineNo, colNo, error) => {
511
- var _a;
512
507
  // Default source
513
508
  source || (source = globalThis.location.href);
514
509
  let data;
@@ -519,25 +514,26 @@ export var DomUtils;
519
514
  source,
520
515
  lineNo,
521
516
  colNo,
522
- stack: error === null || error === void 0 ? void 0 : error.stack
517
+ stack: error?.stack
523
518
  };
524
519
  }
525
520
  else {
526
521
  data = {
527
522
  type: 'error',
528
523
  eventType: message.type,
529
- message: (_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : `${message.currentTarget} event error`,
524
+ message: error?.message ??
525
+ `${message.currentTarget} event error`,
530
526
  source,
531
527
  lineNo,
532
528
  colNo,
533
- stack: error === null || error === void 0 ? void 0 : error.stack
529
+ stack: error?.stack
534
530
  };
535
531
  }
536
532
  action(data);
537
533
  // Return true to suppress error alert
538
534
  return errorPD;
539
535
  };
540
- const rejectionPD = (_b = Utils.getResult(preventDefault, 'error')) !== null && _b !== void 0 ? _b : true;
536
+ const rejectionPD = Utils.getResult(preventDefault, 'error') ?? true;
541
537
  globalThis.onunhandledrejection = (event) => {
542
538
  if (rejectionPD)
543
539
  event.preventDefault();
@@ -553,8 +549,7 @@ export var DomUtils;
553
549
  action(data);
554
550
  };
555
551
  const localConsole = (type, orgin) => {
556
- var _a;
557
- const consolePD = (_a = Utils.getResult(preventDefault, type)) !== null && _a !== void 0 ? _a : false;
552
+ const consolePD = Utils.getResult(preventDefault, type) ?? false;
558
553
  return (...args) => {
559
554
  // Keep original action
560
555
  if (!consolePD)
@@ -39,7 +39,7 @@ export var ExtendUtils;
39
39
  cancel = waitFor(() => {
40
40
  func(...args);
41
41
  cancel = undefined;
42
- }, miliseconds !== null && miliseconds !== void 0 ? miliseconds : delayMiliseconds);
42
+ }, miliseconds ?? delayMiliseconds);
43
43
  },
44
44
  /**
45
45
  * Clear
@@ -31,19 +31,18 @@ export var NumberUtils;
31
31
  * @returns Result
32
32
  */
33
33
  function formatMoney(input, currency, locale, isInteger = false, options = {}) {
34
- var _a, _b, _c, _d;
35
34
  if (currency) {
36
35
  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat
37
36
  options.style = 'currency';
38
37
  options.currency = currency;
39
- (_a = options.currencyDisplay) !== null && _a !== void 0 ? _a : (options.currencyDisplay = 'narrowSymbol');
38
+ options.currencyDisplay ?? (options.currencyDisplay = 'narrowSymbol');
40
39
  }
41
40
  if (isInteger) {
42
- (_b = options.minimumFractionDigits) !== null && _b !== void 0 ? _b : (options.minimumFractionDigits = 0);
43
- (_c = options.maximumFractionDigits) !== null && _c !== void 0 ? _c : (options.maximumFractionDigits = 0);
41
+ options.minimumFractionDigits ?? (options.minimumFractionDigits = 0);
42
+ options.maximumFractionDigits ?? (options.maximumFractionDigits = 0);
44
43
  }
45
44
  else
46
- (_d = options.minimumFractionDigits) !== null && _d !== void 0 ? _d : (options.minimumFractionDigits = 2);
45
+ options.minimumFractionDigits ?? (options.minimumFractionDigits = 2);
47
46
  return format(input, locale, options);
48
47
  }
49
48
  NumberUtils.formatMoney = formatMoney;
@@ -68,14 +67,13 @@ export var NumberUtils;
68
67
  * @returns Result
69
68
  */
70
69
  function getCurrencySymbol(code, display = 'narrowSymbol', locale) {
71
- var _a;
72
70
  const formatter = new Intl.NumberFormat(locale, {
73
71
  style: 'currency',
74
72
  currency: code,
75
73
  currencyDisplay: display
76
74
  });
77
75
  const parts = formatter.formatToParts();
78
- const symbol = (_a = parts.find((part) => part.type === 'currency')) === null || _a === void 0 ? void 0 : _a.value;
76
+ const symbol = parts.find((part) => part.type === 'currency')?.value;
79
77
  return symbol;
80
78
  }
81
79
  NumberUtils.getCurrencySymbol = getCurrencySymbol;
@@ -1,9 +1,8 @@
1
- var _a, _b;
2
1
  import { NodeStorage } from './node/Storage';
3
2
  import { Utils } from './Utils';
4
3
  // Mock node
5
- (_a = globalThis.localStorage) !== null && _a !== void 0 ? _a : (globalThis.localStorage = new NodeStorage());
6
- (_b = globalThis.sessionStorage) !== null && _b !== void 0 ? _b : (globalThis.sessionStorage = new NodeStorage());
4
+ globalThis.localStorage ?? (globalThis.localStorage = new NodeStorage());
5
+ globalThis.sessionStorage ?? (globalThis.sessionStorage = new NodeStorage());
7
6
  /**
8
7
  * Storage utilities
9
8
  * NodeStorage needs data persistance
package/lib/mjs/Utils.js CHANGED
@@ -49,7 +49,7 @@ String.prototype.hideEmail = function () {
49
49
  return this.hideData('@');
50
50
  };
51
51
  String.prototype.isDigits = function (minLength) {
52
- return this.length >= (minLength !== null && minLength !== void 0 ? minLength : 0) && /^\d+$/.test(this);
52
+ return this.length >= (minLength ?? 0) && /^\d+$/.test(this);
53
53
  };
54
54
  String.prototype.isEmail = function () {
55
55
  const re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
@@ -72,11 +72,11 @@ export var Utils;
72
72
  */
73
73
  function addBlankItem(options, idField, labelField, blankLabel) {
74
74
  // Avoid duplicate blank items
75
- idField !== null && idField !== void 0 ? idField : (idField = 'id');
75
+ idField ?? (idField = 'id');
76
76
  if (options.length === 0 || Reflect.get(options[0], idField) !== '') {
77
77
  const blankItem = {
78
78
  [idField]: '',
79
- [typeof labelField === 'string' ? labelField : 'label']: blankLabel !== null && blankLabel !== void 0 ? blankLabel : '---'
79
+ [typeof labelField === 'string' ? labelField : 'label']: blankLabel ?? '---'
80
80
  };
81
81
  options.unshift(blankItem);
82
82
  }
@@ -193,7 +193,6 @@ export var Utils;
193
193
  // Changed fields
194
194
  const changes = [];
195
195
  Object.entries(input).forEach(([key, value]) => {
196
- var _a;
197
196
  // Ignore fields, no process
198
197
  if (ignoreFields.includes(key))
199
198
  return;
@@ -208,7 +207,7 @@ export var Utils;
208
207
  // Date when meets string
209
208
  if (value instanceof Date) {
210
209
  if (value.valueOf() ===
211
- ((_a = DateUtils.parse(initValue)) === null || _a === void 0 ? void 0 : _a.valueOf())) {
210
+ DateUtils.parse(initValue)?.valueOf()) {
212
211
  Reflect.deleteProperty(input, key);
213
212
  return;
214
213
  }
@@ -478,7 +477,7 @@ export var Utils;
478
477
  * @returns Result
479
478
  */
480
479
  Utils.removeNonLetters = (input) => {
481
- return input === null || input === void 0 ? void 0 : input.removeNonLetters();
480
+ return input?.removeNonLetters();
482
481
  };
483
482
  /**
484
483
  * Replace null or empty with default value
@@ -499,9 +498,8 @@ export var Utils;
499
498
  */
500
499
  Utils.setLabels = (source, labels, reference) => {
501
500
  Object.keys(source).forEach((key) => {
502
- var _a;
503
501
  // Reference key
504
- const labelKey = reference == null ? key : (_a = reference[key]) !== null && _a !== void 0 ? _a : key;
502
+ const labelKey = reference == null ? key : reference[key] ?? key;
505
503
  // Label
506
504
  const label = labels[labelKey];
507
505
  if (label != null) {
@@ -61,7 +61,7 @@ export class ContentDisposition {
61
61
  }
62
62
  }
63
63
  if (type === 'form-data') {
64
- return new ContentDisposition(type, filename, name !== null && name !== void 0 ? name : 'file');
64
+ return new ContentDisposition(type, filename, name ?? 'file');
65
65
  }
66
66
  if (type === 'inline' || type === 'attachment') {
67
67
  return new ContentDisposition(type, filename);
@@ -214,7 +214,7 @@ export class EColor {
214
214
  includeAlpha = alpha;
215
215
  }
216
216
  if (includeAlpha)
217
- return `RGBA(${this.r}, ${this.g}, ${this.b}, ${alphaValue !== null && alphaValue !== void 0 ? alphaValue : 1})`;
217
+ return `RGBA(${this.r}, ${this.g}, ${this.b}, ${alphaValue ?? 1})`;
218
218
  return `RGB(${this.r}, ${this.g}, ${this.b})`;
219
219
  }
220
220
  }
@@ -85,11 +85,10 @@ export class EventClass {
85
85
  * @param options Options
86
86
  */
87
87
  on(type, callback, options) {
88
- var _a, _b;
89
88
  if (typeof type === 'object') {
90
89
  for (const key in type) {
91
90
  const item = key;
92
- const itemCallback = (_a = type[item]) !== null && _a !== void 0 ? _a : callback;
91
+ const itemCallback = type[item] ?? callback;
93
92
  if (itemCallback)
94
93
  this.on(item, itemCallback, options);
95
94
  }
@@ -100,7 +99,7 @@ export class EventClass {
100
99
  this.listeners.has(type) || this.listeners.set(type, []);
101
100
  // String to T conversion problem
102
101
  // "keyofStringsOnly": true could solve part of it
103
- (_b = this.listeners.get(type)) === null || _b === void 0 ? void 0 : _b.push([callback, options]);
102
+ this.listeners.get(type)?.push([callback, options]);
104
103
  }
105
104
  /**
106
105
  * Trigger event
@@ -136,10 +135,10 @@ export class EventClass {
136
135
  for (let c = 0; c < len; c++) {
137
136
  const item = items[c];
138
137
  const [callback, options] = item;
139
- if (options === null || options === void 0 ? void 0 : options.capture)
138
+ if (options?.capture)
140
139
  continue;
141
140
  callback(event);
142
- if (options === null || options === void 0 ? void 0 : options.once) {
141
+ if (options?.once) {
143
142
  indicies.push(c);
144
143
  }
145
144
  if (event.propagationStopped) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/shared",
3
- "version": "1.2.26",
3
+ "version": "1.2.28",
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
@@ -7,8 +7,8 @@ import { FormDataFieldValue, IFormData } from './types/FormData';
7
7
 
8
8
  if (typeof navigator === 'undefined') {
9
9
  // Test mock only
10
- global.navigator = { language: 'en-US' } as any;
11
- global.location = { href: 'http://localhost/' } as any;
10
+ globalThis.navigator = { language: 'en-US' } as any;
11
+ globalThis.location = { href: 'http://localhost/' } as any;
12
12
  }
13
13
 
14
14
  /**
package/tsconfig.cjs.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  /* Visit https://aka.ms/tsconfig.json to read more about this file */
4
- "target": "ES2019",
5
- "module": "commonjs",
6
- "moduleResolution": "node",
4
+ "target": "ES2020",
5
+ "module": "CommonJS",
6
+ "moduleResolution": "Node",
7
7
  "isolatedModules": true,
8
8
  "outDir": "./lib/cjs",
9
9
  "noEmit": false,
package/tsconfig.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  /* Visit https://aka.ms/tsconfig.json to read more about this file */
4
- "target": "ES2019",
4
+ "target": "ES2020",
5
5
  "module": "ESNext",
6
- "moduleResolution": "node",
6
+ "moduleResolution": "bundler",
7
7
  "isolatedModules": true,
8
8
  "outDir": "./lib/mjs",
9
9
  "noEmit": false,