@etsoo/shared 1.1.37 → 1.1.40
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 +11 -2
- package/lib/cjs/Utils.d.ts +4 -4
- package/lib/mjs/DomUtils.d.ts +8 -1
- package/lib/mjs/DomUtils.js +11 -2
- package/lib/mjs/Utils.d.ts +4 -4
- package/package.json +7 -7
- 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/__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
|
@@ -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/cjs/Utils.d.ts
CHANGED
|
@@ -114,13 +114,13 @@ export declare namespace Utils {
|
|
|
114
114
|
* @param minLength Minimum length
|
|
115
115
|
* @returns Result
|
|
116
116
|
*/
|
|
117
|
-
const isDigits: (input?: string
|
|
117
|
+
const isDigits: (input?: string, minLength?: number) => boolean;
|
|
118
118
|
/**
|
|
119
119
|
* Is email string
|
|
120
120
|
* @param input Input string
|
|
121
121
|
* @returns Result
|
|
122
122
|
*/
|
|
123
|
-
const isEmail: (input?: string
|
|
123
|
+
const isEmail: (input?: string) => boolean;
|
|
124
124
|
/**
|
|
125
125
|
* Join items as a string
|
|
126
126
|
* @param items Items
|
|
@@ -188,7 +188,7 @@ export declare namespace Utils {
|
|
|
188
188
|
* @param input Input string
|
|
189
189
|
* @returns Result
|
|
190
190
|
*/
|
|
191
|
-
const removeNonLetters: (input?: string
|
|
191
|
+
const removeNonLetters: (input?: string) => string | undefined;
|
|
192
192
|
/**
|
|
193
193
|
* Replace null or empty with default value
|
|
194
194
|
* @param input Input string
|
|
@@ -202,7 +202,7 @@ export declare namespace Utils {
|
|
|
202
202
|
* @param labels Labels
|
|
203
203
|
* @param reference Key reference dictionary
|
|
204
204
|
*/
|
|
205
|
-
const setLabels: (source: {}, labels: DataTypes.StringRecord, reference?: Readonly<DataTypes.StringDictionary>
|
|
205
|
+
const setLabels: (source: {}, labels: DataTypes.StringRecord, reference?: Readonly<DataTypes.StringDictionary>) => void;
|
|
206
206
|
/**
|
|
207
207
|
* Snake name to works, 'snake_name' to 'Snake Name'
|
|
208
208
|
* @param name Name text
|
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/lib/mjs/Utils.d.ts
CHANGED
|
@@ -114,13 +114,13 @@ export declare namespace Utils {
|
|
|
114
114
|
* @param minLength Minimum length
|
|
115
115
|
* @returns Result
|
|
116
116
|
*/
|
|
117
|
-
const isDigits: (input?: string
|
|
117
|
+
const isDigits: (input?: string, minLength?: number) => boolean;
|
|
118
118
|
/**
|
|
119
119
|
* Is email string
|
|
120
120
|
* @param input Input string
|
|
121
121
|
* @returns Result
|
|
122
122
|
*/
|
|
123
|
-
const isEmail: (input?: string
|
|
123
|
+
const isEmail: (input?: string) => boolean;
|
|
124
124
|
/**
|
|
125
125
|
* Join items as a string
|
|
126
126
|
* @param items Items
|
|
@@ -188,7 +188,7 @@ export declare namespace Utils {
|
|
|
188
188
|
* @param input Input string
|
|
189
189
|
* @returns Result
|
|
190
190
|
*/
|
|
191
|
-
const removeNonLetters: (input?: string
|
|
191
|
+
const removeNonLetters: (input?: string) => string | undefined;
|
|
192
192
|
/**
|
|
193
193
|
* Replace null or empty with default value
|
|
194
194
|
* @param input Input string
|
|
@@ -202,7 +202,7 @@ export declare namespace Utils {
|
|
|
202
202
|
* @param labels Labels
|
|
203
203
|
* @param reference Key reference dictionary
|
|
204
204
|
*/
|
|
205
|
-
const setLabels: (source: {}, labels: DataTypes.StringRecord, reference?: Readonly<DataTypes.StringDictionary>
|
|
205
|
+
const setLabels: (source: {}, labels: DataTypes.StringRecord, reference?: Readonly<DataTypes.StringDictionary>) => void;
|
|
206
206
|
/**
|
|
207
207
|
* Snake name to works, 'snake_name' to 'Snake Name'
|
|
208
208
|
* @param name Name text
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/shared",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.40",
|
|
4
4
|
"description": "TypeScript shared utilities and functions",
|
|
5
5
|
"main": "lib/cjs/index.js",
|
|
6
6
|
"module": "lib/mjs/index.js",
|
|
@@ -55,15 +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.26.0",
|
|
60
|
+
"@typescript-eslint/parser": "^5.26.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
|
-
"ts-jest": "^28.0.
|
|
67
|
-
"typescript": "^4.
|
|
66
|
+
"ts-jest": "^28.0.3",
|
|
67
|
+
"typescript": "^4.7.2"
|
|
68
68
|
}
|
|
69
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;
|