@etsoo/shared 1.2.57 → 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 |
@@ -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,
@@ -89,6 +89,7 @@ declare global {
89
89
  * Utilities
90
90
  */
91
91
  export declare namespace Utils {
92
+ const IgnoredProperty: "changedFields";
92
93
  /**
93
94
  * Add blank item to collection
94
95
  * @param options Options
@@ -96,19 +97,19 @@ export declare namespace Utils {
96
97
  * @param labelField Label field, default is label
97
98
  * @param blankLabel Blank label, default is ---
98
99
  */
99
- function addBlankItem<T extends object>(options: T[], idField?: string | keyof T, labelField?: unknown, blankLabel?: string): T[];
100
+ export function addBlankItem<T extends object>(options: T[], idField?: string | keyof T, labelField?: unknown, blankLabel?: string): T[];
100
101
  /**
101
102
  * Base64 chars to number
102
103
  * @param base64Chars Base64 chars
103
104
  * @returns Number
104
105
  */
105
- function charsToNumber(base64Chars: string): number;
106
+ export function charsToNumber(base64Chars: string): number;
106
107
  /**
107
108
  * Correct object's property value type
108
109
  * @param input Input object
109
110
  * @param fields Fields to correct
110
111
  */
111
- function correctTypes<T extends object, F extends {
112
+ export function correctTypes<T extends object, F extends {
112
113
  [P in keyof T]?: DataTypes.BasicNames;
113
114
  }>(input: T, fields: F): void;
114
115
  /**
@@ -117,7 +118,7 @@ export declare namespace Utils {
117
118
  * @param v2 Value 2
118
119
  * @param strict Strict level, 0 with ==, 1 === but null equal undefined, 2 ===
119
120
  */
120
- function equals(v1: unknown, v2: unknown, strict?: number): boolean;
121
+ export function equals(v1: unknown, v2: unknown, strict?: number): boolean;
121
122
  /**
122
123
  * Exclude specific items
123
124
  * @param items Items
@@ -125,7 +126,7 @@ export declare namespace Utils {
125
126
  * @param excludedValues Excluded values
126
127
  * @returns Result
127
128
  */
128
- function exclude<T extends {
129
+ export function exclude<T extends {
129
130
  [P in D]: IdType;
130
131
  }, D extends string = "id">(items: T[], field: D, ...excludedValues: T[D][]): T[];
131
132
  /**
@@ -135,7 +136,7 @@ export declare namespace Utils {
135
136
  * @param excludedValues Excluded values
136
137
  * @returns Result
137
138
  */
138
- function excludeAsync<T extends {
139
+ export function excludeAsync<T extends {
139
140
  [P in D]: IdType;
140
141
  }, D extends string = "id">(items: Promise<T[] | undefined>, field: D, ...excludedValues: T[D][]): Promise<T[] | undefined>;
141
142
  /**
@@ -143,75 +144,75 @@ export declare namespace Utils {
143
144
  * @param input Input string
144
145
  * @param upperCase To upper case or lower case
145
146
  */
146
- function formatInitial(input: string, upperCase?: boolean): string;
147
+ export function formatInitial(input: string, upperCase?: boolean): string;
147
148
  /**
148
149
  * Format string with parameters
149
150
  * @param template Template with {0}, {1}, ...
150
151
  * @param parameters Parameters to fill the template
151
152
  * @returns Result
152
153
  */
153
- function formatString(template: string, ...parameters: string[]): string;
154
+ export function formatString(template: string, ...parameters: string[]): string;
154
155
  /**
155
- * Get data changed fields with input data updated
156
+ * Get data changed fields (ignored changedFields) with input data updated
156
157
  * @param input Input data
157
158
  * @param initData Initial data
158
159
  * @param ignoreFields Ignore fields
159
160
  * @returns
160
161
  */
161
- function getDataChanges<T extends object>(input: T, initData: object, ignoreFields?: string[]): (keyof T & string)[];
162
+ export function getDataChanges<T extends object>(input: T, initData: object, ignoreFields?: string[]): Exclude<keyof T & string, typeof IgnoredProperty>[];
162
163
  /**
163
164
  * Get nested value from object
164
165
  * @param data Data
165
166
  * @param name Field name, support property chain like 'jsonData.logSize'
166
167
  * @returns Result
167
168
  */
168
- function getNestedValue(data: object, name: string): any;
169
+ export function getNestedValue(data: object, name: string): any;
169
170
  /**
170
171
  * Get input function or value result
171
172
  * @param input Input function or value
172
173
  * @param args Arguments
173
174
  * @returns Result
174
175
  */
175
- const getResult: <R, T = R | DataTypes.Func<R>>(input: T, ...args: T extends DataTypes.Func<R> ? Parameters<typeof input> : never | []) => T extends DataTypes.Func<R> ? ReturnType<T> : T;
176
+ export const getResult: <R, T = R | DataTypes.Func<R>>(input: T, ...args: T extends DataTypes.Func<R> ? Parameters<typeof input> : never | []) => T extends DataTypes.Func<R> ? ReturnType<T> : T;
176
177
  /**
177
178
  * Get time zone
178
179
  * @returns Timezone
179
180
  */
180
- const getTimeZone: () => string | undefined;
181
+ export const getTimeZone: () => string | undefined;
181
182
  /**
182
183
  * Is digits string
183
184
  * @param input Input string
184
185
  * @param minLength Minimum length
185
186
  * @returns Result
186
187
  */
187
- const isDigits: (input?: string, minLength?: number) => boolean;
188
+ export const isDigits: (input?: string, minLength?: number) => boolean;
188
189
  /**
189
190
  * Is email string
190
191
  * @param input Input string
191
192
  * @returns Result
192
193
  */
193
- const isEmail: (input?: string) => boolean;
194
+ export const isEmail: (input?: string) => boolean;
194
195
  /**
195
196
  * Join items as a string
196
197
  * @param items Items
197
198
  * @param joinPart Join string
198
199
  */
199
- const joinItems: (items: (string | undefined)[], joinPart?: string) => string;
200
+ export const joinItems: (items: (string | undefined)[], joinPart?: string) => string;
200
201
  /**
201
202
  * Merge class names
202
203
  * @param classNames Class names
203
204
  */
204
- const mergeClasses: (...classNames: (string | undefined)[]) => string;
205
+ export const mergeClasses: (...classNames: (string | undefined)[]) => string;
205
206
  /**
206
207
  * Create a GUID
207
208
  */
208
- function newGUID(): string;
209
+ export function newGUID(): string;
209
210
  /**
210
211
  * Number to base64 chars
211
212
  * @param num Input number
212
213
  * @returns Result
213
214
  */
214
- function numberToChars(num: number): string;
215
+ export function numberToChars(num: number): string;
215
216
  /**
216
217
  * Test two objects are equal or not
217
218
  * @param obj1 Object 1
@@ -220,7 +221,7 @@ export declare namespace Utils {
220
221
  * @param strict Strict level, 0 with ==, 1 === but null equal undefined, 2 ===
221
222
  * @returns Result
222
223
  */
223
- function objectEqual(obj1: object, obj2: object, ignoreFields?: string[], strict?: number): boolean;
224
+ export function objectEqual(obj1: object, obj2: object, ignoreFields?: string[], strict?: number): boolean;
224
225
  /**
225
226
  * Get two object's unqiue properties
226
227
  * @param obj1 Object 1
@@ -228,7 +229,7 @@ export declare namespace Utils {
228
229
  * @param ignoreFields Ignored fields
229
230
  * @returns Unique properties
230
231
  */
231
- function objectKeys(obj1: object, obj2: object, ignoreFields?: string[]): Set<string>;
232
+ export function objectKeys(obj1: object, obj2: object, ignoreFields?: string[]): Set<string>;
232
233
  /**
233
234
  * Get the new object's updated fields contrast to the previous object
234
235
  * @param objNew New object
@@ -237,21 +238,21 @@ export declare namespace Utils {
237
238
  * @param strict Strict level, 0 with ==, 1 === but null equal undefined, 2 ===
238
239
  * @returns Updated fields
239
240
  */
240
- function objectUpdated(objNew: object, objPrev: object, ignoreFields?: string[], strict?: number): string[];
241
+ export function objectUpdated(objNew: object, objPrev: object, ignoreFields?: string[], strict?: number): string[];
241
242
  /**
242
243
  * Try to parse JSON input to array
243
244
  * @param input JSON input
244
245
  * @param checkValue Type check value
245
246
  * @returns Result
246
247
  */
247
- function parseJsonArray<T>(input: string, checkValue?: T): T[] | undefined;
248
+ export function parseJsonArray<T>(input: string, checkValue?: T): T[] | undefined;
248
249
  /**
249
250
  * Parse string (JSON) to specific type, no type conversion
250
251
  * For type conversion, please use DataTypes.convert
251
252
  * @param input Input string
252
253
  * @returns Parsed value
253
254
  */
254
- function parseString<T>(input: string | undefined | null): T | undefined;
255
+ export function parseString<T>(input: string | undefined | null): T | undefined;
255
256
  /**
256
257
  * Parse string (JSON) to specific type, no type conversion
257
258
  * For type conversion, please use DataTypes.convert
@@ -259,38 +260,38 @@ export declare namespace Utils {
259
260
  * @param defaultValue Default value
260
261
  * @returns Parsed value
261
262
  */
262
- function parseString<T>(input: string | undefined | null, defaultValue: T): T;
263
+ export function parseString<T>(input: string | undefined | null, defaultValue: T): T;
263
264
  /**
264
265
  * Remove empty values (null, undefined, '') from the input object
265
266
  * @param input Input object
266
267
  */
267
- function removeEmptyValues(input: object): void;
268
+ export function removeEmptyValues(input: object): void;
268
269
  /**
269
270
  * Remove non letters
270
271
  * @param input Input string
271
272
  * @returns Result
272
273
  */
273
- const removeNonLetters: (input?: string) => string | undefined;
274
+ export const removeNonLetters: (input?: string) => string | undefined;
274
275
  /**
275
276
  * Replace null or empty with default value
276
277
  * @param input Input string
277
278
  * @param defaultValue Default value
278
279
  * @returns Result
279
280
  */
280
- const replaceNullOrEmpty: (input: string | null | undefined, defaultValue: string) => string;
281
+ export const replaceNullOrEmpty: (input: string | null | undefined, defaultValue: string) => string;
281
282
  /**
282
283
  * Set source with new labels
283
284
  * @param source Source
284
285
  * @param labels Labels
285
286
  * @param reference Key reference dictionary
286
287
  */
287
- const setLabels: (source: DataTypes.StringRecord, labels: DataTypes.StringRecord, reference?: Readonly<DataTypes.StringDictionary>) => void;
288
+ export const setLabels: (source: DataTypes.StringRecord, labels: DataTypes.StringRecord, reference?: Readonly<DataTypes.StringDictionary>) => void;
288
289
  /**
289
290
  * Snake name to works, 'snake_name' to 'Snake Name'
290
291
  * @param name Name text
291
292
  * @param firstOnly Only convert the first word to upper case
292
293
  */
293
- const snakeNameToWord: (name: string, firstOnly?: boolean) => string;
294
+ export const snakeNameToWord: (name: string, firstOnly?: boolean) => string;
294
295
  /**
295
296
  * Set nested value to object
296
297
  * @param data Data
@@ -298,19 +299,19 @@ export declare namespace Utils {
298
299
  * @param value Value
299
300
  * @param keepNull Keep null value or not
300
301
  */
301
- function setNestedValue(data: object, name: string, value: unknown, keepNull?: boolean): void;
302
+ export function setNestedValue(data: object, name: string, value: unknown, keepNull?: boolean): void;
302
303
  /**
303
304
  * Parse path similar with node.js path.parse
304
305
  * @param path Input path
305
306
  */
306
- const parsePath: (path: string) => ParsedPath;
307
+ export const parsePath: (path: string) => ParsedPath;
307
308
  /**
308
309
  * Sort array by favored values
309
310
  * @param items Items
310
311
  * @param favored Favored values
311
312
  * @returns Sorted array
312
313
  */
313
- const sortByFavor: <T>(items: T[], favored: T[]) => T[];
314
+ export const sortByFavor: <T>(items: T[], favored: T[]) => T[];
314
315
  /**
315
316
  * Sort array by favored field values
316
317
  * @param items Items
@@ -318,26 +319,27 @@ export declare namespace Utils {
318
319
  * @param favored Favored field values
319
320
  * @returns Sorted array
320
321
  */
321
- const sortByFieldFavor: <T, F extends keyof T>(items: T[], field: F, favored: T[F][]) => T[];
322
+ export const sortByFieldFavor: <T, F extends keyof T>(items: T[], field: F, favored: T[F][]) => T[];
322
323
  /**
323
324
  * Trim chars
324
325
  * @param input Input string
325
326
  * @param chars Trim chars
326
327
  * @returns Result
327
328
  */
328
- const trim: (input: string, ...chars: string[]) => string;
329
+ export const trim: (input: string, ...chars: string[]) => string;
329
330
  /**
330
331
  * Trim end chars
331
332
  * @param input Input string
332
333
  * @param chars Trim chars
333
334
  * @returns Result
334
335
  */
335
- const trimEnd: (input: string, ...chars: string[]) => string;
336
+ export const trimEnd: (input: string, ...chars: string[]) => string;
336
337
  /**
337
338
  * Trim start chars
338
339
  * @param input Input string
339
340
  * @param chars Trim chars
340
341
  * @returns Result
341
342
  */
342
- const trimStart: (input: string, ...chars: string[]) => string;
343
+ export const trimStart: (input: string, ...chars: string[]) => string;
344
+ export {};
343
345
  }
package/lib/cjs/Utils.js CHANGED
@@ -133,6 +133,7 @@ String.prototype.removeNonLetters = function () {
133
133
  */
134
134
  var Utils;
135
135
  (function (Utils) {
136
+ const IgnoredProperty = "changedFields";
136
137
  /**
137
138
  * Add blank item to collection
138
139
  * @param options Options
@@ -253,7 +254,7 @@ var Utils;
253
254
  }
254
255
  Utils.formatString = formatString;
255
256
  /**
256
- * Get data changed fields with input data updated
257
+ * Get data changed fields (ignored changedFields) with input data updated
257
258
  * @param input Input data
258
259
  * @param initData Initial data
259
260
  * @param ignoreFields Ignore fields
@@ -264,7 +265,7 @@ var Utils;
264
265
  const changes = [];
265
266
  Object.entries(input).forEach(([key, value]) => {
266
267
  // Ignore fields, no process
267
- if (ignoreFields.includes(key))
268
+ if (key === IgnoredProperty || ignoreFields.includes(key))
268
269
  return;
269
270
  // Compare with init value
270
271
  const initValue = Reflect.get(initData, key);
@@ -89,6 +89,7 @@ declare global {
89
89
  * Utilities
90
90
  */
91
91
  export declare namespace Utils {
92
+ const IgnoredProperty: "changedFields";
92
93
  /**
93
94
  * Add blank item to collection
94
95
  * @param options Options
@@ -96,19 +97,19 @@ export declare namespace Utils {
96
97
  * @param labelField Label field, default is label
97
98
  * @param blankLabel Blank label, default is ---
98
99
  */
99
- function addBlankItem<T extends object>(options: T[], idField?: string | keyof T, labelField?: unknown, blankLabel?: string): T[];
100
+ export function addBlankItem<T extends object>(options: T[], idField?: string | keyof T, labelField?: unknown, blankLabel?: string): T[];
100
101
  /**
101
102
  * Base64 chars to number
102
103
  * @param base64Chars Base64 chars
103
104
  * @returns Number
104
105
  */
105
- function charsToNumber(base64Chars: string): number;
106
+ export function charsToNumber(base64Chars: string): number;
106
107
  /**
107
108
  * Correct object's property value type
108
109
  * @param input Input object
109
110
  * @param fields Fields to correct
110
111
  */
111
- function correctTypes<T extends object, F extends {
112
+ export function correctTypes<T extends object, F extends {
112
113
  [P in keyof T]?: DataTypes.BasicNames;
113
114
  }>(input: T, fields: F): void;
114
115
  /**
@@ -117,7 +118,7 @@ export declare namespace Utils {
117
118
  * @param v2 Value 2
118
119
  * @param strict Strict level, 0 with ==, 1 === but null equal undefined, 2 ===
119
120
  */
120
- function equals(v1: unknown, v2: unknown, strict?: number): boolean;
121
+ export function equals(v1: unknown, v2: unknown, strict?: number): boolean;
121
122
  /**
122
123
  * Exclude specific items
123
124
  * @param items Items
@@ -125,7 +126,7 @@ export declare namespace Utils {
125
126
  * @param excludedValues Excluded values
126
127
  * @returns Result
127
128
  */
128
- function exclude<T extends {
129
+ export function exclude<T extends {
129
130
  [P in D]: IdType;
130
131
  }, D extends string = "id">(items: T[], field: D, ...excludedValues: T[D][]): T[];
131
132
  /**
@@ -135,7 +136,7 @@ export declare namespace Utils {
135
136
  * @param excludedValues Excluded values
136
137
  * @returns Result
137
138
  */
138
- function excludeAsync<T extends {
139
+ export function excludeAsync<T extends {
139
140
  [P in D]: IdType;
140
141
  }, D extends string = "id">(items: Promise<T[] | undefined>, field: D, ...excludedValues: T[D][]): Promise<T[] | undefined>;
141
142
  /**
@@ -143,75 +144,75 @@ export declare namespace Utils {
143
144
  * @param input Input string
144
145
  * @param upperCase To upper case or lower case
145
146
  */
146
- function formatInitial(input: string, upperCase?: boolean): string;
147
+ export function formatInitial(input: string, upperCase?: boolean): string;
147
148
  /**
148
149
  * Format string with parameters
149
150
  * @param template Template with {0}, {1}, ...
150
151
  * @param parameters Parameters to fill the template
151
152
  * @returns Result
152
153
  */
153
- function formatString(template: string, ...parameters: string[]): string;
154
+ export function formatString(template: string, ...parameters: string[]): string;
154
155
  /**
155
- * Get data changed fields with input data updated
156
+ * Get data changed fields (ignored changedFields) with input data updated
156
157
  * @param input Input data
157
158
  * @param initData Initial data
158
159
  * @param ignoreFields Ignore fields
159
160
  * @returns
160
161
  */
161
- function getDataChanges<T extends object>(input: T, initData: object, ignoreFields?: string[]): (keyof T & string)[];
162
+ export function getDataChanges<T extends object>(input: T, initData: object, ignoreFields?: string[]): Exclude<keyof T & string, typeof IgnoredProperty>[];
162
163
  /**
163
164
  * Get nested value from object
164
165
  * @param data Data
165
166
  * @param name Field name, support property chain like 'jsonData.logSize'
166
167
  * @returns Result
167
168
  */
168
- function getNestedValue(data: object, name: string): any;
169
+ export function getNestedValue(data: object, name: string): any;
169
170
  /**
170
171
  * Get input function or value result
171
172
  * @param input Input function or value
172
173
  * @param args Arguments
173
174
  * @returns Result
174
175
  */
175
- const getResult: <R, T = R | DataTypes.Func<R>>(input: T, ...args: T extends DataTypes.Func<R> ? Parameters<typeof input> : never | []) => T extends DataTypes.Func<R> ? ReturnType<T> : T;
176
+ export const getResult: <R, T = R | DataTypes.Func<R>>(input: T, ...args: T extends DataTypes.Func<R> ? Parameters<typeof input> : never | []) => T extends DataTypes.Func<R> ? ReturnType<T> : T;
176
177
  /**
177
178
  * Get time zone
178
179
  * @returns Timezone
179
180
  */
180
- const getTimeZone: () => string | undefined;
181
+ export const getTimeZone: () => string | undefined;
181
182
  /**
182
183
  * Is digits string
183
184
  * @param input Input string
184
185
  * @param minLength Minimum length
185
186
  * @returns Result
186
187
  */
187
- const isDigits: (input?: string, minLength?: number) => boolean;
188
+ export const isDigits: (input?: string, minLength?: number) => boolean;
188
189
  /**
189
190
  * Is email string
190
191
  * @param input Input string
191
192
  * @returns Result
192
193
  */
193
- const isEmail: (input?: string) => boolean;
194
+ export const isEmail: (input?: string) => boolean;
194
195
  /**
195
196
  * Join items as a string
196
197
  * @param items Items
197
198
  * @param joinPart Join string
198
199
  */
199
- const joinItems: (items: (string | undefined)[], joinPart?: string) => string;
200
+ export const joinItems: (items: (string | undefined)[], joinPart?: string) => string;
200
201
  /**
201
202
  * Merge class names
202
203
  * @param classNames Class names
203
204
  */
204
- const mergeClasses: (...classNames: (string | undefined)[]) => string;
205
+ export const mergeClasses: (...classNames: (string | undefined)[]) => string;
205
206
  /**
206
207
  * Create a GUID
207
208
  */
208
- function newGUID(): string;
209
+ export function newGUID(): string;
209
210
  /**
210
211
  * Number to base64 chars
211
212
  * @param num Input number
212
213
  * @returns Result
213
214
  */
214
- function numberToChars(num: number): string;
215
+ export function numberToChars(num: number): string;
215
216
  /**
216
217
  * Test two objects are equal or not
217
218
  * @param obj1 Object 1
@@ -220,7 +221,7 @@ export declare namespace Utils {
220
221
  * @param strict Strict level, 0 with ==, 1 === but null equal undefined, 2 ===
221
222
  * @returns Result
222
223
  */
223
- function objectEqual(obj1: object, obj2: object, ignoreFields?: string[], strict?: number): boolean;
224
+ export function objectEqual(obj1: object, obj2: object, ignoreFields?: string[], strict?: number): boolean;
224
225
  /**
225
226
  * Get two object's unqiue properties
226
227
  * @param obj1 Object 1
@@ -228,7 +229,7 @@ export declare namespace Utils {
228
229
  * @param ignoreFields Ignored fields
229
230
  * @returns Unique properties
230
231
  */
231
- function objectKeys(obj1: object, obj2: object, ignoreFields?: string[]): Set<string>;
232
+ export function objectKeys(obj1: object, obj2: object, ignoreFields?: string[]): Set<string>;
232
233
  /**
233
234
  * Get the new object's updated fields contrast to the previous object
234
235
  * @param objNew New object
@@ -237,21 +238,21 @@ export declare namespace Utils {
237
238
  * @param strict Strict level, 0 with ==, 1 === but null equal undefined, 2 ===
238
239
  * @returns Updated fields
239
240
  */
240
- function objectUpdated(objNew: object, objPrev: object, ignoreFields?: string[], strict?: number): string[];
241
+ export function objectUpdated(objNew: object, objPrev: object, ignoreFields?: string[], strict?: number): string[];
241
242
  /**
242
243
  * Try to parse JSON input to array
243
244
  * @param input JSON input
244
245
  * @param checkValue Type check value
245
246
  * @returns Result
246
247
  */
247
- function parseJsonArray<T>(input: string, checkValue?: T): T[] | undefined;
248
+ export function parseJsonArray<T>(input: string, checkValue?: T): T[] | undefined;
248
249
  /**
249
250
  * Parse string (JSON) to specific type, no type conversion
250
251
  * For type conversion, please use DataTypes.convert
251
252
  * @param input Input string
252
253
  * @returns Parsed value
253
254
  */
254
- function parseString<T>(input: string | undefined | null): T | undefined;
255
+ export function parseString<T>(input: string | undefined | null): T | undefined;
255
256
  /**
256
257
  * Parse string (JSON) to specific type, no type conversion
257
258
  * For type conversion, please use DataTypes.convert
@@ -259,38 +260,38 @@ export declare namespace Utils {
259
260
  * @param defaultValue Default value
260
261
  * @returns Parsed value
261
262
  */
262
- function parseString<T>(input: string | undefined | null, defaultValue: T): T;
263
+ export function parseString<T>(input: string | undefined | null, defaultValue: T): T;
263
264
  /**
264
265
  * Remove empty values (null, undefined, '') from the input object
265
266
  * @param input Input object
266
267
  */
267
- function removeEmptyValues(input: object): void;
268
+ export function removeEmptyValues(input: object): void;
268
269
  /**
269
270
  * Remove non letters
270
271
  * @param input Input string
271
272
  * @returns Result
272
273
  */
273
- const removeNonLetters: (input?: string) => string | undefined;
274
+ export const removeNonLetters: (input?: string) => string | undefined;
274
275
  /**
275
276
  * Replace null or empty with default value
276
277
  * @param input Input string
277
278
  * @param defaultValue Default value
278
279
  * @returns Result
279
280
  */
280
- const replaceNullOrEmpty: (input: string | null | undefined, defaultValue: string) => string;
281
+ export const replaceNullOrEmpty: (input: string | null | undefined, defaultValue: string) => string;
281
282
  /**
282
283
  * Set source with new labels
283
284
  * @param source Source
284
285
  * @param labels Labels
285
286
  * @param reference Key reference dictionary
286
287
  */
287
- const setLabels: (source: DataTypes.StringRecord, labels: DataTypes.StringRecord, reference?: Readonly<DataTypes.StringDictionary>) => void;
288
+ export const setLabels: (source: DataTypes.StringRecord, labels: DataTypes.StringRecord, reference?: Readonly<DataTypes.StringDictionary>) => void;
288
289
  /**
289
290
  * Snake name to works, 'snake_name' to 'Snake Name'
290
291
  * @param name Name text
291
292
  * @param firstOnly Only convert the first word to upper case
292
293
  */
293
- const snakeNameToWord: (name: string, firstOnly?: boolean) => string;
294
+ export const snakeNameToWord: (name: string, firstOnly?: boolean) => string;
294
295
  /**
295
296
  * Set nested value to object
296
297
  * @param data Data
@@ -298,19 +299,19 @@ export declare namespace Utils {
298
299
  * @param value Value
299
300
  * @param keepNull Keep null value or not
300
301
  */
301
- function setNestedValue(data: object, name: string, value: unknown, keepNull?: boolean): void;
302
+ export function setNestedValue(data: object, name: string, value: unknown, keepNull?: boolean): void;
302
303
  /**
303
304
  * Parse path similar with node.js path.parse
304
305
  * @param path Input path
305
306
  */
306
- const parsePath: (path: string) => ParsedPath;
307
+ export const parsePath: (path: string) => ParsedPath;
307
308
  /**
308
309
  * Sort array by favored values
309
310
  * @param items Items
310
311
  * @param favored Favored values
311
312
  * @returns Sorted array
312
313
  */
313
- const sortByFavor: <T>(items: T[], favored: T[]) => T[];
314
+ export const sortByFavor: <T>(items: T[], favored: T[]) => T[];
314
315
  /**
315
316
  * Sort array by favored field values
316
317
  * @param items Items
@@ -318,26 +319,27 @@ export declare namespace Utils {
318
319
  * @param favored Favored field values
319
320
  * @returns Sorted array
320
321
  */
321
- const sortByFieldFavor: <T, F extends keyof T>(items: T[], field: F, favored: T[F][]) => T[];
322
+ export const sortByFieldFavor: <T, F extends keyof T>(items: T[], field: F, favored: T[F][]) => T[];
322
323
  /**
323
324
  * Trim chars
324
325
  * @param input Input string
325
326
  * @param chars Trim chars
326
327
  * @returns Result
327
328
  */
328
- const trim: (input: string, ...chars: string[]) => string;
329
+ export const trim: (input: string, ...chars: string[]) => string;
329
330
  /**
330
331
  * Trim end chars
331
332
  * @param input Input string
332
333
  * @param chars Trim chars
333
334
  * @returns Result
334
335
  */
335
- const trimEnd: (input: string, ...chars: string[]) => string;
336
+ export const trimEnd: (input: string, ...chars: string[]) => string;
336
337
  /**
337
338
  * Trim start chars
338
339
  * @param input Input string
339
340
  * @param chars Trim chars
340
341
  * @returns Result
341
342
  */
342
- const trimStart: (input: string, ...chars: string[]) => string;
343
+ export const trimStart: (input: string, ...chars: string[]) => string;
344
+ export {};
343
345
  }
package/lib/mjs/Utils.js CHANGED
@@ -127,6 +127,7 @@ String.prototype.removeNonLetters = function () {
127
127
  */
128
128
  export var Utils;
129
129
  (function (Utils) {
130
+ const IgnoredProperty = "changedFields";
130
131
  /**
131
132
  * Add blank item to collection
132
133
  * @param options Options
@@ -247,7 +248,7 @@ export var Utils;
247
248
  }
248
249
  Utils.formatString = formatString;
249
250
  /**
250
- * Get data changed fields with input data updated
251
+ * Get data changed fields (ignored changedFields) with input data updated
251
252
  * @param input Input data
252
253
  * @param initData Initial data
253
254
  * @param ignoreFields Ignore fields
@@ -258,7 +259,7 @@ export var Utils;
258
259
  const changes = [];
259
260
  Object.entries(input).forEach(([key, value]) => {
260
261
  // Ignore fields, no process
261
- if (ignoreFields.includes(key))
262
+ if (key === IgnoredProperty || ignoreFields.includes(key))
262
263
  return;
263
264
  // Compare with init value
264
265
  const initValue = Reflect.get(initData, key);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/shared",
3
- "version": "1.2.57",
3
+ "version": "1.2.58",
4
4
  "description": "TypeScript shared utilities and functions",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
package/src/Utils.ts CHANGED
@@ -261,6 +261,8 @@ String.prototype.removeNonLetters = function (this: string) {
261
261
  * Utilities
262
262
  */
263
263
  export namespace Utils {
264
+ const IgnoredProperty = "changedFields" as const;
265
+
264
266
  /**
265
267
  * Add blank item to collection
266
268
  * @param options Options
@@ -397,7 +399,7 @@ export namespace Utils {
397
399
  }
398
400
 
399
401
  /**
400
- * Get data changed fields with input data updated
402
+ * Get data changed fields (ignored changedFields) with input data updated
401
403
  * @param input Input data
402
404
  * @param initData Initial data
403
405
  * @param ignoreFields Ignore fields
@@ -407,13 +409,13 @@ export namespace Utils {
407
409
  input: T,
408
410
  initData: object,
409
411
  ignoreFields: string[] = ["id"]
410
- ): (keyof T & string)[] {
412
+ ): Exclude<keyof T & string, typeof IgnoredProperty>[] {
411
413
  // Changed fields
412
- const changes: (keyof T & string)[] = [];
414
+ const changes: Exclude<keyof T & string, typeof IgnoredProperty>[] = [];
413
415
 
414
416
  Object.entries(input).forEach(([key, value]) => {
415
417
  // Ignore fields, no process
416
- if (ignoreFields.includes(key)) return;
418
+ if (key === IgnoredProperty || ignoreFields.includes(key)) return;
417
419
 
418
420
  // Compare with init value
419
421
  const initValue = Reflect.get(initData, key);
package/tsconfig.cjs.json CHANGED
@@ -10,7 +10,7 @@
10
10
  "declaration": true,
11
11
  "strict": true,
12
12
  "esModuleInterop": true,
13
- "skipLibCheck": false,
13
+ "skipLibCheck": true,
14
14
  "forceConsistentCasingInFileNames": true,
15
15
  "lib": ["dom", "dom.iterable", "ESNext"]
16
16
  },
package/tsconfig.json CHANGED
@@ -10,7 +10,7 @@
10
10
  "declaration": true,
11
11
  "strict": true,
12
12
  "esModuleInterop": true,
13
- "skipLibCheck": false,
13
+ "skipLibCheck": true,
14
14
  "forceConsistentCasingInFileNames": true,
15
15
  "lib": ["dom", "dom.iterable", "esnext"]
16
16
  },