@etsoo/shared 1.1.45 → 1.1.46

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
@@ -88,6 +88,8 @@ Data type definitions and type safe functions
88
88
  |BasicTemplateType|Basic template type|
89
89
  |CombinedEnum|Combined type enum|
90
90
  |CultureDefinition|Culture definition|
91
+ |DI|Dynamic interface with multiple properties|
92
+ |DIS|Dynamic interface with single property|
91
93
  |EnumBase|Enum base type|
92
94
  |EnumValue|Enum value type|
93
95
  |ExtendedEnum|Extended type enum|
@@ -97,6 +99,7 @@ Data type definitions and type safe functions
97
99
  |IdType|Number and string combination id type|
98
100
  |IdItem|Item with id or id generator|
99
101
  |IdLabelItem|Item with id and label|
102
+ |IdLabelType|Item with id and label dynamic type|
100
103
  |KeyCollection|Key collection, like { key1: {}, key2: {} }|
101
104
  |Keys|Get specific type keys|
102
105
  |Simple|Basic or basic array type|
@@ -1,5 +1,22 @@
1
1
  import { DataTypes } from '../src/DataTypes';
2
2
 
3
+ test('Tests for DI', () => {
4
+ const item: DataTypes.DIS<'id', number> & DataTypes.DIS<'label', string> = {
5
+ id: 1,
6
+ label: 'Etsoo'
7
+ };
8
+ expect(item.id).toBe(1);
9
+ });
10
+
11
+ test('Tests for IdLabelType', () => {
12
+ const item: DataTypes.IdLabelItem = {
13
+ id: 1,
14
+ label: 'Etsoo'
15
+ };
16
+ const itemCopy: DataTypes.IdLabelType<'id', 'label'> = { ...item };
17
+ expect(item).toEqual(itemCopy);
18
+ });
19
+
3
20
  test('Tests for convert', () => {
4
21
  expect(DataTypes.convert('5', 0)).toStrictEqual(5);
5
22
  expect(
@@ -168,6 +168,10 @@ export declare namespace DataTypes {
168
168
  */
169
169
  label: string;
170
170
  };
171
+ /**
172
+ * Item with id and label dynamic type
173
+ */
174
+ type IdLabelType<I extends string, L extends string, D extends IdType = number> = DIS<I, D> & DIS<L, string>;
171
175
  /**
172
176
  * Get specific type keys
173
177
  */
@@ -195,6 +199,18 @@ export declare namespace DataTypes {
195
199
  */
196
200
  compatibleName?: string[];
197
201
  }>;
202
+ /**
203
+ * Dynamic interface with multiple properties
204
+ */
205
+ type DI<K extends readonly string[], T> = {
206
+ [P in K[number]]: T;
207
+ };
208
+ /**
209
+ * Dynamic interface with single property
210
+ */
211
+ type DIS<K extends string, T> = {
212
+ [P in K]: T;
213
+ };
198
214
  /**
199
215
  * Convert value to target type
200
216
  * @param input Input value
@@ -168,6 +168,10 @@ export declare namespace DataTypes {
168
168
  */
169
169
  label: string;
170
170
  };
171
+ /**
172
+ * Item with id and label dynamic type
173
+ */
174
+ type IdLabelType<I extends string, L extends string, D extends IdType = number> = DIS<I, D> & DIS<L, string>;
171
175
  /**
172
176
  * Get specific type keys
173
177
  */
@@ -195,6 +199,18 @@ export declare namespace DataTypes {
195
199
  */
196
200
  compatibleName?: string[];
197
201
  }>;
202
+ /**
203
+ * Dynamic interface with multiple properties
204
+ */
205
+ type DI<K extends readonly string[], T> = {
206
+ [P in K[number]]: T;
207
+ };
208
+ /**
209
+ * Dynamic interface with single property
210
+ */
211
+ type DIS<K extends string, T> = {
212
+ [P in K]: T;
213
+ };
198
214
  /**
199
215
  * Convert value to target type
200
216
  * @param input Input value
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/shared",
3
- "version": "1.1.45",
3
+ "version": "1.1.46",
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": "^28.1.6",
59
- "@typescript-eslint/eslint-plugin": "^5.33.0",
60
- "@typescript-eslint/parser": "^5.33.0",
58
+ "@types/jest": "^28.1.7",
59
+ "@typescript-eslint/eslint-plugin": "^5.34.0",
60
+ "@typescript-eslint/parser": "^5.34.0",
61
61
  "eslint": "^8.22.0",
62
62
  "eslint-config-airbnb-base": "^15.0.0",
63
63
  "eslint-plugin-import": "^2.26.0",
64
64
  "jest": "^28.1.3",
65
65
  "jest-environment-jsdom": "^28.1.3",
66
- "ts-jest": "^28.0.7",
66
+ "ts-jest": "^28.0.8",
67
67
  "typescript": "^4.7.4"
68
68
  }
69
69
  }
package/src/DataTypes.ts CHANGED
@@ -213,6 +213,15 @@ export namespace DataTypes {
213
213
  label: string;
214
214
  };
215
215
 
216
+ /**
217
+ * Item with id and label dynamic type
218
+ */
219
+ export type IdLabelType<
220
+ I extends string,
221
+ L extends string,
222
+ D extends IdType = number
223
+ > = DIS<I, D> & DIS<L, string>;
224
+
216
225
  /**
217
226
  * Get specific type keys
218
227
  */
@@ -245,6 +254,16 @@ export namespace DataTypes {
245
254
  compatibleName?: string[];
246
255
  }>;
247
256
 
257
+ /**
258
+ * Dynamic interface with multiple properties
259
+ */
260
+ export type DI<K extends readonly string[], T> = { [P in K[number]]: T };
261
+
262
+ /**
263
+ * Dynamic interface with single property
264
+ */
265
+ export type DIS<K extends string, T> = { [P in K]: T };
266
+
248
267
  /**
249
268
  * Convert value to target type
250
269
  * @param input Input value