@etsoo/shared 1.1.19 → 1.1.22

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 CHANGED
@@ -68,6 +68,7 @@ Data type definitions and type safe functions
68
68
  |IdType|Number and string combination id type|
69
69
  |IdItem|Item with id or id generator|
70
70
  |IdLabelItem|Item with id and label|
71
+ |KeyCollection|Key collection, like { key1: {}, key2: {} }|
71
72
  |Simple|Basic or basic array type|
72
73
  |SimpleEnum|Simple type enum|
73
74
  |SimpleNames|Simple type names|
@@ -120,6 +120,12 @@ export declare namespace DataTypes {
120
120
  type AddOrEditType<T, Editing extends boolean> = (Editing extends true ? T : Partial<T>) & {
121
121
  changedFields?: string[];
122
122
  };
123
+ /**
124
+ * Key collection, like { key1: {}, key2: {} }
125
+ */
126
+ type KeyCollection<K extends readonly string[], I extends {}> = {
127
+ [index in K[number]]: I;
128
+ };
123
129
  /**
124
130
  * Enum value type
125
131
  */
@@ -177,23 +183,23 @@ export declare namespace DataTypes {
177
183
  /**
178
184
  * Culture definiton
179
185
  */
180
- type CultureDefinition = Readonly<{
186
+ type CultureDefinition<T extends {} = StringRecord> = Readonly<{
181
187
  /**
182
188
  * Name, like zh-CN
183
189
  */
184
- readonly name: string;
190
+ name: string;
185
191
  /**
186
192
  * Label for description, like Simplifined Chinese
187
193
  */
188
- readonly label: string;
194
+ label: string;
189
195
  /**
190
196
  * Resources
191
197
  */
192
- readonly resources: Readonly<StringRecord>;
198
+ resources: T;
193
199
  /**
194
200
  * Compatible names
195
201
  */
196
- readonly compatibleName?: string[];
202
+ compatibleName?: string[];
197
203
  }>;
198
204
  /**
199
205
  * Convert value to target type
@@ -54,11 +54,16 @@ export declare namespace DomUtils {
54
54
  * @param items Available cultures
55
55
  * @param culture Detected culture
56
56
  */
57
- const getCulture: (items: DataTypes.CultureDefinition[], culture: string) => Readonly<{
58
- readonly name: string;
59
- readonly label: string;
60
- readonly resources: Readonly<DataTypes.StringRecord>;
61
- readonly compatibleName?: string[] | undefined;
57
+ const getCulture: <T extends {}>(items: Readonly<{
58
+ name: string;
59
+ label: string;
60
+ resources: T;
61
+ compatibleName?: string[] | undefined;
62
+ }>[], culture: string) => Readonly<{
63
+ name: string;
64
+ label: string;
65
+ resources: T;
66
+ compatibleName?: string[] | undefined;
62
67
  }> | undefined;
63
68
  /**
64
69
  * Get an unique key combined with current URL
@@ -120,6 +120,12 @@ export declare namespace DataTypes {
120
120
  type AddOrEditType<T, Editing extends boolean> = (Editing extends true ? T : Partial<T>) & {
121
121
  changedFields?: string[];
122
122
  };
123
+ /**
124
+ * Key collection, like { key1: {}, key2: {} }
125
+ */
126
+ type KeyCollection<K extends readonly string[], I extends {}> = {
127
+ [index in K[number]]: I;
128
+ };
123
129
  /**
124
130
  * Enum value type
125
131
  */
@@ -177,23 +183,23 @@ export declare namespace DataTypes {
177
183
  /**
178
184
  * Culture definiton
179
185
  */
180
- type CultureDefinition = Readonly<{
186
+ type CultureDefinition<T extends {} = StringRecord> = Readonly<{
181
187
  /**
182
188
  * Name, like zh-CN
183
189
  */
184
- readonly name: string;
190
+ name: string;
185
191
  /**
186
192
  * Label for description, like Simplifined Chinese
187
193
  */
188
- readonly label: string;
194
+ label: string;
189
195
  /**
190
196
  * Resources
191
197
  */
192
- readonly resources: Readonly<StringRecord>;
198
+ resources: T;
193
199
  /**
194
200
  * Compatible names
195
201
  */
196
- readonly compatibleName?: string[];
202
+ compatibleName?: string[];
197
203
  }>;
198
204
  /**
199
205
  * Convert value to target type
@@ -54,11 +54,16 @@ export declare namespace DomUtils {
54
54
  * @param items Available cultures
55
55
  * @param culture Detected culture
56
56
  */
57
- const getCulture: (items: DataTypes.CultureDefinition[], culture: string) => Readonly<{
58
- readonly name: string;
59
- readonly label: string;
60
- readonly resources: Readonly<DataTypes.StringRecord>;
61
- readonly compatibleName?: string[] | undefined;
57
+ const getCulture: <T extends {}>(items: Readonly<{
58
+ name: string;
59
+ label: string;
60
+ resources: T;
61
+ compatibleName?: string[] | undefined;
62
+ }>[], culture: string) => Readonly<{
63
+ name: string;
64
+ label: string;
65
+ resources: T;
66
+ compatibleName?: string[] | undefined;
62
67
  }> | undefined;
63
68
  /**
64
69
  * Get an unique key combined with current URL
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/shared",
3
- "version": "1.1.19",
3
+ "version": "1.1.22",
4
4
  "description": "TypeScript shared utilities and functions",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -55,11 +55,11 @@
55
55
  "dependencies": {},
56
56
  "devDependencies": {
57
57
  "@types/jest": "^27.4.1",
58
- "@typescript-eslint/eslint-plugin": "^5.17.0",
59
- "@typescript-eslint/parser": "^5.17.0",
60
- "eslint": "^8.12.0",
58
+ "@typescript-eslint/eslint-plugin": "^5.20.0",
59
+ "@typescript-eslint/parser": "^5.20.0",
60
+ "eslint": "^8.14.0",
61
61
  "eslint-config-airbnb-base": "^15.0.0",
62
- "eslint-plugin-import": "^2.25.4",
62
+ "eslint-plugin-import": "^2.26.0",
63
63
  "jest": "^27.5.1",
64
64
  "ts-jest": "^27.1.4",
65
65
  "typescript": "^4.6.3"
package/src/DataTypes.ts CHANGED
@@ -156,6 +156,13 @@ export namespace DataTypes {
156
156
  Editing extends boolean
157
157
  > = (Editing extends true ? T : Partial<T>) & { changedFields?: string[] };
158
158
 
159
+ /**
160
+ * Key collection, like { key1: {}, key2: {} }
161
+ */
162
+ export type KeyCollection<K extends readonly string[], I extends {}> = {
163
+ [index in K[number]]: I;
164
+ };
165
+
159
166
  /**
160
167
  * Enum value type
161
168
  */
@@ -230,26 +237,26 @@ export namespace DataTypes {
230
237
  /**
231
238
  * Culture definiton
232
239
  */
233
- export type CultureDefinition = Readonly<{
240
+ export type CultureDefinition<T extends {} = StringRecord> = Readonly<{
234
241
  /**
235
242
  * Name, like zh-CN
236
243
  */
237
- readonly name: string;
244
+ name: string;
238
245
 
239
246
  /**
240
247
  * Label for description, like Simplifined Chinese
241
248
  */
242
- readonly label: string;
249
+ label: string;
243
250
 
244
251
  /**
245
252
  * Resources
246
253
  */
247
- readonly resources: Readonly<StringRecord>;
254
+ resources: T;
248
255
 
249
256
  /**
250
257
  * Compatible names
251
258
  */
252
- readonly compatibleName?: string[];
259
+ compatibleName?: string[];
253
260
  }>;
254
261
 
255
262
  /**
package/src/DomUtils.ts CHANGED
@@ -281,8 +281,8 @@ export namespace DomUtils {
281
281
  * @param items Available cultures
282
282
  * @param culture Detected culture
283
283
  */
284
- export const getCulture = (
285
- items: DataTypes.CultureDefinition[],
284
+ export const getCulture = <T extends {}>(
285
+ items: DataTypes.CultureDefinition<T>[],
286
286
  culture: string
287
287
  ) => {
288
288
  if (items.length === 0) {