@etsoo/shared 1.1.42 → 1.1.43
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 +0 -2
- package/__tests__/DataTypes.ts +6 -20
- package/lib/cjs/DataTypes.d.ts +6 -18
- package/lib/cjs/DataTypes.js +0 -22
- package/lib/mjs/DataTypes.d.ts +6 -18
- package/lib/mjs/DataTypes.js +0 -22
- package/package.json +3 -3
- package/src/DataTypes.ts +6 -27
package/README.md
CHANGED
|
@@ -118,8 +118,6 @@ Data type definitions and type safe functions
|
|
|
118
118
|
|getEnumKey|Get enum string literal type value|
|
|
119
119
|
|getEnumKeys|Get Enum keys|
|
|
120
120
|
|getIdValue|Get object id field value|
|
|
121
|
-
|getItemId|Get item id|
|
|
122
|
-
|getItemLabel|Get item label|
|
|
123
121
|
|getResult|Get input function or value result|
|
|
124
122
|
|getStringValue|Get object string field value|
|
|
125
123
|
|getValue|Get object field value|
|
package/__tests__/DataTypes.ts
CHANGED
|
@@ -77,17 +77,16 @@ test('Tests for getEnumKeys', () => {
|
|
|
77
77
|
expect(keys).toContainEqual('Unkwown');
|
|
78
78
|
});
|
|
79
79
|
|
|
80
|
-
test('Tests for
|
|
80
|
+
test('Tests for IdLabelItem', () => {
|
|
81
81
|
// Arrange
|
|
82
|
-
const items: DataTypes.
|
|
83
|
-
{ id: 1 },
|
|
84
|
-
{ id: '
|
|
85
|
-
{ id: () => 'f123' }
|
|
82
|
+
const items: DataTypes.IdLabelItem[] = [
|
|
83
|
+
{ id: 1, label: 'Item 1' },
|
|
84
|
+
{ id: 2, label: 'Item 2' }
|
|
86
85
|
];
|
|
87
86
|
|
|
88
87
|
// Assert
|
|
89
|
-
expect(
|
|
90
|
-
expect(
|
|
88
|
+
expect(items[0].id).toBe(1);
|
|
89
|
+
expect(items[1].label).toBe('Item 2');
|
|
91
90
|
});
|
|
92
91
|
|
|
93
92
|
test('Tests for getValue', () => {
|
|
@@ -109,19 +108,6 @@ test('Tests for getStringValue', () => {
|
|
|
109
108
|
expect(DataTypes.getStringValue(data, 'flag')).toBe('true');
|
|
110
109
|
});
|
|
111
110
|
|
|
112
|
-
test('Tests for getItemLabel', () => {
|
|
113
|
-
// Arrange
|
|
114
|
-
const items: DataTypes.IdLabelItem[] = [
|
|
115
|
-
{ id: 1, label: '123' },
|
|
116
|
-
{ id: '123', label: () => 'f123' },
|
|
117
|
-
{ id: () => 'f123', label: 'l123' }
|
|
118
|
-
];
|
|
119
|
-
|
|
120
|
-
// Assert
|
|
121
|
-
expect(DataTypes.getItemLabel(items[0])).toBe('123');
|
|
122
|
-
expect(DataTypes.getItemLabel(items[1])).toBe('f123');
|
|
123
|
-
});
|
|
124
|
-
|
|
125
111
|
test('Tests for isSimpleType', () => {
|
|
126
112
|
expect(DataTypes.isSimpleType(1)).toBeTruthy();
|
|
127
113
|
expect(DataTypes.isSimpleType(new Date())).toBeTruthy();
|
package/lib/cjs/DataTypes.d.ts
CHANGED
|
@@ -153,20 +153,20 @@ export declare namespace DataTypes {
|
|
|
153
153
|
/**
|
|
154
154
|
* Item with id property
|
|
155
155
|
*/
|
|
156
|
-
type IdItem = {
|
|
156
|
+
type IdItem<T extends IdType = number> = {
|
|
157
157
|
/**
|
|
158
|
-
* Id field
|
|
158
|
+
* Id field
|
|
159
159
|
*/
|
|
160
|
-
id:
|
|
160
|
+
id: T;
|
|
161
161
|
};
|
|
162
162
|
/**
|
|
163
163
|
* Item with id and label property
|
|
164
164
|
*/
|
|
165
|
-
type IdLabelItem = IdItem & {
|
|
165
|
+
type IdLabelItem<T extends IdType = number> = IdItem<T> & {
|
|
166
166
|
/**
|
|
167
|
-
* label field
|
|
167
|
+
* label field
|
|
168
168
|
*/
|
|
169
|
-
label: string
|
|
169
|
+
label: string;
|
|
170
170
|
};
|
|
171
171
|
/**
|
|
172
172
|
* Get specific type keys
|
|
@@ -174,18 +174,6 @@ export declare namespace DataTypes {
|
|
|
174
174
|
type Keys<T, R = string | number> = {
|
|
175
175
|
[k in keyof T]: T[k] extends R ? k : never;
|
|
176
176
|
}[keyof T];
|
|
177
|
-
/**
|
|
178
|
-
* Get item id
|
|
179
|
-
* @param item Item with id
|
|
180
|
-
* @returns string id
|
|
181
|
-
*/
|
|
182
|
-
const getItemId: (item: IdItem) => string;
|
|
183
|
-
/**
|
|
184
|
-
* Get item label
|
|
185
|
-
* @param item Item with id
|
|
186
|
-
* @returns string id
|
|
187
|
-
*/
|
|
188
|
-
const getItemLabel: (item: IdLabelItem) => string;
|
|
189
177
|
/**
|
|
190
178
|
* Culture definiton
|
|
191
179
|
*/
|
package/lib/cjs/DataTypes.js
CHANGED
|
@@ -71,28 +71,6 @@ var DataTypes;
|
|
|
71
71
|
VAlignEnum[VAlignEnum["Center"] = 2] = "Center";
|
|
72
72
|
VAlignEnum[VAlignEnum["Bottom"] = 3] = "Bottom";
|
|
73
73
|
})(VAlignEnum = DataTypes.VAlignEnum || (DataTypes.VAlignEnum = {}));
|
|
74
|
-
/**
|
|
75
|
-
* Get item id
|
|
76
|
-
* @param item Item with id
|
|
77
|
-
* @returns string id
|
|
78
|
-
*/
|
|
79
|
-
DataTypes.getItemId = (item) => {
|
|
80
|
-
if (typeof item.id === 'function')
|
|
81
|
-
return item.id();
|
|
82
|
-
if (typeof item.id === 'number')
|
|
83
|
-
return item.id.toString();
|
|
84
|
-
return item.id;
|
|
85
|
-
};
|
|
86
|
-
/**
|
|
87
|
-
* Get item label
|
|
88
|
-
* @param item Item with id
|
|
89
|
-
* @returns string id
|
|
90
|
-
*/
|
|
91
|
-
DataTypes.getItemLabel = (item) => {
|
|
92
|
-
if (typeof item.label === 'function')
|
|
93
|
-
return item.label();
|
|
94
|
-
return item.label;
|
|
95
|
-
};
|
|
96
74
|
/**
|
|
97
75
|
* Convert value to target type
|
|
98
76
|
* @param input Input value
|
package/lib/mjs/DataTypes.d.ts
CHANGED
|
@@ -153,20 +153,20 @@ export declare namespace DataTypes {
|
|
|
153
153
|
/**
|
|
154
154
|
* Item with id property
|
|
155
155
|
*/
|
|
156
|
-
type IdItem = {
|
|
156
|
+
type IdItem<T extends IdType = number> = {
|
|
157
157
|
/**
|
|
158
|
-
* Id field
|
|
158
|
+
* Id field
|
|
159
159
|
*/
|
|
160
|
-
id:
|
|
160
|
+
id: T;
|
|
161
161
|
};
|
|
162
162
|
/**
|
|
163
163
|
* Item with id and label property
|
|
164
164
|
*/
|
|
165
|
-
type IdLabelItem = IdItem & {
|
|
165
|
+
type IdLabelItem<T extends IdType = number> = IdItem<T> & {
|
|
166
166
|
/**
|
|
167
|
-
* label field
|
|
167
|
+
* label field
|
|
168
168
|
*/
|
|
169
|
-
label: string
|
|
169
|
+
label: string;
|
|
170
170
|
};
|
|
171
171
|
/**
|
|
172
172
|
* Get specific type keys
|
|
@@ -174,18 +174,6 @@ export declare namespace DataTypes {
|
|
|
174
174
|
type Keys<T, R = string | number> = {
|
|
175
175
|
[k in keyof T]: T[k] extends R ? k : never;
|
|
176
176
|
}[keyof T];
|
|
177
|
-
/**
|
|
178
|
-
* Get item id
|
|
179
|
-
* @param item Item with id
|
|
180
|
-
* @returns string id
|
|
181
|
-
*/
|
|
182
|
-
const getItemId: (item: IdItem) => string;
|
|
183
|
-
/**
|
|
184
|
-
* Get item label
|
|
185
|
-
* @param item Item with id
|
|
186
|
-
* @returns string id
|
|
187
|
-
*/
|
|
188
|
-
const getItemLabel: (item: IdLabelItem) => string;
|
|
189
177
|
/**
|
|
190
178
|
* Culture definiton
|
|
191
179
|
*/
|
package/lib/mjs/DataTypes.js
CHANGED
|
@@ -68,28 +68,6 @@ export var DataTypes;
|
|
|
68
68
|
VAlignEnum[VAlignEnum["Center"] = 2] = "Center";
|
|
69
69
|
VAlignEnum[VAlignEnum["Bottom"] = 3] = "Bottom";
|
|
70
70
|
})(VAlignEnum = DataTypes.VAlignEnum || (DataTypes.VAlignEnum = {}));
|
|
71
|
-
/**
|
|
72
|
-
* Get item id
|
|
73
|
-
* @param item Item with id
|
|
74
|
-
* @returns string id
|
|
75
|
-
*/
|
|
76
|
-
DataTypes.getItemId = (item) => {
|
|
77
|
-
if (typeof item.id === 'function')
|
|
78
|
-
return item.id();
|
|
79
|
-
if (typeof item.id === 'number')
|
|
80
|
-
return item.id.toString();
|
|
81
|
-
return item.id;
|
|
82
|
-
};
|
|
83
|
-
/**
|
|
84
|
-
* Get item label
|
|
85
|
-
* @param item Item with id
|
|
86
|
-
* @returns string id
|
|
87
|
-
*/
|
|
88
|
-
DataTypes.getItemLabel = (item) => {
|
|
89
|
-
if (typeof item.label === 'function')
|
|
90
|
-
return item.label();
|
|
91
|
-
return item.label;
|
|
92
|
-
};
|
|
93
71
|
/**
|
|
94
72
|
* Convert value to target type
|
|
95
73
|
* @param input Input value
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/shared",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.43",
|
|
4
4
|
"description": "TypeScript shared utilities and functions",
|
|
5
5
|
"main": "lib/cjs/index.js",
|
|
6
6
|
"module": "lib/mjs/index.js",
|
|
@@ -56,8 +56,8 @@
|
|
|
56
56
|
"dependencies": {},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@types/jest": "^28.1.6",
|
|
59
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
60
|
-
"@typescript-eslint/parser": "^5.
|
|
59
|
+
"@typescript-eslint/eslint-plugin": "^5.33.0",
|
|
60
|
+
"@typescript-eslint/parser": "^5.33.0",
|
|
61
61
|
"eslint": "^8.21.0",
|
|
62
62
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
63
63
|
"eslint-plugin-import": "^2.26.0",
|
package/src/DataTypes.ts
CHANGED
|
@@ -196,21 +196,21 @@ export namespace DataTypes {
|
|
|
196
196
|
/**
|
|
197
197
|
* Item with id property
|
|
198
198
|
*/
|
|
199
|
-
export type IdItem = {
|
|
199
|
+
export type IdItem<T extends IdType = number> = {
|
|
200
200
|
/**
|
|
201
|
-
* Id field
|
|
201
|
+
* Id field
|
|
202
202
|
*/
|
|
203
|
-
id:
|
|
203
|
+
id: T;
|
|
204
204
|
};
|
|
205
205
|
|
|
206
206
|
/**
|
|
207
207
|
* Item with id and label property
|
|
208
208
|
*/
|
|
209
|
-
export type IdLabelItem = IdItem & {
|
|
209
|
+
export type IdLabelItem<T extends IdType = number> = IdItem<T> & {
|
|
210
210
|
/**
|
|
211
|
-
* label field
|
|
211
|
+
* label field
|
|
212
212
|
*/
|
|
213
|
-
label: string
|
|
213
|
+
label: string;
|
|
214
214
|
};
|
|
215
215
|
|
|
216
216
|
/**
|
|
@@ -220,27 +220,6 @@ export namespace DataTypes {
|
|
|
220
220
|
[k in keyof T]: T[k] extends R ? k : never;
|
|
221
221
|
}[keyof T];
|
|
222
222
|
|
|
223
|
-
/**
|
|
224
|
-
* Get item id
|
|
225
|
-
* @param item Item with id
|
|
226
|
-
* @returns string id
|
|
227
|
-
*/
|
|
228
|
-
export const getItemId = (item: IdItem) => {
|
|
229
|
-
if (typeof item.id === 'function') return item.id();
|
|
230
|
-
if (typeof item.id === 'number') return item.id.toString();
|
|
231
|
-
return item.id;
|
|
232
|
-
};
|
|
233
|
-
|
|
234
|
-
/**
|
|
235
|
-
* Get item label
|
|
236
|
-
* @param item Item with id
|
|
237
|
-
* @returns string id
|
|
238
|
-
*/
|
|
239
|
-
export const getItemLabel = (item: IdLabelItem) => {
|
|
240
|
-
if (typeof item.label === 'function') return item.label();
|
|
241
|
-
return item.label;
|
|
242
|
-
};
|
|
243
|
-
|
|
244
223
|
/**
|
|
245
224
|
* Culture definiton
|
|
246
225
|
*/
|