@etsoo/shared 1.1.38 → 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/lib/cjs/DomUtils.d.ts +8 -1
- package/lib/cjs/DomUtils.js +11 -2
- package/lib/mjs/DomUtils.d.ts +8 -1
- package/lib/mjs/DomUtils.js +11 -2
- package/package.json +1 -1
- package/src/DomUtils.ts +12 -3
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/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
|
@@ -134,12 +134,21 @@ var DomUtils;
|
|
|
134
134
|
Reflect.set(data, property, propertyValue);
|
|
135
135
|
}
|
|
136
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
|
+
*/
|
|
137
144
|
function dataAs(source, template, keepSource = false) {
|
|
138
145
|
// New data
|
|
139
146
|
// Object.create(...)
|
|
140
147
|
const data = {};
|
|
141
|
-
|
|
142
|
-
|
|
148
|
+
if (source != null && typeof source === 'object') {
|
|
149
|
+
// Travel all properties
|
|
150
|
+
dataAsTraveller(source, data, template, keepSource, false);
|
|
151
|
+
}
|
|
143
152
|
// Return
|
|
144
153
|
return data;
|
|
145
154
|
}
|
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
|
@@ -131,12 +131,21 @@ export var DomUtils;
|
|
|
131
131
|
Reflect.set(data, property, propertyValue);
|
|
132
132
|
}
|
|
133
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
|
+
*/
|
|
134
141
|
function dataAs(source, template, keepSource = false) {
|
|
135
142
|
// New data
|
|
136
143
|
// Object.create(...)
|
|
137
144
|
const data = {};
|
|
138
|
-
|
|
139
|
-
|
|
145
|
+
if (source != null && typeof source === 'object') {
|
|
146
|
+
// Travel all properties
|
|
147
|
+
dataAsTraveller(source, data, template, keepSource, false);
|
|
148
|
+
}
|
|
140
149
|
// Return
|
|
141
150
|
return data;
|
|
142
151
|
}
|
package/package.json
CHANGED
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;
|