@etsoo/shared 1.2.56 → 1.2.58

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
@@ -1,4 +1,5 @@
1
1
  # Shared
2
+
2
3
  **TypeScript shared utilities and functions.**
3
4
 
4
5
  ## Installing
@@ -16,303 +17,318 @@ $ yarn add @etsoo/shared
16
17
  ```
17
18
 
18
19
  ## ActionResult / IActionResult, IdActionResult, MsgActionResult, IdMsgActionResult, DynamicActionResult
19
- |Name|Description|
20
- |---:|---|
21
- |static create|Create a result from error|
22
- |data|Result data|
23
- |detail|Details|
24
- |errors|Result errors|
25
- |field|Related field|
26
- |ok|Success or failure|
27
- |status|Status code|
28
- |title|Title|
29
- |traceId|Trace id|
30
- |type|Type|
20
+
21
+ | Name | Description |
22
+ | ------------: | -------------------------- |
23
+ | static create | Create a result from error |
24
+ | data | Result data |
25
+ | detail | Details |
26
+ | errors | Result errors |
27
+ | field | Related field |
28
+ | ok | Success or failure |
29
+ | status | Status code |
30
+ | title | Title |
31
+ | traceId | Trace id |
32
+ | type | Type |
31
33
 
32
34
  ## storage
35
+
33
36
  Storage interface and browser storage implementation
34
37
 
35
38
  ## ContentDisposition
39
+
36
40
  Content disposition of HTTP
37
41
 
38
- |Name|Description|
39
- |---:|---|
40
- |static parse|Parse header value|
41
- |Methods||
42
- |format|Format to standard output|
42
+ | Name | Description |
43
+ | -----------: | ------------------------- |
44
+ | static parse | Parse header value |
45
+ | Methods | |
46
+ | format | Format to standard output |
43
47
 
44
48
  ## DataError
49
+
45
50
  Error with custom data
46
51
 
47
52
  ## EColor
53
+
48
54
  Etsoo implmented Color
49
55
 
50
- |Name|Description|
51
- |---:|---|
52
- |static getColors|Get HEX or RGB colors|
53
- |static getEColors|Get EColors|
54
- |static parse|Parse HTML color to EColor|
55
- |Methods||
56
- |clone|Clone color with adjustments|
57
- |getContrastRatio|Get contrast ratio, a value between 0 and 1|
58
- |getDeltaValue|Get Delta value (perceptible by human eyes)|
59
- |getLuminance|Get luminance|
60
- |toHEXColor|To HEX color string|
61
- |toLabValue|To Lab value|
62
- |toRGBColor|To RGB color string|
56
+ | Name | Description |
57
+ | ----------------: | ------------------------------------------- |
58
+ | static getColors | Get HEX or RGB colors |
59
+ | static getEColors | Get EColors |
60
+ | static parse | Parse HTML color to EColor |
61
+ | Methods | |
62
+ | clone | Clone color with adjustments |
63
+ | getContrastRatio | Get contrast ratio, a value between 0 and 1 |
64
+ | getDeltaValue | Get Delta value (perceptible by human eyes) |
65
+ | getLuminance | Get luminance |
66
+ | toHEXColor | To HEX color string |
67
+ | toLabValue | To Lab value |
68
+ | toRGBColor | To RGB color string |
63
69
 
64
70
  ## EventClass
71
+
65
72
  Etsoo implmented abstract Event Class
66
73
 
67
- |Name|Description|
68
- |---:|---|
69
- |hasEvents|Has specific type and callback events|
70
- |off|Remove specific type and callback event|
71
- |on|Add event listener|
72
- |trigger|Trigger event|
74
+ | Name | Description |
75
+ | --------: | --------------------------------------- |
76
+ | hasEvents | Has specific type and callback events |
77
+ | off | Remove specific type and callback event |
78
+ | on | Add event listener |
79
+ | trigger | Trigger event |
73
80
 
74
81
  ## Keyboard
82
+
75
83
  Keyboard keys and codes
76
84
 
77
- |Name|Description|
78
- |---:|---|
79
- |Keys|KeyboardEvent.key constants|
80
- |Codes|KeyboardEvent.code constants|
85
+ | Name | Description |
86
+ | ----: | ---------------------------- |
87
+ | Keys | KeyboardEvent.key constants |
88
+ | Codes | KeyboardEvent.code constants |
81
89
 
82
90
  |isTypingContent|Is typing content or press command key|
83
91
 
84
92
  ## EHistory
93
+
85
94
  ETSOO Extended abstract history class
86
95
 
87
- |Name|Description|
88
- |---:|---|
89
- |index|Current index|
90
- |length|States length|
91
- |state|Current state|
92
- |states|States|
93
- |Methods||
94
- |back|Back to the previous state|
95
- |clear|Clear all states but keep event listeners|
96
- |forward|Forward to the next state|
97
- |getStatus|Get [undo, redo] status|
98
- |go|Go to the specific state|
99
- |pushState|Adds an entry to the history stack|
100
- |replaceState|Modifies the current history entry|
96
+ | Name | Description |
97
+ | -----------: | ----------------------------------------- |
98
+ | index | Current index |
99
+ | length | States length |
100
+ | state | Current state |
101
+ | states | States |
102
+ | Methods | |
103
+ | back | Back to the previous state |
104
+ | clear | Clear all states but keep event listeners |
105
+ | forward | Forward to the next state |
106
+ | getStatus | Get [undo, redo] status |
107
+ | go | Go to the specific state |
108
+ | pushState | Adds an entry to the history stack |
109
+ | replaceState | Modifies the current history entry |
101
110
 
102
111
  ## ArrayUtils
112
+
103
113
  Array related utilities
104
114
 
105
- |Name|Description|
106
- |---:|---|
107
- |differences|Array 1 items do not exist in Array 2 or reverse match|
108
- |max|Get max number item or number item property|
109
- |maxItem|Get max field value item|
110
- |min|Get min number item or number item property|
111
- |minItem|Get min field value item|
112
- |remove|Remove items by value or condition|
113
- |sum|Sum number items or number item properties|
114
- |toUnique|Make all items are unique|
115
+ | Name | Description |
116
+ | ----------: | ------------------------------------------------------ |
117
+ | differences | Array 1 items do not exist in Array 2 or reverse match |
118
+ | max | Get max number item or number item property |
119
+ | maxItem | Get max field value item |
120
+ | min | Get min number item or number item property |
121
+ | minItem | Get min field value item |
122
+ | remove | Remove items by value or condition |
123
+ | sum | Sum number items or number item properties |
124
+ | toUnique | Make all items are unique |
115
125
 
116
126
  ## DataTypes
117
- Data type definitions and type safe functions. ListItemType, ListItemType1 and ListItemType2 are sugar types.
118
127
 
119
- |Name|Description|
120
- |---:|---|
121
- |DataType|Data type enum|
122
- |AddAndEditType|Add and edit data type|
123
- |AddOrEditType|Add or edit conditional type|
124
- |addUrlParam|Add parameter to URL|
125
- |addUrlParams|Add parameters to URL|
126
- |Basic|Basic types, includes number, bigint, Date, boolean, string|
127
- |BasicArray|Basic type name array|
128
- |BasicConditional|Conditional type based on BasicNames|
129
- |BasicNames|Basic type and basic type array names array|
130
- |BasicTemplate|Basic type template|
131
- |BasicTemplateType|Basic template type|
132
- |CombinedEnum|Combined type enum|
133
- |CultureDefinition|Culture definition|
134
- |DI|Dynamic interface with multiple properties|
135
- |DIS|Dynamic interface with single property|
136
- |EnumBase|Enum base type|
137
- |EnumValue|Enum value type|
138
- |ExtendedEnum|Extended type enum|
139
- |Func<R>|Function type, R is return type|
140
- |HAlign|Horizontal align|
141
- |HAlignEnum|Horizontal align enum|
142
- |IdDefaultType|Id default type|
143
- |IdType|Number and string combination id type|
144
- |IdItem|Item with id or id generator|
145
- |IdLabelItem|Item with id and label|
146
- |IdLabelType|Item with id and label dynamic type|
147
- |IdNameItem|Item with id and name|
148
- |IdTitleItem|Item with id and title|
149
- |KeyCollection|Key collection, like { key1: {}, key2: {} }|
150
- |Keys|Get specific type keys|
151
- |LabelDefaultType|Label default type|
152
- |MConstructor|Mixins constructor|
153
- |ObjType|Generic object type|
154
- |Optional|Make properties optional|
155
- |PlacementEnum|Placement enum|
156
- |Placement|Placement type|
157
- |RequireAtLeastOne|Require at least one property of the keys|
158
- |Simple|Basic or basic array type|
159
- |SimpleEnum|Simple type enum|
160
- |SimpleNames|Simple type names|
161
- |SimpleObject|Simple object, string key, simple type and null value Record|
162
- |StringDictionary|String key, string value Record|
163
- |StringRecord|String key, unknown value Record|
164
- |TitleDefaultType|Title default type|
165
- |VAlign|Vertical align|
166
- |VAlignEnum|Vertical align enum|
167
- |Methods||
168
- |convert|Convert value to target type|
169
- |convertByType|Convert by type name like 'string'|
170
- |convertSimple|Convert value to target enum type|
171
- |getBasicName|Get basic type name from Enum type|
172
- |getBasicNameByValue|Get value's basic type name|
173
- |getEnumByKey|Get enum item from key|
174
- |getEnumByValue|Get enum item from value|
175
- |getEnumKey|Get enum string literal type value|
176
- |getEnumKeys|Get Enum keys|
177
- |getListItemLabel|Get ListType2 item label|
178
- |getIdValue|Get object id field value|
179
- |getIdValue1|Get object id field value 1|
180
- |getObjectItemLabel|Get object item label|
181
- |getResult|Get input function or value result|
182
- |getStringValue|Get object string field value|
183
- |getValue|Get object field value|
184
- |isBasicName|Check the type is a basic type or not (type guard)|
185
- |isSimpleObject|Is the target a simple object, all values are simple type (Type guard)|
186
- |isSimpleType|Is the input value simple type, include null and undefined|
187
- |jsonReplacer|JSON.stringify replacer with full path|
128
+ Data type definitions and type safe functions. ListItemType, ListItemType1 and ListItemType2 are sugar types.
188
129
 
130
+ | Name | Description |
131
+ | ------------------: | ---------------------------------------------------------------------- |
132
+ | DataType | Data type enum |
133
+ | AddAndEditType | Add and edit data type |
134
+ | AddOrEditType | Add or edit conditional type |
135
+ | addUrlParam | Add parameter to URL |
136
+ | addUrlParams | Add parameters to URL |
137
+ | Basic | Basic types, includes number, bigint, Date, boolean, string |
138
+ | BasicArray | Basic type name array |
139
+ | BasicConditional | Conditional type based on BasicNames |
140
+ | BasicNames | Basic type and basic type array names array |
141
+ | BasicTemplate | Basic type template |
142
+ | BasicTemplateType | Basic template type |
143
+ | CombinedEnum | Combined type enum |
144
+ | CultureDefinition | Culture definition |
145
+ | DI | Dynamic interface with multiple properties |
146
+ | DIS | Dynamic interface with single property |
147
+ | EnumBase | Enum base type |
148
+ | EnumValue | Enum value type |
149
+ | ExtendedEnum | Extended type enum |
150
+ | Func<R> | Function type, R is return type |
151
+ | HAlign | Horizontal align |
152
+ | HAlignEnum | Horizontal align enum |
153
+ | IdDefaultType | Id default type |
154
+ | IdType | Number and string combination id type |
155
+ | IdItem | Item with id or id generator |
156
+ | IdLabelItem | Item with id and label |
157
+ | IdLabelType | Item with id and label dynamic type |
158
+ | IdNameItem | Item with id and name |
159
+ | IdTitleItem | Item with id and title |
160
+ | KeyCollection | Key collection, like { key1: {}, key2: {} } |
161
+ | Keys | Get specific type keys |
162
+ | LabelDefaultType | Label default type |
163
+ | MConstructor | Mixins constructor |
164
+ | ObjType | Generic object type |
165
+ | Optional | Make properties optional |
166
+ | PlacementEnum | Placement enum |
167
+ | Placement | Placement type |
168
+ | RequireAtLeastOne | Require at least one property of the keys |
169
+ | Simple | Basic or basic array type |
170
+ | SimpleEnum | Simple type enum |
171
+ | SimpleNames | Simple type names |
172
+ | SimpleObject | Simple object, string key, simple type and null value Record |
173
+ | StringDictionary | String key, string value Record |
174
+ | StringRecord | String key, unknown value Record |
175
+ | TitleDefaultType | Title default type |
176
+ | VAlign | Vertical align |
177
+ | VAlignEnum | Vertical align enum |
178
+ | Methods | |
179
+ | convert | Convert value to target type |
180
+ | convertByType | Convert by type name like 'string' |
181
+ | convertSimple | Convert value to target enum type |
182
+ | getBasicName | Get basic type name from Enum type |
183
+ | getBasicNameByValue | Get value's basic type name |
184
+ | getEnumByKey | Get enum item from key |
185
+ | getEnumByValue | Get enum item from value |
186
+ | getEnumKey | Get enum string literal type value |
187
+ | getEnumKeys | Get Enum keys |
188
+ | getListItemLabel | Get ListType2 item label |
189
+ | getIdValue | Get object id field value |
190
+ | getIdValue1 | Get object id field value 1 |
191
+ | getObjectItemLabel | Get object item label |
192
+ | getResult | Get input function or value result |
193
+ | getStringValue | Get object string field value |
194
+ | getValue | Get object field value |
195
+ | isBasicName | Check the type is a basic type or not (type guard) |
196
+ | isSimpleObject | Is the target a simple object, all values are simple type (Type guard) |
197
+ | isSimpleType | Is the input value simple type, include null and undefined |
198
+ | jsonReplacer | JSON.stringify replacer with full path |
189
199
 
190
200
  ## DateUtils
201
+
191
202
  Dates related utilities
192
203
 
193
- |Name|Description|
194
- |---:|---|
195
- |DayFormat|YYYY-MM-DD|
196
- |MinuteFormat|YYYY-MM-DD hh:mm|
197
- |SecondFormat|YYYY-MM-DD hh:mm:ss|
198
- |Methods||
199
- |getDays|Get month's days|
200
- |forma|Format dates|
201
- |formatForInput|Format to 'yyyy-MM-dd' or 'yyyy-MM-ddThh:mm:ss, especially used for date input min/max property|
202
- |jsonParser|JSON parser|
203
- |parse|Parse string to date|
204
- |sameDay|Two dates are in the same day|
205
- |sameMonth|Two dates are in the same month|
206
- |substract|Date extended method, substract a date|
204
+ | Name | Description |
205
+ | -------------: | ----------------------------------------------------------------------------------------------- |
206
+ | DayFormat | YYYY-MM-DD |
207
+ | MinuteFormat | YYYY-MM-DD hh:mm |
208
+ | SecondFormat | YYYY-MM-DD hh:mm:ss |
209
+ | Methods | |
210
+ | getDays | Get month's days |
211
+ | forma | Format dates |
212
+ | formatForInput | Format to 'yyyy-MM-dd' or 'yyyy-MM-ddThh:mm:ss, especially used for date input min/max property |
213
+ | jsonParser | JSON parser |
214
+ | parse | Parse string to date |
215
+ | sameDay | Two dates are in the same day |
216
+ | sameMonth | Two dates are in the same month |
217
+ | substract | Date extended method, substract a date |
207
218
 
208
219
  ## DomUtils
220
+
209
221
  DOM/window related utilities
210
222
 
211
- |Name|Description|
212
- |---:|---|
213
- |clearFormData|Clear form data|
214
- |CultureMatch|Culture match case Enum|
215
- |dataAs|Cast data as template format|
216
- |detectedCountry|Current detected country|
217
- |detectedCulture|Current detected culture|
218
- |dimensionEqual|Check two rectangles equality|
219
- |downloadFile|Download file from API fetch response body|
220
- |en|Get English resources definition|
221
- |fileToDataURL|File to data URL|
222
- |formDataToObject|Form data to object|
223
- |getCulture|Get the available culture definition|
224
- |getDataChanges|Get data changed fields with input data updated|
225
- |getInputValue|Get input value depending on its type|
226
- |getLocationKey|Get an unique key combined with current URL|
227
- |headersToObject|Convert headers to object|
228
- |isFormData|Is IFormData type guard|
229
- |isJSONContentType|Is JSON content type|
230
- |isWechatClient|Is Wechat client|
231
- |mergeFormData|Merge form data to primary one|
232
- |mergeURLSearchParams|Merge URL search parameters|
233
- |parseUserAgent|parseUserAgent|
234
- |setFocus|Set HTML element focus by name|
235
- |setupLogging|Setup frontend logging|
236
- |verifyPermission|Verify file system permission|
237
- |zhHans|Get simplified Chinese resources definition|
238
- |zhHant|Get traditional Chinese resources definition|
223
+ | Name | Description |
224
+ | -------------------: | ----------------------------------------------------------------------- |
225
+ | clearFormData | Clear form data |
226
+ | CultureMatch | Culture match case Enum |
227
+ | dataAs | Cast data as template format |
228
+ | detectedCountry | Current detected country |
229
+ | detectedCulture | Current detected culture |
230
+ | dimensionEqual | Check two rectangles equality |
231
+ | downloadFile | Download file from API fetch response body |
232
+ | en | Get English resources definition |
233
+ | fileToDataURL | File to data URL |
234
+ | formDataToObject | Form data to object |
235
+ | getCulture | Get the available culture definition |
236
+ | getDataChanges | Get data changed fields (ignored changedFields) with input data updated |
237
+ | getInputValue | Get input value depending on its type |
238
+ | getLocationKey | Get an unique key combined with current URL |
239
+ | headersToObject | Convert headers to object |
240
+ | isFormData | Is IFormData type guard |
241
+ | isJSONContentType | Is JSON content type |
242
+ | isWechatClient | Is Wechat client |
243
+ | mergeFormData | Merge form data to primary one |
244
+ | mergeURLSearchParams | Merge URL search parameters |
245
+ | parseUserAgent | parseUserAgent |
246
+ | setFocus | Set HTML element focus by name |
247
+ | setupLogging | Setup frontend logging |
248
+ | verifyPermission | Verify file system permission |
249
+ | zhHans | Get simplified Chinese resources definition |
250
+ | zhHant | Get traditional Chinese resources definition |
239
251
 
240
252
  ## ExtendUtils
253
+
241
254
  Extend current class/object functioning
242
255
 
243
- |Name|Description|
244
- |---:|---|
245
- |applyMixins|Apply mixins to current class|
246
- |delayedExecutor|Create delayed executor|
247
- |intervalFor|Repeat interval for callback|
248
- |promiseHandler|Promise handler to catch error|
249
- |sleep|Delay promise|
250
- |waitFor|Wait for condition meets and execute callback|
256
+ | Name | Description |
257
+ | --------------: | --------------------------------------------- |
258
+ | applyMixins | Apply mixins to current class |
259
+ | delayedExecutor | Create delayed executor |
260
+ | intervalFor | Repeat interval for callback |
261
+ | promiseHandler | Promise handler to catch error |
262
+ | sleep | Delay promise |
263
+ | waitFor | Wait for condition meets and execute callback |
251
264
 
252
265
  ## NumberUtils
266
+
253
267
  Numbers related utilities
254
268
 
255
- |Name|Description|
256
- |---:|---|
257
- |format|Format number|
258
- |formatFileSize|Format file size|
259
- |formatMoney|Format money number|
260
- |getCurrencySymbol|Get currency symbol or name from ISO code|
261
- |parse|Parse to number, with or without default value|
262
- |toExact|To the exact precision number avoiding precision lost|
269
+ | Name | Description |
270
+ | ----------------: | ----------------------------------------------------- |
271
+ | format | Format number |
272
+ | formatFileSize | Format file size |
273
+ | formatMoney | Format money number |
274
+ | getCurrencySymbol | Get currency symbol or name from ISO code |
275
+ | parse | Parse to number, with or without default value |
276
+ | toExact | To the exact precision number avoiding precision lost |
263
277
 
264
278
  ## StorageUtils
279
+
265
280
  Storage related utilities
266
281
 
267
- |Name|Description|
268
- |---:|---|
269
- |setLocalData|Set local storage data|
270
- |setSessionData|Set session storage data|
271
- |getLocalData|Get local storage data|
272
- |getLocalObject|Get local storage object data|
273
- |getSessionData|Get session storage data|
274
- |getSessionObject|Get session storage object data|
282
+ | Name | Description |
283
+ | ---------------: | ------------------------------- |
284
+ | setLocalData | Set local storage data |
285
+ | setSessionData | Set session storage data |
286
+ | getLocalData | Get local storage data |
287
+ | getLocalObject | Get local storage object data |
288
+ | getSessionData | Get session storage data |
289
+ | getSessionObject | Get session storage object data |
275
290
 
276
291
  ## Utils
292
+
277
293
  String and other related utilities
278
294
 
279
- |Name|Description|
280
- |---:|---|
281
- |addBlankItem|Add blank item to collection|
282
- |charsToNumber|Base64 chars to number|
283
- |containChinese|Check the input string contains Chinese character or not|
284
- |correctTypes|Correct object's property value type|
285
- |equals|Two values equal|
286
- |exclude|Exclude specific items|
287
- |excludeAsync|Async exclude specific items|
288
- |formatInitial|Format inital character to lower case or upper case|
289
- |formatString|Format string with parameters|
290
- |getDataChanges|Get data changed fields with input data updated|
291
- |getNestedValue|Get nested value from object|
292
- |getTimeZone|Get time zone|
293
- |hideData|Hide data|
294
- |hideEmail|Hide email data|
295
- |isDigits|Is digits string|
296
- |isEmail|Is email string|
297
- |joinItems|Join items as a string|
298
- |mergeFormData|Merge form data to primary one|
299
- |mergeClasses|Merge class names|
300
- |newGUID|Create a GUID|
301
- |numberToChars|Number to base64 chars|
302
- |objectEqual|Test two objects are equal or not|
303
- |objectKeys|Get two object's unqiue properties|
304
- |objectUpdated|Get the new object's updated fields contrast to the previous object|
305
- |parseJsonArray|Try to parse JSON input to array|
306
- |parsePath|Parse path similar with node.js path.parse|
307
- |parseString|Parse string (JSON) to specific type|
308
- |removeEmptyValues|Remove empty values (null, undefined, '') from the input object|
309
- |removeNonLetters|Remove non letters (0-9, a-z, A-Z)|
310
- |replaceNullOrEmpty|Replace null or empty with default value|
311
- |setLabels|Set source with new labels|
312
- |setNestedValue|Set nested value to object|
313
- |snakeNameToWord|Snake name to works, 'snake_name' to 'Snake Name'|
314
- |sortByFavor|Sort array by favored values|
315
- |sortByFieldFavor|Sort array by favored field values|
316
- |trim|Trim chars|
317
- |trimEnd|Trim end chars|
318
- |trimStart|Trim start chars|
295
+ | Name | Description |
296
+ | -----------------: | ------------------------------------------------------------------- |
297
+ | addBlankItem | Add blank item to collection |
298
+ | charsToNumber | Base64 chars to number |
299
+ | containChinese | Check the input string contains Chinese character or not |
300
+ | correctTypes | Correct object's property value type |
301
+ | equals | Two values equal |
302
+ | exclude | Exclude specific items |
303
+ | excludeAsync | Async exclude specific items |
304
+ | formatInitial | Format inital character to lower case or upper case |
305
+ | formatString | Format string with parameters |
306
+ | getDataChanges | Get data changed fields with input data updated |
307
+ | getNestedValue | Get nested value from object |
308
+ | getTimeZone | Get time zone |
309
+ | hideData | Hide data |
310
+ | hideEmail | Hide email data |
311
+ | isDigits | Is digits string |
312
+ | isEmail | Is email string |
313
+ | joinItems | Join items as a string |
314
+ | mergeFormData | Merge form data to primary one |
315
+ | mergeClasses | Merge class names |
316
+ | newGUID | Create a GUID |
317
+ | numberToChars | Number to base64 chars |
318
+ | objectEqual | Test two objects are equal or not |
319
+ | objectKeys | Get two object's unqiue properties |
320
+ | objectUpdated | Get the new object's updated fields contrast to the previous object |
321
+ | parseJsonArray | Try to parse JSON input to array |
322
+ | parsePath | Parse path similar with node.js path.parse |
323
+ | parseString | Parse string (JSON) to specific type |
324
+ | removeEmptyValues | Remove empty values (null, undefined, '') from the input object |
325
+ | removeNonLetters | Remove non letters (0-9, a-z, A-Z) |
326
+ | replaceNullOrEmpty | Replace null or empty with default value |
327
+ | setLabels | Set source with new labels |
328
+ | setNestedValue | Set nested value to object |
329
+ | snakeNameToWord | Snake name to works, 'snake_name' to 'Snake Name' |
330
+ | sortByFavor | Sort array by favored values |
331
+ | sortByFieldFavor | Sort array by favored field values |
332
+ | trim | Trim chars |
333
+ | trimEnd | Trim end chars |
334
+ | trimStart | Trim start chars |
@@ -217,6 +217,26 @@ test("Tests for AddAndEditType", () => {
217
217
  expect(data2.name).toBe(data3.name);
218
218
  });
219
219
 
220
+ test("Tests for AddOrEditType", () => {
221
+ type Entity = {
222
+ id: number;
223
+ name: string;
224
+ age?: number;
225
+ };
226
+ type AddEntity = DataTypes.AddOrEditType<Entity, false>;
227
+ type EditEntity = DataTypes.AddOrEditType<Entity, true>;
228
+
229
+ const data1: AddEntity = { id: 1, name: "hello" };
230
+ const data2: AddEntity = { id: undefined, name: "hello" };
231
+ const data3: AddEntity = { name: "hello" };
232
+
233
+ const data4: EditEntity = { id: 1, name: "hello", changedFields: ["name"] };
234
+
235
+ expect(data1.name).toBe(data2.name);
236
+ expect(data2.name).toBe(data3.name);
237
+ expect(data3.name).toBe(data4.name);
238
+ });
239
+
220
240
  test("Tests for BasicTemplate", () => {
221
241
  const template: DataTypes.BasicTemplate = {
222
242
  id: "number",
@@ -114,7 +114,8 @@ test("Tests for getDataChanges", () => {
114
114
  value: undefined,
115
115
  date: new Date("2023/03/18"),
116
116
  ids: [1, 2],
117
- data: { d1: 1, d2: false, d3: 1.2, d4: "Hello" }
117
+ data: { d1: 1, d2: false, d3: 1.2, d4: "Hello" },
118
+ changedFields: ["gender", "brand", "date"]
118
119
  };
119
120
  const initData = {
120
121
  id: 1,
@@ -4,7 +4,7 @@
4
4
  "module": "ES2022",
5
5
  "moduleResolution": "bundler",
6
6
  "allowJs": false,
7
- "skipLibCheck": true,
7
+ "skipLibCheck": false,
8
8
  "esModuleInterop": true,
9
9
  "allowSyntheticDefaultImports": true,
10
10
  "strict": true,
@@ -147,7 +147,7 @@ export declare namespace DataTypes {
147
147
  }, D extends string = "id"> = (Omit<T, D> & {
148
148
  [key in D]?: undefined | never;
149
149
  }) | (Partial<T> & Readonly<Pick<T, D>> & {
150
- changedFields?: string[];
150
+ changedFields?: (keyof T & string)[];
151
151
  });
152
152
  /**
153
153
  * Add or edit conditional type
@@ -158,7 +158,7 @@ export declare namespace DataTypes {
158
158
  }, // Entity modal
159
159
  E extends boolean, // Editing or not
160
160
  D extends string = "id"> = E extends false ? Optional<T, D> : Partial<T> & Readonly<Pick<T, D>> & {
161
- changedFields?: string[];
161
+ changedFields?: (keyof T & string)[];
162
162
  };
163
163
  /**
164
164
  * Key collection, like { key1: {}, key2: {} }