@etsoo/shared 1.1.47 → 1.1.48

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
@@ -102,6 +102,7 @@ Data type definitions and type safe functions
102
102
  |IdLabelType|Item with id and label dynamic type|
103
103
  |KeyCollection|Key collection, like { key1: {}, key2: {} }|
104
104
  |Keys|Get specific type keys|
105
+ |ObjType|Generic object type|
105
106
  |Simple|Basic or basic array type|
106
107
  |SimpleEnum|Simple type enum|
107
108
  |SimpleNames|Simple type names|
@@ -143,9 +143,9 @@ test('Tests for objectEqual', () => {
143
143
 
144
144
  test('Tests for objectUpdated', () => {
145
145
  const objPrev = { a: 1, b: 'abc', c: true, d: null, f: [1, 2] };
146
- const objNew = { a: 2, b: 'abc', d: new Date(), f: [1, 2, 3] };
146
+ const objNew = { a: 2, b: 'abc', d: new Date(), f: [1, 2, 3], g: true };
147
147
  const fields = Utils.objectUpdated(objNew, objPrev, ['d']);
148
- expect(fields.sort()).toStrictEqual(['a', 'c', 'f']);
148
+ expect(fields.sort()).toStrictEqual(['a', 'c', 'f', 'g']);
149
149
  });
150
150
 
151
151
  test('Tests for parseString', () => {
@@ -1,3 +1,8 @@
1
+ /**
2
+ * Generic object type
3
+ * Narrow case, uses StringRecord
4
+ * Before was wrong with {}, from 4.8 unknown = {} | null | undefined
5
+ */
1
6
  /**
2
7
  * Interface data types
3
8
  */
@@ -123,8 +128,8 @@ export declare namespace DataTypes {
123
128
  /**
124
129
  * Key collection, like { key1: {}, key2: {} }
125
130
  */
126
- type KeyCollection<K extends readonly string[], I extends {}> = {
127
- [index in K[number]]: I;
131
+ type KeyCollection<K extends readonly string[], I extends object> = {
132
+ [P in K[number]]: I;
128
133
  };
129
134
  /**
130
135
  * Enum value type
@@ -181,7 +186,7 @@ export declare namespace DataTypes {
181
186
  /**
182
187
  * Culture definiton
183
188
  */
184
- type CultureDefinition<T extends {} = StringRecord> = Readonly<{
189
+ type CultureDefinition<T extends StringRecord = StringRecord> = Readonly<{
185
190
  /**
186
191
  * Name, like zh-CN
187
192
  */
@@ -278,28 +283,28 @@ export declare namespace DataTypes {
278
283
  * @param key Property name
279
284
  * @returns Value
280
285
  */
281
- function getValue<T extends {}, K extends keyof T | string>(data: T | undefined | null, key: K): K extends keyof T ? T[K] : undefined;
286
+ function getValue<T extends object, K extends keyof T | string>(data: T | undefined | null, key: K): K extends keyof T ? T[K] : undefined;
282
287
  /**
283
288
  * Get object id field value
284
289
  * @param data Data
285
290
  * @param key Property name
286
291
  * @returns Id value
287
292
  */
288
- function getIdValue<T extends {}, K extends Keys<T, string | number>>(data: T, key: K): T[K];
293
+ function getIdValue<T extends object, K extends Keys<T, string | number>>(data: T, key: K): T[K];
289
294
  /**
290
295
  * Get object id field value 1
291
296
  * @param data Data
292
297
  * @param key Property name
293
298
  * @returns Id value
294
299
  */
295
- function getIdValue1<T extends {}, K extends keyof T | string>(data: T | undefined | null, key: K): K extends keyof T ? (T[K] extends number ? number : string) : undefined;
300
+ function getIdValue1<T extends object, K extends keyof T | string>(data: T | undefined | null, key: K): K extends keyof T ? (T[K] extends number ? number : string) : undefined;
296
301
  /**
297
302
  * Get object string field value
298
303
  * @param data Data
299
304
  * @param key Property name
300
305
  * @returns String value
301
306
  */
302
- function getStringValue<T extends {}>(data: T | undefined | null, key: keyof T | string): string | undefined;
307
+ function getStringValue<T extends object>(data: T | undefined | null, key: keyof T | string): string | undefined;
303
308
  /**
304
309
  * Check the type is a basic type or not (type guard)
305
310
  * @param name Type name
@@ -1,4 +1,9 @@
1
1
  "use strict";
2
+ /**
3
+ * Generic object type
4
+ * Narrow case, uses StringRecord
5
+ * Before was wrong with {}, from 4.8 unknown = {} | null | undefined
6
+ */
2
7
  Object.defineProperty(exports, "__esModule", { value: true });
3
8
  exports.DataTypes = void 0;
4
9
  /**
@@ -19,7 +19,7 @@ export declare namespace DomUtils {
19
19
  * @param source Source data to match
20
20
  * @param keepFields Fields need to be kept
21
21
  */
22
- function clearFormData(data: IFormData, source?: {}, keepFields?: string[]): IFormData;
22
+ function clearFormData(data: IFormData, source?: object, keepFields?: string[]): IFormData;
23
23
  /**
24
24
  * Cast data as template format
25
25
  * @param source Source data
@@ -35,7 +35,7 @@ export declare namespace DomUtils {
35
35
  * @param keepSource Means even the template does not include the definition, still keep the item
36
36
  * @returns Result
37
37
  */
38
- function dataValueAs<T extends {}>(source: IFormData | {}, templateValue: T, keepSource?: boolean): Partial<T>;
38
+ function dataValueAs<T extends object>(source: IFormData | object, templateValue: T, keepSource?: boolean): Partial<T>;
39
39
  /**
40
40
  * Current detected country
41
41
  */
@@ -67,7 +67,7 @@ export declare namespace DomUtils {
67
67
  * @param items Available cultures
68
68
  * @param culture Detected culture
69
69
  */
70
- const getCulture: <T extends {}>(items: Readonly<{
70
+ const getCulture: <T extends DataTypes.StringRecord>(items: Readonly<{
71
71
  name: string;
72
72
  label: string;
73
73
  resources: T;
@@ -117,5 +117,5 @@ export declare namespace DomUtils {
117
117
  * @param name Element name or first collection item
118
118
  * @param container Container, limits the element range
119
119
  */
120
- function setFocus(name: string | {}, container?: HTMLElement): void;
120
+ function setFocus(name: string | object, container?: HTMLElement): void;
121
121
  }
@@ -30,7 +30,7 @@ export declare namespace StorageUtils {
30
30
  * Get local storage object data
31
31
  * @param key Key name
32
32
  */
33
- function getLocalObject<T extends {}>(key: string): T | undefined;
33
+ function getLocalObject<T extends object>(key: string): T | undefined;
34
34
  /**
35
35
  * Get session storage data
36
36
  * @param key Key name
@@ -46,5 +46,5 @@ export declare namespace StorageUtils {
46
46
  * Get session storage object data
47
47
  * @param key Key name
48
48
  */
49
- function getSessionObject<T extends {}>(key: string): T | undefined;
49
+ function getSessionObject<T extends object>(key: string): T | undefined;
50
50
  }
@@ -53,7 +53,7 @@ export declare namespace Utils {
53
53
  * @param labelField Label field, default is label
54
54
  * @param blankLabel Blank label, default is ---
55
55
  */
56
- function addBlankItem<T extends {}>(options: T[], idField?: string | keyof T, labelField?: unknown, blankLabel?: string): void;
56
+ function addBlankItem<T extends object>(options: T[], idField?: string | keyof T, labelField?: unknown, blankLabel?: string): void;
57
57
  /**
58
58
  * Base64 chars to number
59
59
  * @param base64Chars Base64 chars
@@ -65,7 +65,7 @@ export declare namespace Utils {
65
65
  * @param input Input object
66
66
  * @param fields Fields to correct
67
67
  */
68
- function correctTypes<T extends {}, F extends {
68
+ function correctTypes<T extends object, F extends {
69
69
  [P in keyof T]: DataTypes.BasicNames;
70
70
  }>(input: T, fields: F): void;
71
71
  /**
@@ -95,7 +95,7 @@ export declare namespace Utils {
95
95
  * @param ignoreFields Ignore fields
96
96
  * @returns
97
97
  */
98
- function getDataChanges(input: {}, initData: {}, ignoreFields?: string[]): string[];
98
+ function getDataChanges(input: object, initData: object, ignoreFields?: string[]): string[];
99
99
  /**
100
100
  * Get input function or value result
101
101
  * @param input Input function or value
@@ -150,7 +150,7 @@ export declare namespace Utils {
150
150
  * @param strict Strict level, 0 with ==, 1 === but null equal undefined, 2 ===
151
151
  * @returns Result
152
152
  */
153
- function objectEqual(obj1: {}, obj2: {}, ignoreFields?: string[], strict?: number): boolean;
153
+ function objectEqual(obj1: object, obj2: object, ignoreFields?: string[], strict?: number): boolean;
154
154
  /**
155
155
  * Get two object's unqiue properties
156
156
  * @param obj1 Object 1
@@ -158,7 +158,7 @@ export declare namespace Utils {
158
158
  * @param ignoreFields Ignored fields
159
159
  * @returns Unique properties
160
160
  */
161
- function objectKeys(obj1: {}, obj2: {}, ignoreFields?: string[]): Set<string>;
161
+ function objectKeys(obj1: object, obj2: object, ignoreFields?: string[]): Set<string>;
162
162
  /**
163
163
  * Get the new object's updated fields contrast to the previous object
164
164
  * @param objNew New object
@@ -167,7 +167,7 @@ export declare namespace Utils {
167
167
  * @param strict Strict level, 0 with ==, 1 === but null equal undefined, 2 ===
168
168
  * @returns Updated fields
169
169
  */
170
- function objectUpdated(objNew: {}, objPrev: {}, ignoreFields?: string[], strict?: number): string[];
170
+ function objectUpdated(objNew: object, objPrev: object, ignoreFields?: string[], strict?: number): string[];
171
171
  /**
172
172
  * Parse string (JSON) to specific type, no type conversion
173
173
  * For type conversion, please use DataTypes.convert
@@ -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>) => void;
205
+ const setLabels: (source: DataTypes.StringRecord, 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
@@ -9,7 +9,6 @@ export declare class NodeStorage {
9
9
  source: [string, string][];
10
10
  /**
11
11
  * Constructor
12
- * @param session Is session storage
13
12
  */
14
13
  constructor();
15
14
  /**
@@ -8,7 +8,6 @@ exports.NodeStorage = void 0;
8
8
  class NodeStorage {
9
9
  /**
10
10
  * Constructor
11
- * @param session Is session storage
12
11
  */
13
12
  constructor() {
14
13
  /**
@@ -46,12 +46,12 @@ export interface IStorage {
46
46
  * Get object data
47
47
  * @param key Key name
48
48
  */
49
- getObject<T extends {}>(key: string): T | undefined;
49
+ getObject<T extends object>(key: string): T | undefined;
50
50
  /**
51
51
  * Get persisted object data
52
52
  * @param key Key name
53
53
  */
54
- getPersistedObject<T extends {}>(key: string): T | undefined;
54
+ getPersistedObject<T extends object>(key: string): T | undefined;
55
55
  /**
56
56
  * Set data
57
57
  * @param key Key name
@@ -48,12 +48,12 @@ export declare class WindowStorage implements IStorage {
48
48
  * Get object data
49
49
  * @param key Key name
50
50
  */
51
- getObject<T extends {}>(key: string): T | undefined;
51
+ getObject<T extends object>(key: string): T | undefined;
52
52
  /**
53
53
  * Get persisted object data
54
54
  * @param key Key name
55
55
  */
56
- getPersistedObject<T extends {}>(key: string): T | undefined;
56
+ getPersistedObject<T extends object>(key: string): T | undefined;
57
57
  /**
58
58
  * Set data
59
59
  * @param key Key name
@@ -41,7 +41,7 @@ interface EventOptions {
41
41
  once?: boolean;
42
42
  }
43
43
  declare type EventClassDef = {
44
- [key: string]: {};
44
+ [key: string]: object;
45
45
  };
46
46
  /**
47
47
  * Event class
@@ -1,3 +1,8 @@
1
+ /**
2
+ * Generic object type
3
+ * Narrow case, uses StringRecord
4
+ * Before was wrong with {}, from 4.8 unknown = {} | null | undefined
5
+ */
1
6
  /**
2
7
  * Interface data types
3
8
  */
@@ -123,8 +128,8 @@ export declare namespace DataTypes {
123
128
  /**
124
129
  * Key collection, like { key1: {}, key2: {} }
125
130
  */
126
- type KeyCollection<K extends readonly string[], I extends {}> = {
127
- [index in K[number]]: I;
131
+ type KeyCollection<K extends readonly string[], I extends object> = {
132
+ [P in K[number]]: I;
128
133
  };
129
134
  /**
130
135
  * Enum value type
@@ -181,7 +186,7 @@ export declare namespace DataTypes {
181
186
  /**
182
187
  * Culture definiton
183
188
  */
184
- type CultureDefinition<T extends {} = StringRecord> = Readonly<{
189
+ type CultureDefinition<T extends StringRecord = StringRecord> = Readonly<{
185
190
  /**
186
191
  * Name, like zh-CN
187
192
  */
@@ -278,28 +283,28 @@ export declare namespace DataTypes {
278
283
  * @param key Property name
279
284
  * @returns Value
280
285
  */
281
- function getValue<T extends {}, K extends keyof T | string>(data: T | undefined | null, key: K): K extends keyof T ? T[K] : undefined;
286
+ function getValue<T extends object, K extends keyof T | string>(data: T | undefined | null, key: K): K extends keyof T ? T[K] : undefined;
282
287
  /**
283
288
  * Get object id field value
284
289
  * @param data Data
285
290
  * @param key Property name
286
291
  * @returns Id value
287
292
  */
288
- function getIdValue<T extends {}, K extends Keys<T, string | number>>(data: T, key: K): T[K];
293
+ function getIdValue<T extends object, K extends Keys<T, string | number>>(data: T, key: K): T[K];
289
294
  /**
290
295
  * Get object id field value 1
291
296
  * @param data Data
292
297
  * @param key Property name
293
298
  * @returns Id value
294
299
  */
295
- function getIdValue1<T extends {}, K extends keyof T | string>(data: T | undefined | null, key: K): K extends keyof T ? (T[K] extends number ? number : string) : undefined;
300
+ function getIdValue1<T extends object, K extends keyof T | string>(data: T | undefined | null, key: K): K extends keyof T ? (T[K] extends number ? number : string) : undefined;
296
301
  /**
297
302
  * Get object string field value
298
303
  * @param data Data
299
304
  * @param key Property name
300
305
  * @returns String value
301
306
  */
302
- function getStringValue<T extends {}>(data: T | undefined | null, key: keyof T | string): string | undefined;
307
+ function getStringValue<T extends object>(data: T | undefined | null, key: keyof T | string): string | undefined;
303
308
  /**
304
309
  * Check the type is a basic type or not (type guard)
305
310
  * @param name Type name
@@ -1,3 +1,8 @@
1
+ /**
2
+ * Generic object type
3
+ * Narrow case, uses StringRecord
4
+ * Before was wrong with {}, from 4.8 unknown = {} | null | undefined
5
+ */
1
6
  /**
2
7
  * Interface data types
3
8
  */
@@ -19,7 +19,7 @@ export declare namespace DomUtils {
19
19
  * @param source Source data to match
20
20
  * @param keepFields Fields need to be kept
21
21
  */
22
- function clearFormData(data: IFormData, source?: {}, keepFields?: string[]): IFormData;
22
+ function clearFormData(data: IFormData, source?: object, keepFields?: string[]): IFormData;
23
23
  /**
24
24
  * Cast data as template format
25
25
  * @param source Source data
@@ -35,7 +35,7 @@ export declare namespace DomUtils {
35
35
  * @param keepSource Means even the template does not include the definition, still keep the item
36
36
  * @returns Result
37
37
  */
38
- function dataValueAs<T extends {}>(source: IFormData | {}, templateValue: T, keepSource?: boolean): Partial<T>;
38
+ function dataValueAs<T extends object>(source: IFormData | object, templateValue: T, keepSource?: boolean): Partial<T>;
39
39
  /**
40
40
  * Current detected country
41
41
  */
@@ -67,7 +67,7 @@ export declare namespace DomUtils {
67
67
  * @param items Available cultures
68
68
  * @param culture Detected culture
69
69
  */
70
- const getCulture: <T extends {}>(items: Readonly<{
70
+ const getCulture: <T extends DataTypes.StringRecord>(items: Readonly<{
71
71
  name: string;
72
72
  label: string;
73
73
  resources: T;
@@ -117,5 +117,5 @@ export declare namespace DomUtils {
117
117
  * @param name Element name or first collection item
118
118
  * @param container Container, limits the element range
119
119
  */
120
- function setFocus(name: string | {}, container?: HTMLElement): void;
120
+ function setFocus(name: string | object, container?: HTMLElement): void;
121
121
  }
@@ -30,7 +30,7 @@ export declare namespace StorageUtils {
30
30
  * Get local storage object data
31
31
  * @param key Key name
32
32
  */
33
- function getLocalObject<T extends {}>(key: string): T | undefined;
33
+ function getLocalObject<T extends object>(key: string): T | undefined;
34
34
  /**
35
35
  * Get session storage data
36
36
  * @param key Key name
@@ -46,5 +46,5 @@ export declare namespace StorageUtils {
46
46
  * Get session storage object data
47
47
  * @param key Key name
48
48
  */
49
- function getSessionObject<T extends {}>(key: string): T | undefined;
49
+ function getSessionObject<T extends object>(key: string): T | undefined;
50
50
  }
@@ -53,7 +53,7 @@ export declare namespace Utils {
53
53
  * @param labelField Label field, default is label
54
54
  * @param blankLabel Blank label, default is ---
55
55
  */
56
- function addBlankItem<T extends {}>(options: T[], idField?: string | keyof T, labelField?: unknown, blankLabel?: string): void;
56
+ function addBlankItem<T extends object>(options: T[], idField?: string | keyof T, labelField?: unknown, blankLabel?: string): void;
57
57
  /**
58
58
  * Base64 chars to number
59
59
  * @param base64Chars Base64 chars
@@ -65,7 +65,7 @@ export declare namespace Utils {
65
65
  * @param input Input object
66
66
  * @param fields Fields to correct
67
67
  */
68
- function correctTypes<T extends {}, F extends {
68
+ function correctTypes<T extends object, F extends {
69
69
  [P in keyof T]: DataTypes.BasicNames;
70
70
  }>(input: T, fields: F): void;
71
71
  /**
@@ -95,7 +95,7 @@ export declare namespace Utils {
95
95
  * @param ignoreFields Ignore fields
96
96
  * @returns
97
97
  */
98
- function getDataChanges(input: {}, initData: {}, ignoreFields?: string[]): string[];
98
+ function getDataChanges(input: object, initData: object, ignoreFields?: string[]): string[];
99
99
  /**
100
100
  * Get input function or value result
101
101
  * @param input Input function or value
@@ -150,7 +150,7 @@ export declare namespace Utils {
150
150
  * @param strict Strict level, 0 with ==, 1 === but null equal undefined, 2 ===
151
151
  * @returns Result
152
152
  */
153
- function objectEqual(obj1: {}, obj2: {}, ignoreFields?: string[], strict?: number): boolean;
153
+ function objectEqual(obj1: object, obj2: object, ignoreFields?: string[], strict?: number): boolean;
154
154
  /**
155
155
  * Get two object's unqiue properties
156
156
  * @param obj1 Object 1
@@ -158,7 +158,7 @@ export declare namespace Utils {
158
158
  * @param ignoreFields Ignored fields
159
159
  * @returns Unique properties
160
160
  */
161
- function objectKeys(obj1: {}, obj2: {}, ignoreFields?: string[]): Set<string>;
161
+ function objectKeys(obj1: object, obj2: object, ignoreFields?: string[]): Set<string>;
162
162
  /**
163
163
  * Get the new object's updated fields contrast to the previous object
164
164
  * @param objNew New object
@@ -167,7 +167,7 @@ export declare namespace Utils {
167
167
  * @param strict Strict level, 0 with ==, 1 === but null equal undefined, 2 ===
168
168
  * @returns Updated fields
169
169
  */
170
- function objectUpdated(objNew: {}, objPrev: {}, ignoreFields?: string[], strict?: number): string[];
170
+ function objectUpdated(objNew: object, objPrev: object, ignoreFields?: string[], strict?: number): string[];
171
171
  /**
172
172
  * Parse string (JSON) to specific type, no type conversion
173
173
  * For type conversion, please use DataTypes.convert
@@ -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>) => void;
205
+ const setLabels: (source: DataTypes.StringRecord, 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
@@ -9,7 +9,6 @@ export declare class NodeStorage {
9
9
  source: [string, string][];
10
10
  /**
11
11
  * Constructor
12
- * @param session Is session storage
13
12
  */
14
13
  constructor();
15
14
  /**
@@ -5,7 +5,6 @@
5
5
  export class NodeStorage {
6
6
  /**
7
7
  * Constructor
8
- * @param session Is session storage
9
8
  */
10
9
  constructor() {
11
10
  /**
@@ -46,12 +46,12 @@ export interface IStorage {
46
46
  * Get object data
47
47
  * @param key Key name
48
48
  */
49
- getObject<T extends {}>(key: string): T | undefined;
49
+ getObject<T extends object>(key: string): T | undefined;
50
50
  /**
51
51
  * Get persisted object data
52
52
  * @param key Key name
53
53
  */
54
- getPersistedObject<T extends {}>(key: string): T | undefined;
54
+ getPersistedObject<T extends object>(key: string): T | undefined;
55
55
  /**
56
56
  * Set data
57
57
  * @param key Key name
@@ -48,12 +48,12 @@ export declare class WindowStorage implements IStorage {
48
48
  * Get object data
49
49
  * @param key Key name
50
50
  */
51
- getObject<T extends {}>(key: string): T | undefined;
51
+ getObject<T extends object>(key: string): T | undefined;
52
52
  /**
53
53
  * Get persisted object data
54
54
  * @param key Key name
55
55
  */
56
- getPersistedObject<T extends {}>(key: string): T | undefined;
56
+ getPersistedObject<T extends object>(key: string): T | undefined;
57
57
  /**
58
58
  * Set data
59
59
  * @param key Key name
@@ -41,7 +41,7 @@ interface EventOptions {
41
41
  once?: boolean;
42
42
  }
43
43
  declare type EventClassDef = {
44
- [key: string]: {};
44
+ [key: string]: object;
45
45
  };
46
46
  /**
47
47
  * Event class
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/shared",
3
- "version": "1.1.47",
3
+ "version": "1.1.48",
4
4
  "description": "TypeScript shared utilities and functions",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -55,9 +55,9 @@
55
55
  "homepage": "https://github.com/ETSOO/Shared#readme",
56
56
  "dependencies": {},
57
57
  "devDependencies": {
58
- "@types/jest": "^28.1.7",
59
- "@typescript-eslint/eslint-plugin": "^5.34.0",
60
- "@typescript-eslint/parser": "^5.34.0",
58
+ "@types/jest": "^28.1.8",
59
+ "@typescript-eslint/eslint-plugin": "^5.35.1",
60
+ "@typescript-eslint/parser": "^5.35.1",
61
61
  "eslint": "^8.22.0",
62
62
  "eslint-config-airbnb-base": "^15.0.0",
63
63
  "eslint-plugin-import": "^2.26.0",
package/src/DataTypes.ts CHANGED
@@ -1,3 +1,9 @@
1
+ /**
2
+ * Generic object type
3
+ * Narrow case, uses StringRecord
4
+ * Before was wrong with {}, from 4.8 unknown = {} | null | undefined
5
+ */
6
+
1
7
  /**
2
8
  * Interface data types
3
9
  */
@@ -159,8 +165,8 @@ export namespace DataTypes {
159
165
  /**
160
166
  * Key collection, like { key1: {}, key2: {} }
161
167
  */
162
- export type KeyCollection<K extends readonly string[], I extends {}> = {
163
- [index in K[number]]: I;
168
+ export type KeyCollection<K extends readonly string[], I extends object> = {
169
+ [P in K[number]]: I;
164
170
  };
165
171
 
166
172
  /**
@@ -232,27 +238,28 @@ export namespace DataTypes {
232
238
  /**
233
239
  * Culture definiton
234
240
  */
235
- export type CultureDefinition<T extends {} = StringRecord> = Readonly<{
236
- /**
237
- * Name, like zh-CN
238
- */
239
- name: string;
241
+ export type CultureDefinition<T extends StringRecord = StringRecord> =
242
+ Readonly<{
243
+ /**
244
+ * Name, like zh-CN
245
+ */
246
+ name: string;
240
247
 
241
- /**
242
- * Label for description, like Simplifined Chinese
243
- */
244
- label: string;
248
+ /**
249
+ * Label for description, like Simplifined Chinese
250
+ */
251
+ label: string;
245
252
 
246
- /**
247
- * Resources
248
- */
249
- resources: T;
253
+ /**
254
+ * Resources
255
+ */
256
+ resources: T;
250
257
 
251
- /**
252
- * Compatible names
253
- */
254
- compatibleName?: string[];
255
- }>;
258
+ /**
259
+ * Compatible names
260
+ */
261
+ compatibleName?: string[];
262
+ }>;
256
263
 
257
264
  /**
258
265
  * Dynamic interface with multiple properties
@@ -523,7 +530,7 @@ export namespace DataTypes {
523
530
  * @param key Property name
524
531
  * @returns Value
525
532
  */
526
- export function getValue<T extends {}, K extends keyof T | string>(
533
+ export function getValue<T extends object, K extends keyof T | string>(
527
534
  data: T | undefined | null,
528
535
  key: K
529
536
  ): K extends keyof T ? T[K] : undefined {
@@ -540,7 +547,7 @@ export namespace DataTypes {
540
547
  * @returns Id value
541
548
  */
542
549
  export function getIdValue<
543
- T extends {},
550
+ T extends object,
544
551
  K extends Keys<T, string | number>
545
552
  >(data: T, key: K): T[K] {
546
553
  return data[key];
@@ -552,7 +559,7 @@ export namespace DataTypes {
552
559
  * @param key Property name
553
560
  * @returns Id value
554
561
  */
555
- export function getIdValue1<T extends {}, K extends keyof T | string>(
562
+ export function getIdValue1<T extends object, K extends keyof T | string>(
556
563
  data: T | undefined | null,
557
564
  key: K
558
565
  ): K extends keyof T ? (T[K] extends number ? number : string) : undefined {
@@ -568,7 +575,7 @@ export namespace DataTypes {
568
575
  * @param key Property name
569
576
  * @returns String value
570
577
  */
571
- export function getStringValue<T extends {}>(
578
+ export function getStringValue<T extends object>(
572
579
  data: T | undefined | null,
573
580
  key: keyof T | string
574
581
  ): string | undefined {
package/src/DomUtils.ts CHANGED
@@ -30,7 +30,7 @@ export namespace DomUtils {
30
30
  */
31
31
  export function clearFormData(
32
32
  data: IFormData,
33
- source?: {},
33
+ source?: object,
34
34
  keepFields?: string[]
35
35
  ) {
36
36
  // Unique keys, FormData may have same name keys
@@ -98,9 +98,9 @@ export namespace DomUtils {
98
98
  }
99
99
 
100
100
  function dataAsTraveller(
101
- source: IFormData | {},
102
- data: {},
103
- template: {},
101
+ source: IFormData | object,
102
+ data: object,
103
+ template: object,
104
104
  keepSource: boolean,
105
105
  isValue: boolean
106
106
  ) {
@@ -183,8 +183,8 @@ export namespace DomUtils {
183
183
  * @param keepSource Means even the template does not include the definition, still keep the item
184
184
  * @returns Result
185
185
  */
186
- export function dataValueAs<T extends {}>(
187
- source: IFormData | {},
186
+ export function dataValueAs<T extends object>(
187
+ source: IFormData | object,
188
188
  templateValue: T,
189
189
  keepSource: boolean = false
190
190
  ): Partial<T> {
@@ -312,7 +312,7 @@ export namespace DomUtils {
312
312
  * @param items Available cultures
313
313
  * @param culture Detected culture
314
314
  */
315
- export const getCulture = <T extends {}>(
315
+ export const getCulture = <T extends DataTypes.StringRecord>(
316
316
  items: DataTypes.CultureDefinition<T>[],
317
317
  culture: string
318
318
  ) => {
@@ -453,7 +453,7 @@ export namespace DomUtils {
453
453
  * @param name Element name or first collection item
454
454
  * @param container Container, limits the element range
455
455
  */
456
- export function setFocus(name: string | {}, container?: HTMLElement) {
456
+ export function setFocus(name: string | object, container?: HTMLElement) {
457
457
  const elementName =
458
458
  typeof name === 'string' ? name : Object.keys(name)[0];
459
459
 
@@ -80,7 +80,7 @@ export namespace StorageUtils {
80
80
  * Get local storage object data
81
81
  * @param key Key name
82
82
  */
83
- export function getLocalObject<T extends {}>(key: string) {
83
+ export function getLocalObject<T extends object>(key: string) {
84
84
  // Get storage
85
85
  const data = localStorage.getItem(key);
86
86
  if (data == null) return undefined;
@@ -123,7 +123,7 @@ export namespace StorageUtils {
123
123
  * Get session storage object data
124
124
  * @param key Key name
125
125
  */
126
- export function getSessionObject<T extends {}>(key: string) {
126
+ export function getSessionObject<T extends object>(key: string) {
127
127
  // Get storage
128
128
  const data = sessionStorage.getItem(key);
129
129
  if (data == null) return undefined;
package/src/Utils.ts CHANGED
@@ -119,7 +119,7 @@ export namespace Utils {
119
119
  * @param labelField Label field, default is label
120
120
  * @param blankLabel Blank label, default is ---
121
121
  */
122
- export function addBlankItem<T extends {}>(
122
+ export function addBlankItem<T extends object>(
123
123
  options: T[],
124
124
  idField?: string | keyof T,
125
125
  labelField?: unknown,
@@ -155,7 +155,7 @@ export namespace Utils {
155
155
  * @param fields Fields to correct
156
156
  */
157
157
  export function correctTypes<
158
- T extends {},
158
+ T extends object,
159
159
  F extends { [P in keyof T]: DataTypes.BasicNames }
160
160
  >(input: T, fields: F) {
161
161
  for (const field in fields) {
@@ -218,8 +218,8 @@ export namespace Utils {
218
218
  * @returns
219
219
  */
220
220
  export function getDataChanges(
221
- input: {},
222
- initData: {},
221
+ input: object,
222
+ initData: object,
223
223
  ignoreFields: string[] = ['id']
224
224
  ): string[] {
225
225
  // Changed fields
@@ -375,8 +375,8 @@ export namespace Utils {
375
375
  * @returns Result
376
376
  */
377
377
  export function objectEqual(
378
- obj1: {},
379
- obj2: {},
378
+ obj1: object,
379
+ obj2: object,
380
380
  ignoreFields: string[] = [],
381
381
  strict = 1
382
382
  ) {
@@ -402,8 +402,8 @@ export namespace Utils {
402
402
  * @returns Unique properties
403
403
  */
404
404
  export function objectKeys(
405
- obj1: {},
406
- obj2: {},
405
+ obj1: object,
406
+ obj2: object,
407
407
  ignoreFields: string[] = []
408
408
  ) {
409
409
  // All keys
@@ -424,8 +424,8 @@ export namespace Utils {
424
424
  * @returns Updated fields
425
425
  */
426
426
  export function objectUpdated(
427
- objNew: {},
428
- objPrev: {},
427
+ objNew: object,
428
+ objPrev: object,
429
429
  ignoreFields: string[] = [],
430
430
  strict = 1
431
431
  ) {
@@ -537,7 +537,7 @@ export namespace Utils {
537
537
  * @param reference Key reference dictionary
538
538
  */
539
539
  export const setLabels = (
540
- source: {},
540
+ source: DataTypes.StringRecord,
541
541
  labels: DataTypes.StringRecord,
542
542
  reference?: Readonly<DataTypes.StringDictionary>
543
543
  ) => {
@@ -10,7 +10,6 @@ export class NodeStorage {
10
10
 
11
11
  /**
12
12
  * Constructor
13
- * @param session Is session storage
14
13
  */
15
14
  constructor() {}
16
15
 
@@ -53,13 +53,13 @@ export interface IStorage {
53
53
  * Get object data
54
54
  * @param key Key name
55
55
  */
56
- getObject<T extends {}>(key: string): T | undefined;
56
+ getObject<T extends object>(key: string): T | undefined;
57
57
 
58
58
  /**
59
59
  * Get persisted object data
60
60
  * @param key Key name
61
61
  */
62
- getPersistedObject<T extends {}>(key: string): T | undefined;
62
+ getPersistedObject<T extends object>(key: string): T | undefined;
63
63
 
64
64
  /**
65
65
  * Set data
@@ -105,7 +105,7 @@ export class WindowStorage implements IStorage {
105
105
  * Get object data
106
106
  * @param key Key name
107
107
  */
108
- getObject<T extends {}>(key: string) {
108
+ getObject<T extends object>(key: string) {
109
109
  // Get storage
110
110
  const data = sessionStorage.getItem(key);
111
111
 
@@ -118,7 +118,7 @@ export class WindowStorage implements IStorage {
118
118
  * Get persisted object data
119
119
  * @param key Key name
120
120
  */
121
- getPersistedObject<T extends {}>(key: string) {
121
+ getPersistedObject<T extends object>(key: string) {
122
122
  // Get storage
123
123
  const data = localStorage.getItem(key);
124
124
 
@@ -55,7 +55,7 @@ interface EventOptions {
55
55
  once?: boolean;
56
56
  }
57
57
 
58
- type EventClassDef = { [key: string]: {} };
58
+ type EventClassDef = { [key: string]: object };
59
59
 
60
60
  /**
61
61
  * Event class