@etsoo/shared 1.2.4 → 1.2.5

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
@@ -205,6 +205,7 @@ DOM/window related utilities
205
205
  |detectedCulture|Current detected culture|
206
206
  |dimensionEqual|Check two rectangles equality|
207
207
  |downloadFile|Download file from API fetch response body|
208
+ |en|Get English resources definition|
208
209
  |fileToDataURL|File to data URL|
209
210
  |formDataToObject|Form data to object|
210
211
  |getCulture|Get the available culture definition|
@@ -218,6 +219,8 @@ DOM/window related utilities
218
219
  |mergeURLSearchParams|Merge URL search parameters|
219
220
  |setFocus|Set HTML element focus by name|
220
221
  |verifyPermission|Verify file system permission|
222
+ |zhHans|Get simplified Chinese resources definition|
223
+ |zhHant|Get traditional Chinese resources definition|
221
224
 
222
225
  ## ExtendUtils
223
226
  Extend current class/object functioning
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "target": "ES6",
3
+ "target": "ES2019",
4
4
  "module": "ESNext",
5
5
  "allowJs": true,
6
6
  "skipLibCheck": true,
@@ -57,7 +57,10 @@ var DataTypes;
57
57
  /**
58
58
  * Combined type enum
59
59
  */
60
- DataTypes.CombinedEnum = Object.assign(Object.assign({}, SimpleEnum), ExtendedEnum);
60
+ DataTypes.CombinedEnum = {
61
+ ...SimpleEnum,
62
+ ...ExtendedEnum
63
+ };
61
64
  /**
62
65
  * Horizontal align enum
63
66
  */
@@ -47,11 +47,19 @@ var DateUtils;
47
47
  /**
48
48
  * Minute format, YYYY-MM-DD hh:mm
49
49
  */
50
- DateUtils.MinuteFormat = Object.assign(Object.assign({}, DateUtils.DayFormat), { hour: '2-digit', hourCycle: 'h23', minute: '2-digit' });
50
+ DateUtils.MinuteFormat = {
51
+ ...DateUtils.DayFormat,
52
+ hour: '2-digit',
53
+ hourCycle: 'h23',
54
+ minute: '2-digit'
55
+ };
51
56
  /**
52
57
  * Second format, YYYY-MM-DD hh:mm:ss
53
58
  */
54
- DateUtils.SecondFormat = Object.assign(Object.assign({}, DateUtils.MinuteFormat), { second: '2-digit' });
59
+ DateUtils.SecondFormat = {
60
+ ...DateUtils.MinuteFormat,
61
+ second: '2-digit'
62
+ };
55
63
  /**
56
64
  * Format
57
65
  * @param input Input date time
@@ -84,7 +92,7 @@ var DateUtils;
84
92
  opt = options;
85
93
  }
86
94
  // Clone as new options with time zone
87
- const newOpt = Object.assign(Object.assign({}, opt), (timeZone != null && { timeZone }));
95
+ const newOpt = { ...opt, ...(timeZone != null && { timeZone }) };
88
96
  // Return format result
89
97
  return new Intl.DateTimeFormat(locale, newOpt)
90
98
  .format(parsed)
@@ -79,6 +79,24 @@ export declare namespace DomUtils {
79
79
  SamePart = 2,
80
80
  Default = 3
81
81
  }
82
+ /**
83
+ * Get English resources definition
84
+ * @param resources Resources
85
+ * @returns Result
86
+ */
87
+ const en: <T extends DataTypes.StringRecord = DataTypes.StringRecord>(resources: T | (() => Promise<T>)) => DataTypes.CultureDefinition<T>;
88
+ /**
89
+ * Get simplified Chinese resources definition
90
+ * @param resources Resources
91
+ * @returns Result
92
+ */
93
+ const zhHans: <T extends DataTypes.StringRecord = DataTypes.StringRecord>(resources: T | (() => Promise<T>)) => DataTypes.CultureDefinition<T>;
94
+ /**
95
+ * Get traditional Chinese resources definition
96
+ * @param resources Resources
97
+ * @returns Result
98
+ */
99
+ const zhHant: <T extends DataTypes.StringRecord = DataTypes.StringRecord>(resources: T | (() => Promise<T>)) => DataTypes.CultureDefinition<T>;
82
100
  /**
83
101
  * Get the available culture definition
84
102
  * @param items Available cultures
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.DomUtils = void 0;
13
4
  /// <reference lib="dom" />
@@ -182,7 +173,7 @@ var DomUtils;
182
173
  country =
183
174
  (_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);
184
175
  }
185
- catch (_c) {
176
+ catch {
186
177
  country = null;
187
178
  }
188
179
  // Return
@@ -199,7 +190,7 @@ var DomUtils;
199
190
  culture =
200
191
  (_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);
201
192
  }
202
- catch (_c) {
193
+ catch {
203
194
  culture = null;
204
195
  }
205
196
  // Browser detected
@@ -238,46 +229,44 @@ var DomUtils;
238
229
  * @param suggestedName Suggested file name
239
230
  * @param autoDetect Auto detect, false will use link click way
240
231
  */
