@etsoo/shared 1.1.36 → 1.1.39
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 +1 -1
- package/__tests__/tsconfig.json +1 -1
- package/lib/cjs/DomUtils.d.ts +8 -1
- package/lib/cjs/DomUtils.js +21 -4
- package/lib/cjs/index.js +30 -17
- package/lib/mjs/DomUtils.d.ts +8 -1
- package/lib/mjs/DomUtils.js +20 -3
- package/package.json +5 -6
- package/src/DomUtils.ts +12 -3
- package/tsconfig.cjs.json +0 -2
- package/tsconfig.json +0 -2
package/README.md
CHANGED
|
@@ -147,7 +147,7 @@ DOM/window related utilities
|
|
|
147
147
|
|Name|Description|
|
|
148
148
|
|---:|---|
|
|
149
149
|
|clearFormData|Clear form data|
|
|
150
|
-
|dataAs|Cast data
|
|
150
|
+
|dataAs|Cast data as template format|
|
|
151
151
|
|detectedCountry|Current detected country|
|
|
152
152
|
|detectedCulture|Current detected culture|
|
|
153
153
|
|dimensionEqual|Check two rectangles equality|
|
package/__tests__/tsconfig.json
CHANGED
package/lib/cjs/DomUtils.d.ts
CHANGED
|
@@ -20,7 +20,14 @@ export declare namespace DomUtils {
|
|
|
20
20
|
* @param keepFields Fields need to be kept
|
|
21
21
|
*/
|
|
22
22
|
function clearFormData(data: IFormData, source?: {}, keepFields?: string[]): IFormData;
|
|
23
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Cast data as template format
|
|
25
|
+
* @param source Source data
|
|
26
|
+
* @param template Format template
|
|
27
|
+
* @param keepSource Keep other source properties
|
|
28
|
+
* @returns Result
|
|
29
|
+
*/
|
|
30
|
+
function dataAs<T extends DataTypes.BasicTemplate>(source: unknown, template: T, keepSource?: boolean): DataTypes.BasicTemplateType<T>;
|
|
24
31
|
/**
|
|
25
32
|
* Cast data to target type
|
|
26
33
|
* @param source Source data
|
package/lib/cjs/DomUtils.js
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
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
|
-
const tslib_1 = require("tslib");
|
|
5
13
|
const DataTypes_1 = require("./DataTypes");
|
|
6
14
|
if (typeof navigator === 'undefined') {
|
|
7
15
|
// Test mock only
|
|
@@ -126,12 +134,21 @@ var DomUtils;
|
|
|
126
134
|
Reflect.set(data, property, propertyValue);
|
|
127
135
|
}
|
|
128
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* Cast data as template format
|
|
139
|
+
* @param source Source data
|
|
140
|
+
* @param template Format template
|
|
141
|
+
* @param keepSource Keep other source properties
|
|
142
|
+
* @returns Result
|
|
143
|
+
*/
|
|
129
144
|
function dataAs(source, template, keepSource = false) {
|
|
130
145
|
// New data
|
|
131
146
|
// Object.create(...)
|
|
132
147
|
const data = {};
|
|
133
|
-
|
|
134
|
-
|
|
148
|
+
if (source != null && typeof source === 'object') {
|
|
149
|
+
// Travel all properties
|
|
150
|
+
dataAsTraveller(source, data, template, keepSource, false);
|
|
151
|
+
}
|
|
135
152
|
// Return
|
|
136
153
|
return data;
|
|
137
154
|
}
|
|
@@ -220,7 +237,7 @@ var DomUtils;
|
|
|
220
237
|
* @returns Data URL
|
|
221
238
|
*/
|
|
222
239
|
function fileToDataURL(file) {
|
|
223
|
-
return
|
|
240
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
224
241
|
return new Promise((resolve, reject) => {
|
|
225
242
|
const reader = new FileReader();
|
|
226
243
|
reader.onerror = reject;
|
package/lib/cjs/index.js
CHANGED
|
@@ -1,19 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
tslib_1.__exportStar(require("./Utils"), exports);
|
|
17
|
+
__exportStar(require("./types/DelayedExecutorType"), exports);
|
|
18
|
+
__exportStar(require("./types/EColor"), exports);
|
|
19
|
+
__exportStar(require("./types/EHistory"), exports);
|
|
20
|
+
__exportStar(require("./types/EventClass"), exports);
|
|
21
|
+
__exportStar(require("./types/FormData"), exports);
|
|
22
|
+
__exportStar(require("./storage/IStorage"), exports);
|
|
23
|
+
__exportStar(require("./storage/WindowStorage"), exports);
|
|
24
|
+
__exportStar(require("./DataTypes"), exports);
|
|
25
|
+
__exportStar(require("./ColorUtils"), exports);
|
|
26
|
+
__exportStar(require("./DateUtils"), exports);
|
|
27
|
+
__exportStar(require("./DomUtils"), exports);
|
|
28
|
+
__exportStar(require("./ExtendUtils"), exports);
|
|
29
|
+
__exportStar(require("./Keyboard"), exports);
|
|
30
|
+
__exportStar(require("./NumberUtils"), exports);
|
|
31
|
+
__exportStar(require("./StorageUtils"), exports);
|
|
32
|
+
__exportStar(require("./Utils"), exports);
|
package/lib/mjs/DomUtils.d.ts
CHANGED
|
@@ -20,7 +20,14 @@ export declare namespace DomUtils {
|
|
|
20
20
|
* @param keepFields Fields need to be kept
|
|
21
21
|
*/
|
|
22
22
|
function clearFormData(data: IFormData, source?: {}, keepFields?: string[]): IFormData;
|
|
23
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Cast data as template format
|
|
25
|
+
* @param source Source data
|
|
26
|
+
* @param template Format template
|
|
27
|
+
* @param keepSource Keep other source properties
|
|
28
|
+
* @returns Result
|
|
29
|
+
*/
|
|
30
|
+
function dataAs<T extends DataTypes.BasicTemplate>(source: unknown, template: T, keepSource?: boolean): DataTypes.BasicTemplateType<T>;
|
|
24
31
|
/**
|
|
25
32
|
* Cast data to target type
|
|
26
33
|
* @param source Source data
|
package/lib/mjs/DomUtils.js
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
|
|
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
|
+
};
|
|
2
10
|
import { DataTypes } from './DataTypes';
|
|
3
11
|
if (typeof navigator === 'undefined') {
|
|
4
12
|
// Test mock only
|
|
@@ -123,12 +131,21 @@ export var DomUtils;
|
|
|
123
131
|
Reflect.set(data, property, propertyValue);
|
|
124
132
|
}
|
|
125
133
|
}
|
|
134
|
+
/**
|
|
135
|
+
* Cast data as template format
|
|
136
|
+
* @param source Source data
|
|
137
|
+
* @param template Format template
|
|
138
|
+
* @param keepSource Keep other source properties
|
|
139
|
+
* @returns Result
|
|
140
|
+
*/
|
|
126
141
|
function dataAs(source, template, keepSource = false) {
|
|
127
142
|
// New data
|
|
128
143
|
// Object.create(...)
|
|
129
144
|
const data = {};
|
|
130
|
-
|
|
131
|
-
|
|
145
|
+
if (source != null && typeof source === 'object') {
|
|
146
|
+
// Travel all properties
|
|
147
|
+
dataAsTraveller(source, data, template, keepSource, false);
|
|
148
|
+
}
|
|
132
149
|
// Return
|
|
133
150
|
return data;
|
|
134
151
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/shared",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.39",
|
|
4
4
|
"description": "TypeScript shared utilities and functions",
|
|
5
5
|
"main": "lib/cjs/index.js",
|
|
6
6
|
"module": "lib/mjs/index.js",
|
|
@@ -55,16 +55,15 @@
|
|
|
55
55
|
"homepage": "https://github.com/ETSOO/Shared#readme",
|
|
56
56
|
"dependencies": {},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@types/jest": "^27.5.
|
|
59
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
60
|
-
"@typescript-eslint/parser": "^5.
|
|
61
|
-
"eslint": "^8.
|
|
58
|
+
"@types/jest": "^27.5.1",
|
|
59
|
+
"@typescript-eslint/eslint-plugin": "^5.25.0",
|
|
60
|
+
"@typescript-eslint/parser": "^5.25.0",
|
|
61
|
+
"eslint": "^8.16.0",
|
|
62
62
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
63
63
|
"eslint-plugin-import": "^2.26.0",
|
|
64
64
|
"jest": "^28.1.0",
|
|
65
65
|
"jest-environment-jsdom": "^28.1.0",
|
|
66
66
|
"ts-jest": "^28.0.2",
|
|
67
|
-
"tslib": "^2.4.0",
|
|
68
67
|
"typescript": "^4.6.4"
|
|
69
68
|
}
|
|
70
69
|
}
|
package/src/DomUtils.ts
CHANGED
|
@@ -151,8 +151,15 @@ export namespace DomUtils {
|
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
153
|
|
|
154
|
+
/**
|
|
155
|
+
* Cast data as template format
|
|
156
|
+
* @param source Source data
|
|
157
|
+
* @param template Format template
|
|
158
|
+
* @param keepSource Keep other source properties
|
|
159
|
+
* @returns Result
|
|
160
|
+
*/
|
|
154
161
|
export function dataAs<T extends DataTypes.BasicTemplate>(
|
|
155
|
-
source:
|
|
162
|
+
source: unknown,
|
|
156
163
|
template: T,
|
|
157
164
|
keepSource: boolean = false
|
|
158
165
|
): DataTypes.BasicTemplateType<T> {
|
|
@@ -160,8 +167,10 @@ export namespace DomUtils {
|
|
|
160
167
|
// Object.create(...)
|
|
161
168
|
const data = <DataTypes.BasicTemplateType<T>>{};
|
|
162
169
|
|
|
163
|
-
|
|
164
|
-
|
|
170
|
+
if (source != null && typeof source === 'object') {
|
|
171
|
+
// Travel all properties
|
|
172
|
+
dataAsTraveller(source, data, template, keepSource, false);
|
|
173
|
+
}
|
|
165
174
|
|
|
166
175
|
// Return
|
|
167
176
|
return data;
|
package/tsconfig.cjs.json
CHANGED