@etsoo/shared 1.2.51 → 1.2.54
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/.github/workflows/main.yml +6 -5
- package/README.md +1 -1
- package/lib/cjs/ActionResult.d.ts +1 -1
- package/lib/cjs/ActionResult.js +3 -3
- package/lib/cjs/ArrayUtils.d.ts +1 -1
- package/lib/cjs/ArrayUtils.js +4 -4
- package/lib/cjs/ColorUtils.d.ts +1 -1
- package/lib/cjs/ColorUtils.js +2 -2
- package/lib/cjs/DataTypes.d.ts +6 -6
- package/lib/cjs/DataTypes.js +50 -51
- package/lib/cjs/DateUtils.d.ts +1 -1
- package/lib/cjs/DateUtils.js +27 -28
- package/lib/cjs/DomUtils.d.ts +3 -3
- package/lib/cjs/DomUtils.js +64 -73
- package/lib/cjs/ExtendUtils.d.ts +1 -1
- package/lib/cjs/ExtendUtils.js +6 -6
- package/lib/cjs/IActionResult.d.ts +15 -2
- package/lib/cjs/NumberUtils.d.ts +1 -1
- package/lib/cjs/NumberUtils.js +9 -9
- package/lib/cjs/StorageUtils.js +2 -2
- package/lib/cjs/Utils.d.ts +4 -4
- package/lib/cjs/Utils.js +58 -62
- package/lib/cjs/index.d.ts +22 -22
- package/lib/cjs/storage/WindowStorage.d.ts +1 -1
- package/lib/cjs/types/ContentDisposition.d.ts +2 -2
- package/lib/cjs/types/ContentDisposition.js +11 -13
- package/lib/cjs/types/EColor.js +5 -7
- package/lib/cjs/types/EHistory.d.ts +3 -3
- package/lib/cjs/types/EHistory.js +4 -4
- package/lib/cjs/types/ErrorData.d.ts +1 -1
- package/lib/cjs/types/EventClass.js +1 -1
- package/lib/mjs/ActionResult.d.ts +1 -1
- package/lib/mjs/ActionResult.js +3 -3
- package/lib/mjs/ArrayUtils.d.ts +1 -1
- package/lib/mjs/ArrayUtils.js +5 -5
- package/lib/mjs/ColorUtils.d.ts +1 -1
- package/lib/mjs/ColorUtils.js +3 -3
- package/lib/mjs/DataTypes.d.ts +6 -6
- package/lib/mjs/DataTypes.js +50 -51
- package/lib/mjs/DateUtils.d.ts +1 -1
- package/lib/mjs/DateUtils.js +27 -28
- package/lib/mjs/DomUtils.d.ts +3 -3
- package/lib/mjs/DomUtils.js +67 -76
- package/lib/mjs/ExtendUtils.d.ts +1 -1
- package/lib/mjs/ExtendUtils.js +6 -6
- package/lib/mjs/IActionResult.d.ts +15 -2
- package/lib/mjs/NumberUtils.d.ts +1 -1
- package/lib/mjs/NumberUtils.js +9 -9
- package/lib/mjs/StorageUtils.js +4 -4
- package/lib/mjs/Utils.d.ts +4 -4
- package/lib/mjs/Utils.js +61 -65
- package/lib/mjs/index.d.ts +22 -22
- package/lib/mjs/index.js +22 -22
- package/lib/mjs/storage/WindowStorage.d.ts +1 -1
- package/lib/mjs/storage/WindowStorage.js +2 -2
- package/lib/mjs/types/ContentDisposition.d.ts +2 -2
- package/lib/mjs/types/ContentDisposition.js +12 -14
- package/lib/mjs/types/EColor.js +5 -7
- package/lib/mjs/types/EHistory.d.ts +3 -3
- package/lib/mjs/types/EHistory.js +5 -5
- package/lib/mjs/types/ErrorData.d.ts +1 -1
- package/lib/mjs/types/EventClass.js +1 -1
- package/package.json +61 -63
- package/src/ActionResult.ts +23 -23
- package/src/ArrayUtils.ts +164 -172
- package/src/ColorUtils.ts +80 -82
- package/src/DataTypes.ts +745 -754
- package/src/DateUtils.ts +266 -268
- package/src/DomUtils.ts +806 -831
- package/src/ExtendUtils.ts +191 -191
- package/src/IActionResult.ts +55 -40
- package/src/Keyboard.ts +258 -258
- package/src/NumberUtils.ts +135 -135
- package/src/StorageUtils.ts +117 -117
- package/src/Utils.ts +908 -930
- package/src/index.ts +22 -22
- package/src/node/Storage.ts +53 -53
- package/src/storage/IStorage.ts +62 -62
- package/src/storage/WindowStorage.ts +140 -140
- package/src/types/ContentDisposition.ts +59 -63
- package/src/types/DataError.ts +15 -15
- package/src/types/DelayedExecutorType.ts +15 -15
- package/src/types/EColor.ts +241 -248
- package/src/types/EHistory.ts +151 -151
- package/src/types/ErrorData.ts +11 -11
- package/src/types/EventClass.ts +220 -220
- package/src/types/FormData.ts +25 -25
- package/src/types/ParsedPath.ts +5 -5
- package/tsconfig.cjs.json +16 -16
- package/tsconfig.json +16 -16
- package/.eslintignore +0 -3
- package/.eslintrc.json +0 -29
- package/.prettierignore +0 -5
- package/.prettierrc +0 -6
package/lib/cjs/Utils.js
CHANGED
|
@@ -11,20 +11,20 @@ String.prototype.addUrlParam = function (name, value, arrayFormat) {
|
|
|
11
11
|
return this.addUrlParams({ [name]: value }, arrayFormat);
|
|
12
12
|
};
|
|
13
13
|
String.prototype.addUrlParams = function (data, arrayFormat) {
|
|
14
|
-
if (typeof data ===
|
|
14
|
+
if (typeof data === "string") {
|
|
15
15
|
let url = this;
|
|
16
|
-
if (url.includes(
|
|
17
|
-
url +=
|
|
16
|
+
if (url.includes("?")) {
|
|
17
|
+
url += "&";
|
|
18
18
|
}
|
|
19
19
|
else {
|
|
20
|
-
if (!url.endsWith(
|
|
21
|
-
url = url +
|
|
22
|
-
url +=
|
|
20
|
+
if (!url.endsWith("/"))
|
|
21
|
+
url = url + "/";
|
|
22
|
+
url += "?";
|
|
23
23
|
}
|
|
24
24
|
return url + data;
|
|
25
25
|
}
|
|
26
26
|
// Simple check
|
|
27
|
-
if (typeof URL ===
|
|
27
|
+
if (typeof URL === "undefined" || !this.includes("://")) {
|
|
28
28
|
const params = Object.entries(data)
|
|
29
29
|
.map(([key, value]) => {
|
|
30
30
|
let v;
|
|
@@ -32,21 +32,21 @@ String.prototype.addUrlParams = function (data, arrayFormat) {
|
|
|
32
32
|
if (arrayFormat == null || arrayFormat === false) {
|
|
33
33
|
return value
|
|
34
34
|
.map((item) => `${key}=${encodeURIComponent(`${item}`)}`)
|
|
35
|
-
.join(
|
|
35
|
+
.join("&");
|
|
36
36
|
}
|
|
37
37
|
else {
|
|
38
|
-
v = value.join(arrayFormat ?
|
|
38
|
+
v = value.join(arrayFormat ? "," : arrayFormat);
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
else if (value instanceof Date) {
|
|
42
42
|
v = value.toJSON();
|
|
43
43
|
}
|
|
44
44
|
else {
|
|
45
|
-
v = value == null ?
|
|
45
|
+
v = value == null ? "" : `${value}`;
|
|
46
46
|
}
|
|
47
47
|
return `${key}=${encodeURIComponent(v)}`;
|
|
48
48
|
})
|
|
49
|
-
.join(
|
|
49
|
+
.join("&");
|
|
50
50
|
return this.addUrlParams(params);
|
|
51
51
|
}
|
|
52
52
|
else {
|
|
@@ -59,14 +59,14 @@ String.prototype.addUrlParams = function (data, arrayFormat) {
|
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
61
|
else {
|
|
62
|
-
urlObj.searchParams.append(key, value.join(arrayFormat ?
|
|
62
|
+
urlObj.searchParams.append(key, value.join(arrayFormat ? "," : arrayFormat));
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
else if (value instanceof Date) {
|
|
66
66
|
urlObj.searchParams.append(key, value.toJSON());
|
|
67
67
|
}
|
|
68
68
|
else {
|
|
69
|
-
urlObj.searchParams.append(key, `${value == null ?
|
|
69
|
+
urlObj.searchParams.append(key, `${value == null ? "" : value}`);
|
|
70
70
|
}
|
|
71
71
|
});
|
|
72
72
|
return urlObj.toString();
|
|
@@ -87,14 +87,13 @@ String.prototype.containJapanese = function () {
|
|
|
87
87
|
String.prototype.format = function (...parameters) {
|
|
88
88
|
let template = this;
|
|
89
89
|
parameters.forEach((value, index) => {
|
|
90
|
-
template = template.replace(new RegExp(`\\{${index}\\}`,
|
|
90
|
+
template = template.replace(new RegExp(`\\{${index}\\}`, "g"), value);
|
|
91
91
|
});
|
|
92
92
|
return template;
|
|
93
93
|
};
|
|
94
94
|
String.prototype.formatInitial = function (upperCase = false) {
|
|
95
95
|
const initial = this.charAt(0);
|
|
96
|
-
return ((upperCase ? initial.toUpperCase() : initial.toLowerCase()) +
|
|
97
|
-
this.slice(1));
|
|
96
|
+
return ((upperCase ? initial.toUpperCase() : initial.toLowerCase()) + this.slice(1));
|
|
98
97
|
};
|
|
99
98
|
String.prototype.hideData = function (endChar) {
|
|
100
99
|
if (this.length === 0)
|
|
@@ -107,17 +106,17 @@ String.prototype.hideData = function (endChar) {
|
|
|
107
106
|
}
|
|
108
107
|
var len = this.length;
|
|
109
108
|
if (len < 4)
|
|
110
|
-
return this.substring(0, 1) +
|
|
109
|
+
return this.substring(0, 1) + "***";
|
|
111
110
|
if (len < 6)
|
|
112
|
-
return this.substring(0, 2) +
|
|
111
|
+
return this.substring(0, 2) + "***";
|
|
113
112
|
if (len < 8)
|
|
114
|
-
return this.substring(0, 2) +
|
|
113
|
+
return this.substring(0, 2) + "***" + this.slice(-2);
|
|
115
114
|
if (len < 12)
|
|
116
|
-
return this.substring(0, 3) +
|
|
117
|
-
return this.substring(0, 4) +
|
|
115
|
+
return this.substring(0, 3) + "***" + this.slice(-3);
|
|
116
|
+
return this.substring(0, 4) + "***" + this.slice(-4);
|
|
118
117
|
};
|
|
119
118
|
String.prototype.hideEmail = function () {
|
|
120
|
-
return this.hideData(
|
|
119
|
+
return this.hideData("@");
|
|
121
120
|
};
|
|
122
121
|
String.prototype.isDigits = function (minLength) {
|
|
123
122
|
return this.length >= (minLength ?? 0) && /^\d+$/.test(this);
|
|
@@ -127,7 +126,7 @@ String.prototype.isEmail = function () {
|
|
|
127
126
|
return re.test(this.toLowerCase());
|
|
128
127
|
};
|
|
129
128
|
String.prototype.removeNonLetters = function () {
|
|
130
|
-
return this.replace(/[^a-zA-Z0-9]/g,
|
|
129
|
+
return this.replace(/[^a-zA-Z0-9]/g, "");
|
|
131
130
|
};
|
|
132
131
|
/**
|
|
133
132
|
* Utilities
|
|
@@ -143,11 +142,11 @@ var Utils;
|
|
|
143
142
|
*/
|
|
144
143
|
function addBlankItem(options, idField, labelField, blankLabel) {
|
|
145
144
|
// Avoid duplicate blank items
|
|
146
|
-
idField ?? (idField =
|
|
147
|
-
if (options.length === 0 || Reflect.get(options[0], idField) !==
|
|
145
|
+
idField ?? (idField = "id");
|
|
146
|
+
if (options.length === 0 || Reflect.get(options[0], idField) !== "") {
|
|
148
147
|
const blankItem = {
|
|
149
|
-
[idField]:
|
|
150
|
-
[typeof labelField ===
|
|
148
|
+
[idField]: "",
|
|
149
|
+
[typeof labelField === "string" ? labelField : "label"]: blankLabel ?? "---"
|
|
151
150
|
};
|
|
152
151
|
options.unshift(blankItem);
|
|
153
152
|
}
|
|
@@ -160,9 +159,9 @@ var Utils;
|
|
|
160
159
|
* @returns Number
|
|
161
160
|
*/
|
|
162
161
|
function charsToNumber(base64Chars) {
|
|
163
|
-
const chars = typeof Buffer ===
|
|
162
|
+
const chars = typeof Buffer === "undefined"
|
|
164
163
|
? [...atob(base64Chars)].map((char) => char.charCodeAt(0))
|
|
165
|
-
: [...Buffer.from(base64Chars,
|
|
164
|
+
: [...Buffer.from(base64Chars, "base64")];
|
|
166
165
|
return chars.reduce((previousValue, currentValue, currentIndex) => {
|
|
167
166
|
return previousValue + currentValue * Math.pow(128, currentIndex);
|
|
168
167
|
}, 0);
|
|
@@ -200,7 +199,7 @@ var Utils;
|
|
|
200
199
|
return v1 === v2;
|
|
201
200
|
}
|
|
202
201
|
// For date, array and object
|
|
203
|
-
if (typeof v1 ===
|
|
202
|
+
if (typeof v1 === "object")
|
|
204
203
|
return (0, lodash_isequal_1.default)(v1, v2);
|
|
205
204
|
// 1 and '1' case
|
|
206
205
|
if (strict === 0)
|
|
@@ -260,7 +259,7 @@ var Utils;
|
|
|
260
259
|
* @param ignoreFields Ignore fields
|
|
261
260
|
* @returns
|
|
262
261
|
*/
|
|
263
|
-
function getDataChanges(input, initData, ignoreFields = [
|
|
262
|
+
function getDataChanges(input, initData, ignoreFields = ["id"]) {
|
|
264
263
|
// Changed fields
|
|
265
264
|
const changes = [];
|
|
266
265
|
Object.entries(input).forEach(([key, value]) => {
|
|
@@ -277,8 +276,7 @@ var Utils;
|
|
|
277
276
|
if (initValue != null) {
|
|
278
277
|
// Date when meets string
|
|
279
278
|
if (value instanceof Date) {
|
|
280
|
-
if (value.valueOf() ===
|
|
281
|
-
DateUtils_1.DateUtils.parse(initValue)?.valueOf()) {
|
|
279
|
+
if (value.valueOf() === DateUtils_1.DateUtils.parse(initValue)?.valueOf()) {
|
|
282
280
|
Reflect.deleteProperty(input, key);
|
|
283
281
|
return;
|
|
284
282
|
}
|
|
@@ -294,7 +292,7 @@ var Utils;
|
|
|
294
292
|
Reflect.set(input, key, newValue);
|
|
295
293
|
}
|
|
296
294
|
// Remove empty property
|
|
297
|
-
if (value == null || value ===
|
|
295
|
+
if (value == null || value === "") {
|
|
298
296
|
Reflect.deleteProperty(input, key);
|
|
299
297
|
}
|
|
300
298
|
// Hold the key
|
|
@@ -310,7 +308,7 @@ var Utils;
|
|
|
310
308
|
* @returns Result
|
|
311
309
|
*/
|
|
312
310
|
function getNestedValue(data, name) {
|
|
313
|
-
const properties = name.split(
|
|
311
|
+
const properties = name.split(".");
|
|
314
312
|
const len = properties.length;
|
|
315
313
|
if (len === 1) {
|
|
316
314
|
return Reflect.get(data, name);
|
|
@@ -340,7 +338,7 @@ var Utils;
|
|
|
340
338
|
* @returns Result
|
|
341
339
|
*/
|
|
342
340
|
Utils.getResult = (input, ...args) => {
|
|
343
|
-
return typeof input ===
|
|
341
|
+
return typeof input === "function" ? input(...args) : input;
|
|
344
342
|
};
|
|
345
343
|
/**
|
|
346
344
|
* Get time zone
|
|
@@ -348,8 +346,7 @@ var Utils;
|
|
|
348
346
|
*/
|
|
349
347
|
Utils.getTimeZone = () => {
|
|
350
348
|
// If Intl supported
|
|
351
|
-
if (typeof Intl ===
|
|
352
|
-
typeof Intl.DateTimeFormat === 'function')
|
|
349
|
+
if (typeof Intl === "object" && typeof Intl.DateTimeFormat === "function")
|
|
353
350
|
return Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
354
351
|
};
|
|
355
352
|
/**
|
|
@@ -378,7 +375,7 @@ var Utils;
|
|
|
378
375
|
* @param items Items
|
|
379
376
|
* @param joinPart Join string
|
|
380
377
|
*/
|
|
381
|
-
Utils.joinItems = (items, joinPart =
|
|
378
|
+
Utils.joinItems = (items, joinPart = ", ") => items
|
|
382
379
|
.reduce((items, item) => {
|
|
383
380
|
if (item) {
|
|
384
381
|
const newItem = item.trim();
|
|
@@ -392,13 +389,13 @@ var Utils;
|
|
|
392
389
|
* Merge class names
|
|
393
390
|
* @param classNames Class names
|
|
394
391
|
*/
|
|
395
|
-
Utils.mergeClasses = (...classNames) => Utils.joinItems(classNames,
|
|
392
|
+
Utils.mergeClasses = (...classNames) => Utils.joinItems(classNames, " ");
|
|
396
393
|
/**
|
|
397
394
|
* Create a GUID
|
|
398
395
|
*/
|
|
399
396
|
function newGUID() {
|
|
400
|
-
return
|
|
401
|
-
const r = (Math.random() * 16) | 0, v = c ===
|
|
397
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
398
|
+
const r = (Math.random() * 16) | 0, v = c === "x" ? r : (r & 0x3) | 0x8;
|
|
402
399
|
return v.toString(16);
|
|
403
400
|
});
|
|
404
401
|
}
|
|
@@ -415,12 +412,12 @@ var Utils;
|
|
|
415
412
|
codes.push(code);
|
|
416
413
|
num = (num - code) / 128;
|
|
417
414
|
}
|
|
418
|
-
if (typeof Buffer ===
|
|
415
|
+
if (typeof Buffer === "undefined") {
|
|
419
416
|
return btoa(String.fromCharCode(...codes));
|
|
420
417
|
}
|
|
421
418
|
else {
|
|
422
419
|
const buffer = Buffer.from(codes);
|
|
423
|
-
return buffer.toString(
|
|
420
|
+
return buffer.toString("base64");
|
|
424
421
|
}
|
|
425
422
|
}
|
|
426
423
|
Utils.numberToChars = numberToChars;
|
|
@@ -491,13 +488,12 @@ var Utils;
|
|
|
491
488
|
*/
|
|
492
489
|
function parseJsonArray(input, checkValue) {
|
|
493
490
|
try {
|
|
494
|
-
if (!input.startsWith(
|
|
491
|
+
if (!input.startsWith("["))
|
|
495
492
|
input = `[${input}]`;
|
|
496
493
|
const array = JSON.parse(input);
|
|
497
494
|
const type = typeof checkValue;
|
|
498
495
|
if (Array.isArray(array) &&
|
|
499
|
-
(checkValue == null ||
|
|
500
|
-
!array.some((item) => typeof item !== type))) {
|
|
496
|
+
(checkValue == null || !array.some((item) => typeof item !== type))) {
|
|
501
497
|
return array;
|
|
502
498
|
}
|
|
503
499
|
}
|
|
@@ -517,10 +513,10 @@ var Utils;
|
|
|
517
513
|
*/
|
|
518
514
|
function parseString(input, defaultValue) {
|
|
519
515
|
// Undefined and empty case, return default value
|
|
520
|
-
if (input == null || input ===
|
|
516
|
+
if (input == null || input === "")
|
|
521
517
|
return defaultValue;
|
|
522
518
|
// String
|
|
523
|
-
if (typeof defaultValue ===
|
|
519
|
+
if (typeof defaultValue === "string")
|
|
524
520
|
return input;
|
|
525
521
|
try {
|
|
526
522
|
// Date
|
|
@@ -549,7 +545,7 @@ var Utils;
|
|
|
549
545
|
function removeEmptyValues(input) {
|
|
550
546
|
Object.keys(input).forEach((key) => {
|
|
551
547
|
const value = Reflect.get(input, key);
|
|
552
|
-
if (value == null || value ===
|
|
548
|
+
if (value == null || value === "") {
|
|
553
549
|
Reflect.deleteProperty(input, key);
|
|
554
550
|
}
|
|
555
551
|
});
|
|
@@ -570,7 +566,7 @@ var Utils;
|
|
|
570
566
|
* @returns Result
|
|
571
567
|
*/
|
|
572
568
|
Utils.replaceNullOrEmpty = (input, defaultValue) => {
|
|
573
|
-
if (input == null || input.trim() ===
|
|
569
|
+
if (input == null || input.trim() === "")
|
|
574
570
|
return defaultValue;
|
|
575
571
|
return input;
|
|
576
572
|
};
|
|
@@ -598,12 +594,12 @@ var Utils;
|
|
|
598
594
|
* @param firstOnly Only convert the first word to upper case
|
|
599
595
|
*/
|
|
600
596
|
Utils.snakeNameToWord = (name, firstOnly = false) => {
|
|
601
|
-
const items = name.split(
|
|
597
|
+
const items = name.split("_");
|
|
602
598
|
if (firstOnly) {
|
|
603
599
|
items[0] = items[0].formatInitial(true);
|
|
604
|
-
return items.join(
|
|
600
|
+
return items.join(" ");
|
|
605
601
|
}
|
|
606
|
-
return items.map((part) => part.formatInitial(true)).join(
|
|
602
|
+
return items.map((part) => part.formatInitial(true)).join(" ");
|
|
607
603
|
};
|
|
608
604
|
function getSortValue(n1, n2) {
|
|
609
605
|
if (n1 === n2)
|
|
@@ -622,7 +618,7 @@ var Utils;
|
|
|
622
618
|
* @param keepNull Keep null value or not
|
|
623
619
|
*/
|
|
624
620
|
function setNestedValue(data, name, value, keepNull) {
|
|
625
|
-
const properties = name.split(
|
|
621
|
+
const properties = name.split(".");
|
|
626
622
|
const len = properties.length;
|
|
627
623
|
if (len === 1) {
|
|
628
624
|
if (value == null && keepNull !== true) {
|
|
@@ -660,15 +656,15 @@ var Utils;
|
|
|
660
656
|
// Two formats or mixed
|
|
661
657
|
// /home/user/dir/file.txt
|
|
662
658
|
// C:\\path\\dir\\file.txt
|
|
663
|
-
const lastIndex = Math.max(path.lastIndexOf(
|
|
664
|
-
let root =
|
|
659
|
+
const lastIndex = Math.max(path.lastIndexOf("/"), path.lastIndexOf("\\"));
|
|
660
|
+
let root = "", dir = "", base, ext, name;
|
|
665
661
|
if (lastIndex === -1) {
|
|
666
662
|
base = path;
|
|
667
663
|
}
|
|
668
664
|
else {
|
|
669
665
|
base = path.substring(lastIndex + 1);
|
|
670
|
-
const index1 = path.indexOf(
|
|
671
|
-
const index2 = path.indexOf(
|
|
666
|
+
const index1 = path.indexOf("/");
|
|
667
|
+
const index2 = path.indexOf("\\");
|
|
672
668
|
const index = index1 === -1
|
|
673
669
|
? index2
|
|
674
670
|
: index2 === -1
|
|
@@ -676,13 +672,13 @@ var Utils;
|
|
|
676
672
|
: Math.min(index1, index2);
|
|
677
673
|
root = path.substring(0, index + 1);
|
|
678
674
|
dir = path.substring(0, lastIndex);
|
|
679
|
-
if (dir ===
|
|
675
|
+
if (dir === "")
|
|
680
676
|
dir = root;
|
|
681
677
|
}
|
|
682
|
-
const extIndex = base.lastIndexOf(
|
|
678
|
+
const extIndex = base.lastIndexOf(".");
|
|
683
679
|
if (extIndex === -1) {
|
|
684
680
|
name = base;
|
|
685
|
-
ext =
|
|
681
|
+
ext = "";
|
|
686
682
|
}
|
|
687
683
|
else {
|
|
688
684
|
name = base.substring(0, extIndex);
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
9
|
-
export * from
|
|
10
|
-
export * from
|
|
11
|
-
export * from
|
|
12
|
-
export * from
|
|
13
|
-
export * from
|
|
14
|
-
export * from
|
|
15
|
-
export * from
|
|
16
|
-
export * from
|
|
17
|
-
export * from
|
|
18
|
-
export * from
|
|
19
|
-
export * from
|
|
20
|
-
export * from
|
|
21
|
-
export * from
|
|
22
|
-
export * from
|
|
1
|
+
export * from "./types/ContentDisposition";
|
|
2
|
+
export * from "./types/DataError";
|
|
3
|
+
export * from "./types/DelayedExecutorType";
|
|
4
|
+
export * from "./types/EColor";
|
|
5
|
+
export * from "./types/EHistory";
|
|
6
|
+
export * from "./types/ErrorData";
|
|
7
|
+
export * from "./types/EventClass";
|
|
8
|
+
export * from "./types/FormData";
|
|
9
|
+
export * from "./storage/IStorage";
|
|
10
|
+
export * from "./storage/WindowStorage";
|
|
11
|
+
export * from "./ActionResult";
|
|
12
|
+
export * from "./ArrayUtils";
|
|
13
|
+
export * from "./DataTypes";
|
|
14
|
+
export * from "./ColorUtils";
|
|
15
|
+
export * from "./DateUtils";
|
|
16
|
+
export * from "./DomUtils";
|
|
17
|
+
export * from "./ExtendUtils";
|
|
18
|
+
export * from "./IActionResult";
|
|
19
|
+
export * from "./Keyboard";
|
|
20
|
+
export * from "./NumberUtils";
|
|
21
|
+
export * from "./StorageUtils";
|
|
22
|
+
export * from "./Utils";
|
|
@@ -6,8 +6,8 @@ export declare class ContentDisposition {
|
|
|
6
6
|
readonly type: string;
|
|
7
7
|
readonly filename: string;
|
|
8
8
|
readonly name?: string | undefined;
|
|
9
|
-
constructor(type:
|
|
10
|
-
constructor(type:
|
|
9
|
+
constructor(type: "inline" | "attachment", filename: string);
|
|
10
|
+
constructor(type: "form-data", filename: string, name: string);
|
|
11
11
|
/**
|
|
12
12
|
* Format to standard output
|
|
13
13
|
* @returns Result
|
|
@@ -20,11 +20,11 @@ class ContentDisposition {
|
|
|
20
20
|
const items = [this.type];
|
|
21
21
|
if (this.name)
|
|
22
22
|
items.push(`name="${this.name}"`);
|
|
23
|
-
const filename1 = this.filename.replace(/[^a-zA-Z0-9\.-]/g,
|
|
23
|
+
const filename1 = this.filename.replace(/[^a-zA-Z0-9\.-]/g, "_");
|
|
24
24
|
items.push(`filename="${filename1}"`);
|
|
25
25
|
if (filename1 != this.filename)
|
|
26
26
|
items.push(`filename*="UTF-8''${encodeURIComponent(this.filename)}"`);
|
|
27
|
-
return items.join(
|
|
27
|
+
return items.join("; ");
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
30
|
* Parse header value
|
|
@@ -40,7 +40,7 @@ class ContentDisposition {
|
|
|
40
40
|
return undefined;
|
|
41
41
|
const type = parts[0];
|
|
42
42
|
let name;
|
|
43
|
-
let filename =
|
|
43
|
+
let filename = "";
|
|
44
44
|
for (let i = 1; i < len; i++) {
|
|
45
45
|
const part = parts[i];
|
|
46
46
|
let [field, value] = part.split(/\s*=\s*/g);
|
|
@@ -48,25 +48,23 @@ class ContentDisposition {
|
|
|
48
48
|
field = field.toLowerCase();
|
|
49
49
|
// Remove quotes
|
|
50
50
|
value = Utils_1.Utils.trim(value, '"');
|
|
51
|
-
if (field ===
|
|
51
|
+
if (field === "name") {
|
|
52
52
|
name = value;
|
|
53
53
|
}
|
|
54
|
-
else if (field ===
|
|
55
|
-
if (filename ===
|
|
54
|
+
else if (field === "filename") {
|
|
55
|
+
if (filename === "")
|
|
56
56
|
filename = value;
|
|
57
57
|
}
|
|
58
|
-
else if (field ===
|
|
58
|
+
else if (field === "filename*") {
|
|
59
59
|
const pos = value.indexOf("''");
|
|
60
60
|
filename =
|
|
61
|
-
pos == -1
|
|
62
|
-
? value
|
|
63
|
-
: decodeURIComponent(value.substring(pos + 2));
|
|
61
|
+
pos == -1 ? value : decodeURIComponent(value.substring(pos + 2));
|
|
64
62
|
}
|
|
65
63
|
}
|
|
66
|
-
if (type ===
|
|
67
|
-
return new ContentDisposition(type, filename, name ??
|
|
64
|
+
if (type === "form-data") {
|
|
65
|
+
return new ContentDisposition(type, filename, name ?? "file");
|
|
68
66
|
}
|
|
69
|
-
if (type ===
|
|
67
|
+
if (type === "inline" || type === "attachment") {
|
|
70
68
|
return new ContentDisposition(type, filename);
|
|
71
69
|
}
|
|
72
70
|
return undefined;
|
package/lib/cjs/types/EColor.js
CHANGED
|
@@ -51,7 +51,7 @@ class EColor {
|
|
|
51
51
|
* @returns Result
|
|
52
52
|
*/
|
|
53
53
|
static toHex(num) {
|
|
54
|
-
return num.toString(16).padStart(2,
|
|
54
|
+
return num.toString(16).padStart(2, "0");
|
|
55
55
|
}
|
|
56
56
|
/**
|
|
57
57
|
* Parse HTML color to EColor
|
|
@@ -64,12 +64,12 @@ class EColor {
|
|
|
64
64
|
return undefined;
|
|
65
65
|
htmlColor = htmlColor.trim().toUpperCase();
|
|
66
66
|
// HEX color
|
|
67
|
-
if (htmlColor.startsWith(
|
|
67
|
+
if (htmlColor.startsWith("#")) {
|
|
68
68
|
htmlColor = htmlColor.substring(1);
|
|
69
69
|
if (htmlColor.length === 3)
|
|
70
70
|
htmlColor = Array.from(htmlColor)
|
|
71
71
|
.map((c) => c + c)
|
|
72
|
-
.join(
|
|
72
|
+
.join("");
|
|
73
73
|
if (htmlColor.length === 6) {
|
|
74
74
|
return new EColor(EColor.hexTo(htmlColor.substring(0, 2)), EColor.hexTo(htmlColor.substring(2, 4)), EColor.hexTo(htmlColor.substring(4, 6)));
|
|
75
75
|
}
|
|
@@ -168,9 +168,7 @@ class EColor {
|
|
|
168
168
|
getLuminance() {
|
|
169
169
|
const a = [this.r, this.g, this.b].map((v) => {
|
|
170
170
|
v /= 255;
|
|
171
|
-
return v <= 0.03928
|
|
172
|
-
? v / 12.92
|
|
173
|
-
: Math.pow((v + 0.055) / 1.055, 2.4);
|
|
171
|
+
return v <= 0.03928 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4);
|
|
174
172
|
});
|
|
175
173
|
return a[0] * 0.2126 + a[1] * 0.7152 + a[2] * 0.0722;
|
|
176
174
|
}
|
|
@@ -206,7 +204,7 @@ class EColor {
|
|
|
206
204
|
toRGBColor(alpha) {
|
|
207
205
|
// Decide
|
|
208
206
|
let includeAlpha, alphaValue = this.alpha;
|
|
209
|
-
if (typeof alpha ===
|
|
207
|
+
if (typeof alpha === "number") {
|
|
210
208
|
alphaValue = alpha;
|
|
211
209
|
includeAlpha = true;
|
|
212
210
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EventBase, EventClass } from
|
|
1
|
+
import { EventBase, EventClass } from "./EventClass";
|
|
2
2
|
interface EHistoryEventData {
|
|
3
3
|
/**
|
|
4
4
|
* Current index
|
|
@@ -17,7 +17,7 @@ type EHistoryEventDef = {
|
|
|
17
17
|
push: EHistoryEventData;
|
|
18
18
|
replace: EHistoryEventData;
|
|
19
19
|
};
|
|
20
|
-
type EHistoryEventType = Exclude<keyof EHistoryEventDef,
|
|
20
|
+
type EHistoryEventType = Exclude<keyof EHistoryEventDef, "navigate">;
|
|
21
21
|
/**
|
|
22
22
|
* ETSOO Extended history event
|
|
23
23
|
*/
|
|
@@ -26,7 +26,7 @@ export declare class EHistoryEvent extends EventBase<EHistoryEventType, EHistory
|
|
|
26
26
|
/**
|
|
27
27
|
* ETSOO Extended history navigate event
|
|
28
28
|
*/
|
|
29
|
-
export declare class EHistoryNavigateEvent extends EventBase<
|
|
29
|
+
export declare class EHistoryNavigateEvent extends EventBase<"navigate", EHistoryNavigateEventData> {
|
|
30
30
|
constructor(target: {}, data: EHistoryNavigateEventData);
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
@@ -13,7 +13,7 @@ exports.EHistoryEvent = EHistoryEvent;
|
|
|
13
13
|
*/
|
|
14
14
|
class EHistoryNavigateEvent extends EventClass_1.EventBase {
|
|
15
15
|
constructor(target, data) {
|
|
16
|
-
super(target,
|
|
16
|
+
super(target, "navigate", data);
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
exports.EHistoryNavigateEvent = EHistoryNavigateEvent;
|
|
@@ -68,7 +68,7 @@ class EHistory extends EventClass_1.EventClass {
|
|
|
68
68
|
// https://stackoverflow.com/questions/1232040/how-do-i-empty-an-array-in-javascript
|
|
69
69
|
this.states.length = 0;
|
|
70
70
|
this._index = -1;
|
|
71
|
-
this.trigger(this.createEvent(
|
|
71
|
+
this.trigger(this.createEvent("clear", this._index));
|
|
72
72
|
}
|
|
73
73
|
/**
|
|
74
74
|
* Create event
|
|
@@ -131,7 +131,7 @@ class EHistory extends EventClass_1.EventClass {
|
|
|
131
131
|
if (this.length > this.maxDepth) {
|
|
132
132
|
this.states.shift();
|
|
133
133
|
}
|
|
134
|
-
this.trigger(this.createEvent(
|
|
134
|
+
this.trigger(this.createEvent("push", this._index));
|
|
135
135
|
}
|
|
136
136
|
/**
|
|
137
137
|
* Modifies the current history entry
|
|
@@ -141,7 +141,7 @@ class EHistory extends EventClass_1.EventClass {
|
|
|
141
141
|
if (this._index === -1)
|
|
142
142
|
return;
|
|
143
143
|
this.states[this._index] = state;
|
|
144
|
-
this.trigger(this.createEvent(
|
|
144
|
+
this.trigger(this.createEvent("replace", this._index));
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
147
|
exports.EHistory = EHistory;
|
package/lib/mjs/ActionResult.js
CHANGED
|
@@ -8,14 +8,14 @@ export class ActionResult {
|
|
|
8
8
|
*/
|
|
9
9
|
static create(error) {
|
|
10
10
|
// If the error has status / statusCode
|
|
11
|
-
const status =
|
|
11
|
+
const status = "status" in error
|
|
12
12
|
? error.status
|
|
13
|
-
:
|
|
13
|
+
: "statusCode" in error
|
|
14
14
|
? error.statusCode
|
|
15
15
|
: undefined;
|
|
16
16
|
// Result
|
|
17
17
|
const result = {
|
|
18
|
-
status: typeof status ===
|
|
18
|
+
status: typeof status === "number" ? status : undefined,
|
|
19
19
|
ok: false,
|
|
20
20
|
type: error.name,
|
|
21
21
|
title: error.message
|
package/lib/mjs/ArrayUtils.d.ts
CHANGED