241
- function downloadFile(data, suggestedName, autoDetect = true) {
242
- return __awaiter(this, void 0, void 0, function* () {
243
- try {
244
- if (autoDetect && 'showSaveFilePicker' in globalThis) {
245
- // AbortError - Use dismisses the window
246
- const handle = yield globalThis.showSaveFilePicker({
247
- suggestedName
248
- });
249
- if (!(yield verifyPermission(handle, true)))
250
- return undefined;
251
- const stream = yield handle.createWritable();
252
- if (data instanceof Blob) {
253
- data.stream().pipeTo(stream);
254
- }
255
- else {
256
- yield data.pipeTo(stream);
257
- }
258
- return true;
232
+ async function downloadFile(data, suggestedName, autoDetect = true) {
233
+ try {
234
+ if (autoDetect && 'showSaveFilePicker' in globalThis) {
235
+ // AbortError - Use dismisses the window
236
+ const handle = await globalThis.showSaveFilePicker({
237
+ suggestedName
238
+ });
239
+ if (!(await verifyPermission(handle, true)))
240
+ return undefined;
241
+ const stream = await handle.createWritable();
242
+ if (data instanceof Blob) {
243
+ data.stream().pipeTo(stream);
259
244
  }
260
245
  else {
261
- const url = window.URL.createObjectURL(data instanceof Blob
262
- ? data
263
- : yield new Response(data).blob());
264
- const a = document.createElement('a');
265
- a.style.display = 'none';
266
- a.href = url;
267
- if (suggestedName)
268
- a.download = suggestedName;
269
- document.body.appendChild(a);
270
- a.click();
271
- a.remove();
272
- window.URL.revokeObjectURL(url);
273
- return true;
246
+ await data.pipeTo(stream);
274
247
  }
248
+ return true;
275
249
  }
276
- catch (e) {
277
- console.log(e);
250
+ else {
251
+ const url = window.URL.createObjectURL(data instanceof Blob
252
+ ? data
253
+ : await new Response(data).blob());
254
+ const a = document.createElement('a');
255
+ a.style.display = 'none';
256
+ a.href = url;
257
+ if (suggestedName)
258
+ a.download = suggestedName;
259
+ document.body.appendChild(a);
260
+ a.click();
261
+ a.remove();
262
+ window.URL.revokeObjectURL(url);
263
+ return true;
278
264
  }
279
- return false;
280
- });
265
+ }
266
+ catch (e) {
267
+ console.log(e);
268
+ }
269
+ return false;
281
270
  }
282
271
  DomUtils.downloadFile = downloadFile;
283
272
  /**
@@ -285,21 +274,19 @@ var DomUtils;
285
274
  * @param file File
286
275
  * @returns Data URL
287
276
  */
288
- function fileToDataURL(file) {
289
- return __awaiter(this, void 0, void 0, function* () {
290
- return new Promise((resolve, reject) => {
291
- const reader = new FileReader();
292
- reader.onerror = reject;
293
- reader.onload = () => {
294
- const data = reader.result;
295
- if (data == null) {
296
- reject();
297
- return;
298
- }
299
- resolve(data);
300
- };
301
- reader.readAsDataURL(file);
302
- });
277
+ async function fileToDataURL(file) {
278
+ return new Promise((resolve, reject) => {
279
+ const reader = new FileReader();
280
+ reader.onerror = reject;
281
+ reader.onload = () => {
282
+ const data = reader.result;
283
+ if (data == null) {
284
+ reject();
285
+ return;
286
+ }
287
+ resolve(data);
288
+ };
289
+ reader.readAsDataURL(file);
303
290
  });
304
291
  }
305
292
  DomUtils.fileToDataURL = fileToDataURL;
@@ -327,6 +314,38 @@ var DomUtils;
327
314
  CultureMatch[CultureMatch["SamePart"] = 2] = "SamePart";
328
315
  CultureMatch[CultureMatch["Default"] = 3] = "Default";
329
316
  })(CultureMatch = DomUtils.CultureMatch || (DomUtils.CultureMatch = {}));
317
+ /**
318
+ * Get English resources definition
319
+ * @param resources Resources
320
+ * @returns Result
321
+ */
322
+ DomUtils.en = (resources) => ({
323
+ name: 'en',
324
+ label: 'English',
325
+ resources
326
+ });
327
+ /**
328
+ * Get simplified Chinese resources definition
329
+ * @param resources Resources
330
+ * @returns Result
331
+ */
332
+ DomUtils.zhHans = (resources) => ({
333
+ name: 'zh-Hans',
334
+ label: '简体中文',
335
+ resources,
336
+ compatibleNames: ['zh-CN', 'zh-SG']
337
+ });
338
+ /**
339
+ * Get traditional Chinese resources definition
340
+ * @param resources Resources
341
+ * @returns Result
342
+ */
343
+ DomUtils.zhHant = (resources) => ({
344
+ name: 'zh-Hant',
345
+ label: '繁體中文',
346
+ resources,
347
+ compatibleNames: ['zh-HK', 'zh-TW', 'zh-MO']
348
+ });
330
349
  /**
331
350
  * Get the available culture definition
332
351
  * @param items Available cultures
@@ -484,24 +503,22 @@ var DomUtils;
484
503
  * @param withWrite With write permission
485
504
  * @returns Result
486
505
  */
487
- function verifyPermission(fileHandle, withWrite = false) {
488
- return __awaiter(this, void 0, void 0, function* () {
489
- if (!('queryPermission' in fileHandle) ||
490
- !('requestPermission' in fileHandle))
491
- return false;
492
- // FileSystemHandlePermissionDescriptor
493
- const opts = { mode: withWrite ? 'readwrite' : 'read' };
494
- // Check if we already have permission, if so, return true.
495
- if ((yield fileHandle.queryPermission(opts)) === 'granted') {
496
- return true;
497
- }
498
- // Request permission to the file, if the user grants permission, return true.
499
- if ((yield fileHandle.requestPermission(opts)) === 'granted') {
500
- return true;
501
- }
502
- // The user did not grant permission, return false.
506
+ async function verifyPermission(fileHandle, withWrite = false) {
507
+ if (!('queryPermission' in fileHandle) ||
508
+ !('requestPermission' in fileHandle))
503
509
  return false;
504
- });
510
+ // FileSystemHandlePermissionDescriptor
511
+ const opts = { mode: withWrite ? 'readwrite' : 'read' };
512
+ // Check if we already have permission, if so, return true.
513
+ if ((await fileHandle.queryPermission(opts)) === 'granted') {
514
+ return true;
515
+ }
516
+ // Request permission to the file, if the user grants permission, return true.
517
+ if ((await fileHandle.requestPermission(opts)) === 'granted') {
518
+ return true;
519
+ }
520
+ // The user did not grant permission, return false.
521
+ return false;
505
522
  }
506
523
  DomUtils.verifyPermission = verifyPermission;
507
524
  })(DomUtils = exports.DomUtils || (exports.DomUtils = {}));
package/lib/cjs/Utils.js CHANGED
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -171,13 +162,11 @@ var Utils;
171
162
  * @param excludedValues Excluded values
172
163
  * @returns Result
173
164
  */
174
- function excludeAsync(items, field, ...excludedValues) {
175
- return __awaiter(this, void 0, void 0, function* () {
176
- const result = yield items;
177
- if (result == null)
178
- return result;
179
- return exclude(result, field, ...excludedValues);
180
- });
165
+ async function excludeAsync(items, field, ...excludedValues) {
166
+ const result = await items;
167
+ if (result == null)
168
+ return result;
169
+ return exclude(result, field, ...excludedValues);
181
170
  }
182
171
  Utils.excludeAsync = excludeAsync;
183
172
  /**
@@ -428,7 +417,7 @@ var Utils;
428
417
  // Return
429
418
  return json;
430
419
  }
431
- catch (_a) {
420
+ catch {
432
421
  if (defaultValue == null)
433
422
  return input;
434
423
  return defaultValue;
@@ -54,7 +54,10 @@ export var DataTypes;
54
54
  /**
55
55
  * Combined type enum
56
56
  */
57
- DataTypes.CombinedEnum = Object.assign(Object.assign({}, SimpleEnum), ExtendedEnum);
57
+ DataTypes.CombinedEnum = {
58
+ ...SimpleEnum,
59
+ ...ExtendedEnum
60
+ };
58
61
  /**
59
62
  * Horizontal align enum
60
63
  */
@@ -44,11 +44,19 @@ export var DateUtils;
44
44
  /**
45
45
  * Minute format, YYYY-MM-DD hh:mm
46
46
  */
47
- DateUtils.MinuteFormat = Object.assign(Object.assign({}, DateUtils.DayFormat), { hour: '2-digit', hourCycle: 'h23', minute: '2-digit' });
47
+ DateUtils.MinuteFormat = {
48
+ ...DateUtils.DayFormat,
49
+ hour: '2-digit',
50
+ hourCycle: 'h23',
51
+ minute: '2-digit'
52
+ };
48
53
  /**
49
54
  * Second format, YYYY-MM-DD hh:mm:ss
50
55
  */
51
- DateUtils.SecondFormat = Object.assign(Object.assign({}, DateUtils.MinuteFormat), { second: '2-digit' });
56
+ DateUtils.SecondFormat = {
57
+ ...DateUtils.MinuteFormat,
58
+ second: '2-digit'
59
+ };
52
60
  /**
53
61
  * Format
54
62
  * @param input Input date time
@@ -81,7 +89,7 @@ export var DateUtils;
81
89
  opt = options;
82
90
  }
83
91
  // Clone as new options with time zone
84
- const newOpt = Object.assign(Object.assign({}, opt), (timeZone != null && { timeZone }));
92
+ const newOpt = { ...opt, ...(timeZone != null && { timeZone }) };
85
93
  // Return format result
86
94
  return new Intl.DateTimeFormat(locale, newOpt)
87
95
  .format(parsed)
@@ -79,6 +79,24 @@ export declare namespace DomUtils {
79
79
  SamePart = 2,
80
80
  Default = 3
81
81
  }
82
+ /**
83
+ * Get English resources definition
84
+ * @param resources Resources
85
+ * @returns Result
86
+ */
87
+ const en: <T extends DataTypes.StringRecord = DataTypes.StringRecord>(resources: T | (() => Promise<T>)) => DataTypes.CultureDefinition<T>;
88
+ /**
89
+ * Get simplified Chinese resources definition
90
+ * @param resources Resources
91
+ * @returns Result
92
+ */
93
+ const zhHans: <T extends DataTypes.StringRecord = DataTypes.StringRecord>(resources: T | (() => Promise<T>)) => DataTypes.CultureDefinition<T>;
94
+ /**
95
+ * Get traditional Chinese resources definition
96
+ * @param resources Resources
97
+ * @returns Result
98
+ */
99
+ const zhHant: <T extends DataTypes.StringRecord = DataTypes.StringRecord>(resources: T | (() => Promise<T>)) => DataTypes.CultureDefinition<T>;
82
100
  /**
83
101
  * Get the available culture definition
84
102
  * @param items Available cultures
@@ -1,12 +1,3 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  /// <reference lib="dom" />
11
2
  import { DataTypes } from './DataTypes';
12
3
  if (typeof navigator === 'undefined') {
@@ -179,7 +170,7 @@ export var DomUtils;
179
170
  country =
180
171
  (_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);
181
172
  }
182
- catch (_c) {
173
+ catch {
183
174
  country = null;
184
175
  }
185
176
  // Return
@@ -196,7 +187,7 @@ export var DomUtils;
196
187
  culture =
197
188
  (_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);
198
189
  }
199
- catch (_c) {
190
+ catch {
200
191
  culture = null;
201
192
  }
202
193
  // Browser detected
@@ -235,46 +226,44 @@ export var DomUtils;
235
226
  * @param suggestedName Suggested file name
236
227
  * @param autoDetect Auto detect, false will use link click way
237
228
  */
238
- function downloadFile(data, suggestedName, autoDetect = true) {
239
- return __awaiter(this, void 0, void 0, function* () {
240
- try {
241
- if (autoDetect && 'showSaveFilePicker' in globalThis) {
242
- // AbortError - Use dismisses the window
243
- const handle = yield globalThis.showSaveFilePicker({
244
- suggestedName
245
- });
246
- if (!(yield verifyPermission(handle, true)))
247
- return undefined;
248
- const stream = yield handle.createWritable();
249
- if (data instanceof Blob) {
250
- data.stream().pipeTo(stream);
251
- }
252
- else {
253
- yield data.pipeTo(stream);
254
- }
255
- return true;
229
+ async function downloadFile(data, suggestedName, autoDetect = true) {
230
+ try {
231
+ if (autoDetect && 'showSaveFilePicker' in globalThis) {
232
+ // AbortError - Use dismisses the window
233
+ const handle = await globalThis.showSaveFilePicker({
234
+ suggestedName
235
+ });
236
+ if (!(await verifyPermission(handle, true)))
237
+ return undefined;
238
+ const stream = await handle.createWritable();
239
+ if (data instanceof Blob) {
240
+ data.stream().pipeTo(stream);
256
241
  }
257
242
  else {
258
- const url = window.URL.createObjectURL(data instanceof Blob
259
- ? data
260
- : yield new Response(data).blob());
261
- const a = document.createElement('a');
262
- a.style.display = 'none';
263
- a.href = url;
264
- if (suggestedName)
265
- a.download = suggestedName;
266
- document.body.appendChild(a);
267
- a.click();
268
- a.remove();
269
- window.URL.revokeObjectURL(url);
270
- return true;
243
+ await data.pipeTo(stream);
271
244
  }
245
+ return true;
272
246
  }
273
- catch (e) {
274
- console.log(e);
247
+ else {
248
+ const url = window.URL.createObjectURL(data instanceof Blob
249
+ ? data
250
+ : await new Response(data).blob());
251
+ const a = document.createElement('a');
252
+ a.style.display = 'none';
253
+ a.href = url;
254
+ if (suggestedName)
255
+ a.download = suggestedName;
256
+ document.body.appendChild(a);
257
+ a.click();
258
+ a.remove();
259
+ window.URL.revokeObjectURL(url);
260
+ return true;
275
261
  }
276
- return false;
277
- });
262
+ }
263
+ catch (e) {
264
+ console.log(e);
265
+ }
266
+ return false;
278
267
  }
279
268
  DomUtils.downloadFile = downloadFile;
280
269
  /**
@@ -282,21 +271,19 @@ export var DomUtils;
282
271
  * @param file File
283
272
  * @returns Data URL
284
273
  */
285
- function fileToDataURL(file) {
286
- return __awaiter(this, void 0, void 0, function* () {
287
- return new Promise((resolve, reject) => {
288
- const reader = new FileReader();
289
- reader.onerror = reject;
290
- reader.onload = () => {
291
- const data = reader.result;
292
- if (data == null) {
293
- reject();
294
- return;
295
- }
296
- resolve(data);
297
- };
298
- reader.readAsDataURL(file);
299
- });
274
+ async function fileToDataURL(file) {
275
+ return new Promise((resolve, reject) => {
276
+ const reader = new FileReader();
277
+ reader.onerror = reject;
278
+ reader.onload = () => {
279
+ const data = reader.result;
280
+ if (data == null) {
281
+ reject();
282
+ return;
283
+ }
284
+ resolve(data);
285
+ };
286
+ reader.readAsDataURL(file);
300
287
  });
301
288
  }
302
289
  DomUtils.fileToDataURL = fileToDataURL;
@@ -324,6 +311,38 @@ export var DomUtils;
324
311
  CultureMatch[CultureMatch["SamePart"] = 2] = "SamePart";
325
312
  CultureMatch[CultureMatch["Default"] = 3] = "Default";
326
313
  })(CultureMatch = DomUtils.CultureMatch || (DomUtils.CultureMatch = {}));
314
+ /**
315
+ * Get English resources definition
316
+ * @param resources Resources
317
+ * @returns Result
318
+ */
319
+ DomUtils.en = (resources) => ({
320
+ name: 'en',
321
+ label: 'English',
322
+ resources
323
+ });
324
+ /**
325
+ * Get simplified Chinese resources definition
326
+ * @param resources Resources
327
+ * @returns Result
328
+ */
329
+ DomUtils.zhHans = (resources) => ({
330
+ name: 'zh-Hans',
331
+ label: '简体中文',
332
+ resources,
333
+ compatibleNames: ['zh-CN', 'zh-SG']
334
+ });
335
+ /**
336
+ * Get traditional Chinese resources definition
337
+ * @param resources Resources
338
+ * @returns Result
339
+ */
340
+ DomUtils.zhHant = (resources) => ({
341
+ name: 'zh-Hant',
342
+ label: '繁體中文',
343
+ resources,
344
+ compatibleNames: ['zh-HK', 'zh-TW', 'zh-MO']
345
+ });
327
346
  /**
328
347
  * Get the available culture definition
329
348
  * @param items Available cultures
@@ -481,24 +500,22 @@ export var DomUtils;
481
500
  * @param withWrite With write permission
482
501
  * @returns Result
483
502
  */
484
- function verifyPermission(fileHandle, withWrite = false) {
485
- return __awaiter(this, void 0, void 0, function* () {
486
- if (!('queryPermission' in fileHandle) ||
487
- !('requestPermission' in fileHandle))
488
- return false;
489
- // FileSystemHandlePermissionDescriptor
490
- const opts = { mode: withWrite ? 'readwrite' : 'read' };
491
- // Check if we already have permission, if so, return true.
492
- if ((yield fileHandle.queryPermission(opts)) === 'granted') {
493
- return true;
494
- }
495
- // Request permission to the file, if the user grants permission, return true.
496
- if ((yield fileHandle.requestPermission(opts)) === 'granted') {
497
- return true;
498
- }
499
- // The user did not grant permission, return false.
503
+ async function verifyPermission(fileHandle, withWrite = false) {
504
+ if (!('queryPermission' in fileHandle) ||
505
+ !('requestPermission' in fileHandle))
500
506
  return false;
501
- });
507
+ // FileSystemHandlePermissionDescriptor
508
+ const opts = { mode: withWrite ? 'readwrite' : 'read' };
509
+ // Check if we already have permission, if so, return true.
510
+ if ((await fileHandle.queryPermission(opts)) === 'granted') {
511
+ return true;
512
+ }
513
+ // Request permission to the file, if the user grants permission, return true.
514
+ if ((await fileHandle.requestPermission(opts)) === 'granted') {
515
+ return true;
516
+ }
517
+ // The user did not grant permission, return false.
518
+ return false;
502
519
  }
503
520
  DomUtils.verifyPermission = verifyPermission;
504
521
  })(DomUtils || (DomUtils = {}));
package/lib/mjs/Utils.js CHANGED
@@ -1,12 +1,3 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import { DataTypes } from './DataTypes';
11
2
  import isEqual from 'lodash.isequal';
12
3
  import { DateUtils } from './DateUtils';
@@ -165,13 +156,11 @@ export var Utils;
165
156
  * @param excludedValues Excluded values
166
157
  * @returns Result
167
158
  */
168
- function excludeAsync(items, field, ...excludedValues) {
169
- return __awaiter(this, void 0, void 0, function* () {
170
- const result = yield items;
171
- if (result == null)
172
- return result;
173
- return exclude(result, field, ...excludedValues);
174
- });
159
+ async function excludeAsync(items, field, ...excludedValues) {
160
+ const result = await items;
161
+ if (result == null)
162
+ return result;
163
+ return exclude(result, field, ...excludedValues);
175
164
  }
176
165
  Utils.excludeAsync = excludeAsync;
177
166
  /**
@@ -422,7 +411,7 @@ export var Utils;
422
411
  // Return
423
412
  return json;
424
413
  }
425
- catch (_a) {
414
+ catch {
426
415
  if (defaultValue == null)
427
416
  return input;
428
417
  return defaultValue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/shared",
3
- "version": "1.2.4",
3
+ "version": "1.2.5",
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
@@ -374,6 +374,53 @@ export namespace DomUtils {
374
374
  Default
375
375
  }
376
376
 
377
+ /**
378
+ * Get English resources definition
379
+ * @param resources Resources
380
+ * @returns Result
381
+ */
382
+ export const en = <
383
+ T extends DataTypes.StringRecord = DataTypes.StringRecord
384
+ >(
385
+ resources: T | (() => Promise<T>)
386
+ ): DataTypes.CultureDefinition<T> => ({
387
+ name: 'en',
388
+ label: 'English',
389
+ resources
390
+ });
391
+
392
+ /**
393
+ * Get simplified Chinese resources definition
394
+ * @param resources Resources
395
+ * @returns Result
396
+ */
397
+ export const zhHans = <
398
+ T extends DataTypes.StringRecord = DataTypes.StringRecord
399
+ >(
400
+ resources: T | (() => Promise<T>)
401
+ ): DataTypes.CultureDefinition<T> => ({
402
+ name: 'zh-Hans',
403
+ label: '简体中文',
404
+ resources,
405
+ compatibleNames: ['zh-CN', 'zh-SG']
406
+ });
407
+
408
+ /**
409
+ * Get traditional Chinese resources definition
410
+ * @param resources Resources
411
+ * @returns Result
412
+ */
413
+ export const zhHant = <
414
+ T extends DataTypes.StringRecord = DataTypes.StringRecord
415
+ >(
416
+ resources: T | (() => Promise<T>)
417
+ ): DataTypes.CultureDefinition<T> => ({
418
+ name: 'zh-Hant',
419
+ label: '繁體中文',
420
+ resources,
421
+ compatibleNames: ['zh-HK', 'zh-TW', 'zh-MO']
422
+ });
423
+
377
424
  /**
378
425
  * Get the available culture definition
379
426
  * @param items Available cultures
package/tsconfig.cjs.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  /* Visit https://aka.ms/tsconfig.json to read more about this file */
4
- "target": "ES6",
4
+ "target": "ES2019",
5
5
  "module": "commonjs",
6
6
  "moduleResolution": "node",
7
7
  "isolatedModules": true,
package/tsconfig.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  /* Visit https://aka.ms/tsconfig.json to read more about this file */
4
- "target": "ES6",
4
+ "target": "ES2019",
5
5
  "module": "ESNext",
6
6
  "moduleResolution": "node",
7
7
  "isolatedModules": true,