@etsoo/shared 1.1.34 → 1.1.37
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/lib/cjs/DataTypes.js +1 -4
- package/lib/cjs/DateUtils.js +3 -11
- package/lib/cjs/DomUtils.js +26 -15
- package/lib/cjs/Utils.js +1 -1
- package/lib/mjs/DataTypes.js +1 -4
- package/lib/mjs/DateUtils.js +3 -11
- package/lib/mjs/DomUtils.js +26 -15
- package/lib/mjs/Utils.js +1 -1
- package/package.json +9 -7
- package/tsconfig.cjs.json +1 -1
- package/tsconfig.json +1 -1
package/lib/cjs/DataTypes.js
CHANGED
package/lib/cjs/DateUtils.js
CHANGED
|
@@ -47,19 +47,11 @@ var DateUtils;
|
|
|
47
47
|
/**
|
|
48
48
|
* Minute format, YYYY-MM-DD hh:mm
|
|
49
49
|
*/
|
|
50
|
-
DateUtils.MinuteFormat = {
|
|
51
|
-
...DateUtils.DayFormat,
|
|
52
|
-
hour: '2-digit',
|
|
53
|
-
hourCycle: 'h23',
|
|
54
|
-
minute: '2-digit'
|
|
55
|
-
};
|
|
50
|
+
DateUtils.MinuteFormat = Object.assign(Object.assign({}, DateUtils.DayFormat), { hour: '2-digit', hourCycle: 'h23', minute: '2-digit' });
|
|
56
51
|
/**
|
|
57
52
|
* Second format, YYYY-MM-DD hh:mm:ss
|
|
58
53
|
*/
|
|
59
|
-
DateUtils.SecondFormat = {
|
|
60
|
-
...DateUtils.MinuteFormat,
|
|
61
|
-
second: '2-digit'
|
|
62
|
-
};
|
|
54
|
+
DateUtils.SecondFormat = Object.assign(Object.assign({}, DateUtils.MinuteFormat), { second: '2-digit' });
|
|
63
55
|
/**
|
|
64
56
|
* Format
|
|
65
57
|
* @param input Input date time
|
|
@@ -92,7 +84,7 @@ var DateUtils;
|
|
|
92
84
|
opt = options;
|
|
93
85
|
}
|
|
94
86
|
// Clone as new options with time zone
|
|
95
|
-
const newOpt = {
|
|
87
|
+
const newOpt = Object.assign(Object.assign({}, opt), (timeZone != null && { timeZone }));
|
|
96
88
|
// Return format result
|
|
97
89
|
return new Intl.DateTimeFormat(locale, newOpt)
|
|
98
90
|
.format(parsed)
|
package/lib/cjs/DomUtils.js
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
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
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.DomUtils = void 0;
|
|
4
13
|
const DataTypes_1 = require("./DataTypes");
|
|
@@ -163,7 +172,7 @@ var DomUtils;
|
|
|
163
172
|
country =
|
|
164
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);
|
|
165
174
|
}
|
|
166
|
-
catch {
|
|
175
|
+
catch (_c) {
|
|
167
176
|
country = null;
|
|
168
177
|
}
|
|
169
178
|
// Return
|
|
@@ -180,7 +189,7 @@ var DomUtils;
|
|
|
180
189
|
culture =
|
|
181
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);
|
|
182
191
|
}
|
|
183
|
-
catch {
|
|
192
|
+
catch (_c) {
|
|
184
193
|
culture = null;
|
|
185
194
|
}
|
|
186
195
|
// Browser detected
|
|
@@ -218,19 +227,21 @@ var DomUtils;
|
|
|
218
227
|
* @param file File
|
|
219
228
|
* @returns Data URL
|
|
220
229
|
*/
|
|
221
|
-
|
|
222
|
-
return
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
230
|
+
function fileToDataURL(file) {
|
|
231
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
232
|
+
return new Promise((resolve, reject) => {
|
|
233
|
+
const reader = new FileReader();
|
|
234
|
+
reader.onerror = reject;
|
|
235
|
+
reader.onload = () => {
|
|
236
|
+
const data = reader.result;
|
|
237
|
+
if (data == null) {
|
|
238
|
+
reject();
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
resolve(data);
|
|
242
|
+
};
|
|
243
|
+
reader.readAsDataURL(file);
|
|
244
|
+
});
|
|
234
245
|
});
|
|
235
246
|
}
|
|
236
247
|
DomUtils.fileToDataURL = fileToDataURL;
|
package/lib/cjs/Utils.js
CHANGED
package/lib/mjs/DataTypes.js
CHANGED
|
@@ -49,10 +49,7 @@ export var DataTypes;
|
|
|
49
49
|
/**
|
|
50
50
|
* Combined type enum
|
|
51
51
|
*/
|
|
52
|
-
DataTypes.CombinedEnum = {
|
|
53
|
-
...SimpleEnum,
|
|
54
|
-
...ExtendedEnum
|
|
55
|
-
};
|
|
52
|
+
DataTypes.CombinedEnum = Object.assign(Object.assign({}, SimpleEnum), ExtendedEnum);
|
|
56
53
|
/**
|
|
57
54
|
* Horizontal align enum
|
|
58
55
|
*/
|
package/lib/mjs/DateUtils.js
CHANGED
|
@@ -44,19 +44,11 @@ export var DateUtils;
|
|
|
44
44
|
/**
|
|
45
45
|
* Minute format, YYYY-MM-DD hh:mm
|
|
46
46
|
*/
|
|
47
|
-
DateUtils.MinuteFormat = {
|
|
48
|
-
...DateUtils.DayFormat,
|
|
49
|
-
hour: '2-digit',
|
|
50
|
-
hourCycle: 'h23',
|
|
51
|
-
minute: '2-digit'
|
|
52
|
-
};
|
|
47
|
+
DateUtils.MinuteFormat = Object.assign(Object.assign({}, DateUtils.DayFormat), { hour: '2-digit', hourCycle: 'h23', minute: '2-digit' });
|
|
53
48
|
/**
|
|
54
49
|
* Second format, YYYY-MM-DD hh:mm:ss
|
|
55
50
|
*/
|
|
56
|
-
DateUtils.SecondFormat = {
|
|
57
|
-
...DateUtils.MinuteFormat,
|
|
58
|
-
second: '2-digit'
|
|
59
|
-
};
|
|
51
|
+
DateUtils.SecondFormat = Object.assign(Object.assign({}, DateUtils.MinuteFormat), { second: '2-digit' });
|
|
60
52
|
/**
|
|
61
53
|
* Format
|
|
62
54
|
* @param input Input date time
|
|
@@ -89,7 +81,7 @@ export var DateUtils;
|
|
|
89
81
|
opt = options;
|
|
90
82
|
}
|
|
91
83
|
// Clone as new options with time zone
|
|
92
|
-
const newOpt = {
|
|
84
|
+
const newOpt = Object.assign(Object.assign({}, opt), (timeZone != null && { timeZone }));
|
|
93
85
|
// Return format result
|
|
94
86
|
return new Intl.DateTimeFormat(locale, newOpt)
|
|
95
87
|
.format(parsed)
|
package/lib/mjs/DomUtils.js
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
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
|
+
};
|
|
1
10
|
import { DataTypes } from './DataTypes';
|
|
2
11
|
if (typeof navigator === 'undefined') {
|
|
3
12
|
// Test mock only
|
|
@@ -160,7 +169,7 @@ export var DomUtils;
|
|
|
160
169
|
country =
|
|
161
170
|
(_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);
|
|
162
171
|
}
|
|
163
|
-
catch {
|
|
172
|
+
catch (_c) {
|
|
164
173
|
country = null;
|
|
165
174
|
}
|
|
166
175
|
// Return
|
|
@@ -177,7 +186,7 @@ export var DomUtils;
|
|
|
177
186
|
culture =
|
|
178
187
|
(_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);
|
|
179
188
|
}
|
|
180
|
-
catch {
|
|
189
|
+
catch (_c) {
|
|
181
190
|
culture = null;
|
|
182
191
|
}
|
|
183
192
|
// Browser detected
|
|
@@ -215,19 +224,21 @@ export var DomUtils;
|
|
|
215
224
|
* @param file File
|
|
216
225
|
* @returns Data URL
|
|
217
226
|
*/
|
|
218
|
-
|
|
219
|
-
return
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
227
|
+
function fileToDataURL(file) {
|
|
228
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
229
|
+
return new Promise((resolve, reject) => {
|
|
230
|
+
const reader = new FileReader();
|
|
231
|
+
reader.onerror = reject;
|
|
232
|
+
reader.onload = () => {
|
|
233
|
+
const data = reader.result;
|
|
234
|
+
if (data == null) {
|
|
235
|
+
reject();
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
resolve(data);
|
|
239
|
+
};
|
|
240
|
+
reader.readAsDataURL(file);
|
|
241
|
+
});
|
|
231
242
|
});
|
|
232
243
|
}
|
|
233
244
|
DomUtils.fileToDataURL = fileToDataURL;
|
package/lib/mjs/Utils.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/shared",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.37",
|
|
4
4
|
"description": "TypeScript shared utilities and functions",
|
|
5
5
|
"main": "lib/cjs/index.js",
|
|
6
6
|
"module": "lib/mjs/index.js",
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"require": "./lib/cjs/index.js"
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
|
+
"sideEffects": false,
|
|
14
15
|
"scripts": {
|
|
15
16
|
"build": "tsc -p tsconfig.json && tsc -p tsconfig.cjs.json",
|
|
16
17
|
"format": "prettier --write src/**/*.ts",
|
|
@@ -54,14 +55,15 @@
|
|
|
54
55
|
"homepage": "https://github.com/ETSOO/Shared#readme",
|
|
55
56
|
"dependencies": {},
|
|
56
57
|
"devDependencies": {
|
|
57
|
-
"@types/jest": "^27.
|
|
58
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
59
|
-
"@typescript-eslint/parser": "^5.
|
|
60
|
-
"eslint": "^8.
|
|
58
|
+
"@types/jest": "^27.5.0",
|
|
59
|
+
"@typescript-eslint/eslint-plugin": "^5.23.0",
|
|
60
|
+
"@typescript-eslint/parser": "^5.23.0",
|
|
61
|
+
"eslint": "^8.15.0",
|
|
61
62
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
62
63
|
"eslint-plugin-import": "^2.26.0",
|
|
63
|
-
"jest": "^
|
|
64
|
-
"
|
|
64
|
+
"jest": "^28.1.0",
|
|
65
|
+
"jest-environment-jsdom": "^28.1.0",
|
|
66
|
+
"ts-jest": "^28.0.2",
|
|
65
67
|
"typescript": "^4.6.4"
|
|
66
68
|
}
|
|
67
69
|
}
|
package/tsconfig.cjs.json
CHANGED