utils-lib-js 2.0.14 → 2.0.16
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.en.md +108 -83
- package/README.md +25 -0
- package/dist/bundle/base.d.ts +2 -0
- package/dist/bundle/index.d.ts +1 -0
- package/dist/bundle/index.js +5 -5
- package/dist/bundle/object.d.ts +1 -0
- package/dist/cjs/base.d.ts +2 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +12 -0
- package/dist/cjs/object.d.ts +1 -0
- package/dist/esm/base.d.ts +2 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +11 -1
- package/dist/esm/object.d.ts +1 -0
- package/dist/umd/base.d.ts +2 -0
- package/dist/umd/index.d.ts +1 -0
- package/dist/umd/index.js +12 -0
- package/dist/umd/object.d.ts +1 -0
- package/package.json +50 -50
package/README.en.md
CHANGED
|
@@ -62,9 +62,9 @@ With reference to https://gitee.com/DieHunter/utils-lib-js/blob/master/src/types
|
|
|
62
62
|
|
|
63
63
|
Generates random integers within the specified range.
|
|
64
64
|
|
|
65
|
-
-
|
|
66
|
-
-
|
|
67
|
-
-
|
|
65
|
+
- `min` : indicates the minimum value (including).
|
|
66
|
+
- `max` : indicates the maximum value (inclusive).
|
|
67
|
+
- `bool` : Indicates whether the maximum value is contained. The default value is false.
|
|
68
68
|
|
|
69
69
|
```javascript
|
|
70
70
|
const randomNumber = randomNum(1, 10);
|
|
@@ -75,7 +75,7 @@ console.log(randomNumber); // Generates a random integer between 1 and 10
|
|
|
75
75
|
|
|
76
76
|
Parses URL query parameters into objects.
|
|
77
77
|
|
|
78
|
-
-
|
|
78
|
+
- `url` : indicates the URL containing the query parameter.
|
|
79
79
|
|
|
80
80
|
```javascript
|
|
81
81
|
const url = "https://example.com/path?param1=value1¶m2=value2";
|
|
@@ -88,8 +88,8 @@ console.log(params);
|
|
|
88
88
|
|
|
89
89
|
Converts the object to a URL query parameter and concatenates it with the original URL.
|
|
90
90
|
|
|
91
|
-
-
|
|
92
|
-
-
|
|
91
|
+
- `url` : indicates the original URL.
|
|
92
|
+
- `query` : object containing query parameters.
|
|
93
93
|
|
|
94
94
|
```javascript
|
|
95
95
|
const url = "https://example.com/path";
|
|
@@ -103,7 +103,7 @@ console.log(newUrl);
|
|
|
103
103
|
|
|
104
104
|
Get the type of data.
|
|
105
105
|
|
|
106
|
-
-
|
|
106
|
+
- `data` : indicates the data to be checked.
|
|
107
107
|
|
|
108
108
|
```javascript
|
|
109
109
|
const dataType = getType("Hello, World!");
|
|
@@ -114,8 +114,8 @@ console.log(dataType); // Output: string
|
|
|
114
114
|
|
|
115
115
|
Check whether the data type is in the whitelist.
|
|
116
116
|
|
|
117
|
-
-
|
|
118
|
-
-
|
|
117
|
+
- `data` : indicates the data to be checked.
|
|
118
|
+
- `whiteList` : indicates the list of allowed data types.
|
|
119
119
|
|
|
120
120
|
```javascript
|
|
121
121
|
const data = 42;
|
|
@@ -124,15 +124,28 @@ const isTypeAllowed = getTypeByList(data, allowedTypes);
|
|
|
124
124
|
console.log(isTypeAllowed); // Output: true
|
|
125
125
|
```
|
|
126
126
|
|
|
127
|
+
##### 6. `toKebabCase(camelCase: string, separator: string = "-"): string`
|
|
128
|
+
|
|
129
|
+
The hump name is converted to a hyphenated name
|
|
130
|
+
|
|
131
|
+
- `camelCase` : hump type variable
|
|
132
|
+
- `separator` : indicates the separator
|
|
133
|
+
|
|
134
|
+
```javascript
|
|
135
|
+
const camelCase = "fontSize";
|
|
136
|
+
const kebabCase = toKebabCase(camelCase);
|
|
137
|
+
console.log(kebabCase); // Output: font-size
|
|
138
|
+
```
|
|
139
|
+
|
|
127
140
|
#### object module
|
|
128
141
|
|
|
129
142
|
##### 1. `getValue(object: object, key: string, defaultValue: any = ''): any`
|
|
130
143
|
|
|
131
144
|
Gets the value of the specified path in the object.
|
|
132
145
|
|
|
133
|
-
-
|
|
134
|
-
-
|
|
135
|
-
-
|
|
146
|
+
- `object` : indicates the target object.
|
|
147
|
+
- `key` : the path to the value to be obtained.
|
|
148
|
+
- `defaultValue` : Default value, returned if the path does not exist.
|
|
136
149
|
|
|
137
150
|
```javascript
|
|
138
151
|
const obj = { a: { b: { c: 42 } } };
|
|
@@ -144,9 +157,9 @@ console.log(value); // Output: 42
|
|
|
144
157
|
|
|
145
158
|
Sets the value of the specified path in the object.
|
|
146
159
|
|
|
147
|
-
-
|
|
148
|
-
-
|
|
149
|
-
-
|
|
160
|
+
- `object` : indicates the target object.
|
|
161
|
+
- `key` : path to the value to be set.
|
|
162
|
+
- `value` : indicates the value to be set.
|
|
150
163
|
|
|
151
164
|
```javascript
|
|
152
165
|
const obj = { a: { b: { c: 42 } } };
|
|
@@ -158,9 +171,9 @@ console.log(obj); // Output: {a: {b: {c: 42, d: 'new value'}}}
|
|
|
158
171
|
|
|
159
172
|
Mixes the properties of the source object into the target object.
|
|
160
173
|
|
|
161
|
-
-
|
|
162
|
-
-
|
|
163
|
-
-
|
|
174
|
+
- `target` : indicates the target object.
|
|
175
|
+
- `source` : indicates the source object.
|
|
176
|
+
- `overwrite` : Whether to overwrite an existing attribute. The default is' false '.
|
|
164
177
|
|
|
165
178
|
```javascript
|
|
166
179
|
const target = { a: 1 };
|
|
@@ -173,7 +186,7 @@ console.log(result); // Output: {a: 1, b: 2}
|
|
|
173
186
|
|
|
174
187
|
Inverts the key-value pair of an enumeration object.
|
|
175
188
|
|
|
176
|
-
-
|
|
189
|
+
- `target` : enumeration object to be reversed.
|
|
177
190
|
|
|
178
191
|
```javascript
|
|
179
192
|
const enumObj = { key1: "value1", key2: "value2" };
|
|
@@ -185,8 +198,8 @@ console.log(invertedEnum); // Output: {value1: 'key1', value2: 'key2'}
|
|
|
185
198
|
|
|
186
199
|
Check whether the value is of a non-object type.
|
|
187
200
|
|
|
188
|
-
-
|
|
189
|
-
-
|
|
201
|
+
- `source` : indicates the value to be checked.
|
|
202
|
+
- `type` : indicates the data type.
|
|
190
203
|
|
|
191
204
|
```javascript
|
|
192
205
|
const result = isNotObject(42, "number");
|
|
@@ -197,7 +210,7 @@ console.log(result); // Output: false
|
|
|
197
210
|
|
|
198
211
|
Deep clone object.
|
|
199
212
|
|
|
200
|
-
-
|
|
213
|
+
- `target` : indicates the object to be cloned.
|
|
201
214
|
|
|
202
215
|
```javascript
|
|
203
216
|
const obj = { a: { b: { c: 42 } } };
|
|
@@ -209,8 +222,8 @@ console.log(clonedObj); // Output: {a: {b: {c: 42}}}
|
|
|
209
222
|
|
|
210
223
|
Creates an object of a specific type based on its type.
|
|
211
224
|
|
|
212
|
-
-
|
|
213
|
-
-
|
|
225
|
+
- `type` : indicates the type of the object to be created.
|
|
226
|
+
- `source` : initializes the data of the object.
|
|
214
227
|
|
|
215
228
|
```javascript
|
|
216
229
|
const array = createObjectVariable("array", [1, 2, 3]);
|
|
@@ -221,7 +234,7 @@ console.log(array); // Output: [1, 2, 3]
|
|
|
221
234
|
|
|
222
235
|
Create objects using a prototype chain.
|
|
223
236
|
|
|
224
|
-
-
|
|
237
|
+
- `source` : prototype object.
|
|
225
238
|
|
|
226
239
|
```javascript
|
|
227
240
|
const protoObj = { a: 1 };
|
|
@@ -233,8 +246,8 @@ console.log(newObj.a); // Output: 1
|
|
|
233
246
|
|
|
234
247
|
Inherit the prototype chain.
|
|
235
248
|
|
|
236
|
-
-
|
|
237
|
-
-
|
|
249
|
+
- `source` : prototype chain of the parent object.
|
|
250
|
+
- `target` : constructor of the child object.
|
|
238
251
|
|
|
239
252
|
```javascript
|
|
240
253
|
function Parent() {}
|
|
@@ -252,9 +265,9 @@ childInstance.method(); // Output: Hello from parent
|
|
|
252
265
|
|
|
253
266
|
Gets a singleton instance of a class.
|
|
254
267
|
|
|
255
|
-
-
|
|
256
|
-
-
|
|
257
|
-
-
|
|
268
|
+
- `classProto` : The prototype chain of the class.
|
|
269
|
+
- `overwrite` : Whether to overwrite an existing instance. The default is' false '.
|
|
270
|
+
- `params` : arguments to the class constructor.
|
|
258
271
|
|
|
259
272
|
```javascript
|
|
260
273
|
class Singleton {
|
|
@@ -273,7 +286,7 @@ console.log(instance1 === instance2); // Output: false
|
|
|
273
286
|
|
|
274
287
|
Add a decorator to the class.
|
|
275
288
|
|
|
276
|
-
-
|
|
289
|
+
- `params` : properties and methods to add.
|
|
277
290
|
|
|
278
291
|
```javascript
|
|
279
292
|
@classDecorator({
|
|
@@ -291,7 +304,7 @@ instance.additionalMethod(); // Output: Additional method
|
|
|
291
304
|
|
|
292
305
|
Converts a JSON string to an object.
|
|
293
306
|
|
|
294
|
-
-
|
|
307
|
+
- `target` : JSON string to be converted.
|
|
295
308
|
|
|
296
309
|
```javascript
|
|
297
310
|
const jsonString = '{"key": "value"}';
|
|
@@ -303,7 +316,7 @@ console.log(jsonObject); // Output: {key: 'value'}
|
|
|
303
316
|
|
|
304
317
|
Converts the object to a JSON string.
|
|
305
318
|
|
|
306
|
-
-
|
|
319
|
+
- `target` : indicates the object to be converted.
|
|
307
320
|
|
|
308
321
|
```javascript
|
|
309
322
|
const obj = { key: "value" };
|
|
@@ -315,7 +328,7 @@ console.log(jsonString); // Output: '{"key":"value"}'
|
|
|
315
328
|
|
|
316
329
|
Check whether it is a browser window.
|
|
317
330
|
|
|
318
|
-
-
|
|
331
|
+
- `win` : indicates the object to be checked.
|
|
319
332
|
|
|
320
333
|
```javascript
|
|
321
334
|
const isBrowserWindow = isWindow(window);
|
|
@@ -326,7 +339,7 @@ console.log(isBrowserWindow); // Output: true
|
|
|
326
339
|
|
|
327
340
|
Creates an object whose prototype is empty.
|
|
328
341
|
|
|
329
|
-
-
|
|
342
|
+
- `init` : initializes the object.
|
|
330
343
|
|
|
331
344
|
```javascript
|
|
332
345
|
const o = emptyObject({ name: "hunter" });
|
|
@@ -334,26 +347,38 @@ const o2 = { name: "hunter" };
|
|
|
334
347
|
console.log(o.__proto__, o2.__proto__); // Output: undefined, [Object: null prototype] {}
|
|
335
348
|
```
|
|
336
349
|
|
|
350
|
+
##### 15. `isEmptyObject(object: IObject<unknown>): boolean`
|
|
351
|
+
|
|
352
|
+
Determines if the object is empty
|
|
353
|
+
|
|
354
|
+
- `object` : the target object.
|
|
355
|
+
|
|
356
|
+
```javascript
|
|
357
|
+
const o = isEmptyObject({name: "a u"});
|
|
358
|
+
const o2 = isEmptyObject({});
|
|
359
|
+
console.log(o, o2); // Output: false true
|
|
360
|
+
```
|
|
361
|
+
|
|
337
362
|
#### array module
|
|
338
363
|
|
|
339
364
|
##### 1. `arrayRandom(arr: any[]): any[]`
|
|
340
365
|
|
|
341
366
|
Randomly sort the array.
|
|
342
367
|
|
|
343
|
-
-
|
|
368
|
+
- `arr` : array to sort.
|
|
344
369
|
|
|
345
370
|
```javascript
|
|
346
371
|
const originalArray = [1, 2, 3, 4, 5];
|
|
347
372
|
const randomizedArray = arrayRandom(originalArray);
|
|
348
373
|
console.log(randomizedArray);
|
|
349
374
|
// Output: a randomly sorted array
|
|
350
|
-
|
|
375
|
+
````
|
|
351
376
|
|
|
352
377
|
##### 2. `arrayUniq(arr: any[]): any[]`
|
|
353
378
|
|
|
354
379
|
Removes duplicate elements from the array.
|
|
355
380
|
|
|
356
|
-
-
|
|
381
|
+
- `arr` : array to process.
|
|
357
382
|
|
|
358
383
|
```javascript
|
|
359
384
|
const arrayWithDuplicates = [1, 2, 2, 3, 4, 4, 5];
|
|
@@ -366,8 +391,8 @@ console.log(uniqueArray);
|
|
|
366
391
|
|
|
367
392
|
Reduces the dimension of multiple nested arrays.
|
|
368
393
|
|
|
369
|
-
-
|
|
370
|
-
-
|
|
394
|
+
- `arr` : array to be reduced.
|
|
395
|
+
- `result` : The array used to store the result. The default is an empty array.
|
|
371
396
|
|
|
372
397
|
```javascript
|
|
373
398
|
const nestedArray = [1, [2, [3, [4]], 5]];
|
|
@@ -382,8 +407,8 @@ console.log(demotedArray);
|
|
|
382
407
|
|
|
383
408
|
Limits how often a function is called within a specified period of time.
|
|
384
409
|
|
|
385
|
-
-
|
|
386
|
-
-
|
|
410
|
+
- `fn` : function to be executed.
|
|
411
|
+
- `time` : indicates the time interval (milliseconds).
|
|
387
412
|
|
|
388
413
|
```javascript
|
|
389
414
|
const throttledFunction = throttle(
|
|
@@ -397,8 +422,8 @@ throttledFunction(); // This command is executed only after 1 second
|
|
|
397
422
|
|
|
398
423
|
Limits the continuous invocation of a function for a specified period of time.
|
|
399
424
|
|
|
400
|
-
-
|
|
401
|
-
-
|
|
425
|
+
- `fn` : function to be executed.
|
|
426
|
+
- `time` : indicates the time interval (milliseconds).
|
|
402
427
|
|
|
403
428
|
```javascript
|
|
404
429
|
const debouncedFunction = debounce(
|
|
@@ -412,7 +437,7 @@ debouncedFunction(); // Called multiple times within 1 second, only the last tim
|
|
|
412
437
|
|
|
413
438
|
Create a flat Promise delay object that can be set to time out after a certain amount of time.
|
|
414
439
|
|
|
415
|
-
-
|
|
440
|
+
- `timer` : indicates the timeout period (milliseconds). The default value is 0.
|
|
416
441
|
|
|
417
442
|
```javascript
|
|
418
443
|
const deferFn = () => {
|
|
@@ -432,7 +457,7 @@ delayFn().catch(console.error); // Timeout output
|
|
|
432
457
|
|
|
433
458
|
Catches an Error for an asynchronous operation and returns' [Error, null] 'or' [null, result] '.
|
|
434
459
|
|
|
435
|
-
-
|
|
460
|
+
- `defer` : The Promise object for the asynchronous operation.
|
|
436
461
|
|
|
437
462
|
```javascript
|
|
438
463
|
const asyncOperation = new Promise((resolve, reject) => {
|
|
@@ -471,10 +496,10 @@ clear(); // Cancel the execution
|
|
|
471
496
|
|
|
472
497
|
Creates and returns an HTML element.
|
|
473
498
|
|
|
474
|
-
-
|
|
475
|
-
-
|
|
476
|
-
-
|
|
477
|
-
-
|
|
499
|
+
- `ele` : element type or existing HTMLElement object, optional, default is 'div'.
|
|
500
|
+
- `style` : The style object of the element, optional.
|
|
501
|
+
- `attr` : attribute object of the element, optional.
|
|
502
|
+
- `parent` : indicates the parent of the element. This parameter is optional.
|
|
478
503
|
|
|
479
504
|
```javascript
|
|
480
505
|
const options = {
|
|
@@ -494,9 +519,9 @@ const createdElement = createElement(options);
|
|
|
494
519
|
|
|
495
520
|
Add event listeners to the element.
|
|
496
521
|
|
|
497
|
-
-
|
|
498
|
-
-
|
|
499
|
-
-
|
|
522
|
+
- `ele` : target element.
|
|
523
|
+
- `type` : indicates the type of the event.
|
|
524
|
+
- `handler` : event handler.
|
|
500
525
|
|
|
501
526
|
```javascript
|
|
502
527
|
const button = document.getElementById("myButton");
|
|
@@ -508,7 +533,7 @@ addHandler(button, "click", handleClick);
|
|
|
508
533
|
|
|
509
534
|
Prevent events from bubbling.
|
|
510
535
|
|
|
511
|
-
-
|
|
536
|
+
- `event` : indicates an event object.
|
|
512
537
|
|
|
513
538
|
```javascript
|
|
514
539
|
const handleClick = (event) => {
|
|
@@ -521,7 +546,7 @@ const handleClick = (event) => {
|
|
|
521
546
|
|
|
522
547
|
Default behavior to block events.
|
|
523
548
|
|
|
524
|
-
-
|
|
549
|
+
- `event` : indicates an event object.
|
|
525
550
|
|
|
526
551
|
```javascript
|
|
527
552
|
const handleFormSubmit = (event) => {
|
|
@@ -534,9 +559,9 @@ const handleFormSubmit = (event) => {
|
|
|
534
559
|
|
|
535
560
|
Removes an element's event listener.
|
|
536
561
|
|
|
537
|
-
-
|
|
538
|
-
-
|
|
539
|
-
-
|
|
562
|
+
- `ele` : target element.
|
|
563
|
+
- `type` : indicates the type of the event.
|
|
564
|
+
- `handler` : event handler to be removed.
|
|
540
565
|
|
|
541
566
|
```javascript
|
|
542
567
|
const button = document.getElementById("myButton");
|
|
@@ -550,8 +575,8 @@ removeHandler(button, "click", handleClick);
|
|
|
550
575
|
|
|
551
576
|
Trigger a custom event.
|
|
552
577
|
|
|
553
|
-
-
|
|
554
|
-
-
|
|
578
|
+
- `ele` : target element.
|
|
579
|
+
- `data` : indicates the data of a custom event.
|
|
555
580
|
|
|
556
581
|
```javascript
|
|
557
582
|
const customEvent = new CustomEvent("customEvent", {
|
|
@@ -567,8 +592,8 @@ dispatchEvent(targetElement, customEvent);
|
|
|
567
592
|
|
|
568
593
|
Store values to local storage.
|
|
569
594
|
|
|
570
|
-
-
|
|
571
|
-
-
|
|
595
|
+
- `key` : specifies the name of the key.
|
|
596
|
+
- `val` : The value to be stored.
|
|
572
597
|
|
|
573
598
|
```javascript
|
|
574
599
|
const userData = { username: "john_doe", email: "john@example.com" };
|
|
@@ -579,7 +604,7 @@ setStorage("user_data", userData);
|
|
|
579
604
|
|
|
580
605
|
Gets the value from local storage.
|
|
581
606
|
|
|
582
|
-
-
|
|
607
|
+
- `key` : specifies the key name to be obtained.
|
|
583
608
|
|
|
584
609
|
```javascript
|
|
585
610
|
const storedUserData = getStorage("user_data");
|
|
@@ -591,7 +616,7 @@ console.log(storedUserData);
|
|
|
591
616
|
|
|
592
617
|
Clear the value from the local store.
|
|
593
618
|
|
|
594
|
-
-
|
|
619
|
+
- `key` : specifies the name of the key to be cleared. If no key name is provided, all storage is cleared.
|
|
595
620
|
|
|
596
621
|
```javascript
|
|
597
622
|
clearStorage("user_data"); // Clear the stored value for a specific key name
|
|
@@ -605,9 +630,9 @@ clearStorage(); // Clear all locally stored values
|
|
|
605
630
|
|
|
606
631
|
Output logs in one line.
|
|
607
632
|
|
|
608
|
-
-
|
|
609
|
-
-
|
|
610
|
-
-
|
|
633
|
+
- `str` : The string to be output.
|
|
634
|
+
- `overwrite` : Whether to overwrite the current line. The default is' false '.
|
|
635
|
+
- `wrap` : Whether to wrap lines after output, defaults to 'true'.
|
|
611
636
|
|
|
612
637
|
```javascript
|
|
613
638
|
logOneLine("This is a single line log message.");
|
|
@@ -617,11 +642,11 @@ logOneLine("This is a single line log message.");
|
|
|
617
642
|
|
|
618
643
|
Output a loop animation in the console.
|
|
619
644
|
|
|
620
|
-
-
|
|
645
|
+
- `opts` : an optional parameter object containing the following properties:
|
|
621
646
|
- `loopList` : animation character list, the default is `[' \ \ ', '|', '/', '-', '-']`.
|
|
622
|
-
-
|
|
623
|
-
-
|
|
624
|
-
-
|
|
647
|
+
- `isStop` : Whether to stop the loop. The default is' false '.
|
|
648
|
+
- `timer` : Animation switch interval (milliseconds), default is' 100 '.
|
|
649
|
+
- `index` : indicates the index of the current animated character. The default value is 0.
|
|
625
650
|
|
|
626
651
|
```javascript
|
|
627
652
|
logLoop(); // Start the default loop animation
|
|
@@ -636,7 +661,7 @@ logLoop({ loopList: ["-", "+", "-", "+"], timer: 200 }); // Start a custom loop
|
|
|
636
661
|
A class that provides frame animation.
|
|
637
662
|
|
|
638
663
|
- `start(duration? : number): void ': Starts frame animation, optional parameter' duration 'is frame number control.
|
|
639
|
-
-
|
|
664
|
+
- `stop(): void` : stops frame animation.
|
|
640
665
|
|
|
641
666
|
```javascript
|
|
642
667
|
const animateFrame = new AnimateFrame((timestamp) => {
|
|
@@ -653,9 +678,9 @@ animateFrame.stop(); // Stop frame animation
|
|
|
653
678
|
|
|
654
679
|
Calculate the coordinates of points on the quadratic Bessel curve.
|
|
655
680
|
|
|
656
|
-
-
|
|
657
|
-
-
|
|
658
|
-
-
|
|
681
|
+
- `\_x` : x coordinates of control point 1.
|
|
682
|
+
- `\_y` : y coordinate of control point 1.
|
|
683
|
+
- `t` : indicates the time parameter. The value ranges from 0 to 1.
|
|
659
684
|
|
|
660
685
|
```javascript
|
|
661
686
|
const result = quadraticBezier(0, 0, 1, 1, 0.5);
|
|
@@ -667,11 +692,11 @@ console.log(result);
|
|
|
667
692
|
|
|
668
693
|
Calculate the coordinates of points on a cubic Bezier curve.
|
|
669
694
|
|
|
670
|
-
-
|
|
671
|
-
-
|
|
672
|
-
-
|
|
673
|
-
-
|
|
674
|
-
-
|
|
695
|
+
- `\_x1` : x coordinate of control point 1.
|
|
696
|
+
- `\_y1` : y coordinate of control point 1.
|
|
697
|
+
- `\_x2` : control point 2 x coordinates.
|
|
698
|
+
- `\_y2` : y coordinate of control point 2.
|
|
699
|
+
- `t` : indicates the time parameter. The value ranges from 0 to 1.
|
|
675
700
|
|
|
676
701
|
```javascript
|
|
677
702
|
const result = cubicBezier(0, 0, 0.5, 1, 0.5);
|
|
@@ -696,7 +721,7 @@ console.log(result);
|
|
|
696
721
|
Calculate the number of combinations.
|
|
697
722
|
|
|
698
723
|
- n: indicates the total number.
|
|
699
|
-
-
|
|
724
|
+
- `k` : indicates the number of selected items.
|
|
700
725
|
|
|
701
726
|
```javascript
|
|
702
727
|
const result = combination(5, 2);
|
|
@@ -708,8 +733,8 @@ console.log(result);
|
|
|
708
733
|
|
|
709
734
|
Calculate the point coordinates on the NTH Bezier curve.
|
|
710
735
|
|
|
711
|
-
-
|
|
712
|
-
-
|
|
736
|
+
- `points` : array of control points. Each point is a second-order array.
|
|
737
|
+
- `t` : indicates the time parameter. The value ranges from 0 to 1.
|
|
713
738
|
|
|
714
739
|
```javascript
|
|
715
740
|
const points = [
|
package/README.md
CHANGED
|
@@ -124,6 +124,19 @@ const isTypeAllowed = getTypeByList(data, allowedTypes);
|
|
|
124
124
|
console.log(isTypeAllowed); // 输出: true
|
|
125
125
|
```
|
|
126
126
|
|
|
127
|
+
##### 6. `toKebabCase(camelCase: string, separator: string = "-"): string`
|
|
128
|
+
|
|
129
|
+
驼峰式命名转换为连字符式命名
|
|
130
|
+
|
|
131
|
+
- `camelCase`: 驼峰式变量
|
|
132
|
+
- `separator`: 分隔符
|
|
133
|
+
|
|
134
|
+
```javascript
|
|
135
|
+
const camelCase = "fontSize";
|
|
136
|
+
const kebabCase = toKebabCase(camelCase);
|
|
137
|
+
console.log(kebabCase); // 输出: font-size
|
|
138
|
+
```
|
|
139
|
+
|
|
127
140
|
#### object 模块
|
|
128
141
|
|
|
129
142
|
##### 1. `getValue(object: object, key: string, defaultValue: any = ''): any`
|
|
@@ -334,6 +347,18 @@ const o2 = { name: "hunter" };
|
|
|
334
347
|
console.log(o.__proto__, o2.__proto__); // 输出: undefined, [Object: null prototype] {}
|
|
335
348
|
```
|
|
336
349
|
|
|
350
|
+
##### 15. `isEmptyObject(object: IObject<unknown>): boolean`
|
|
351
|
+
|
|
352
|
+
判断是否是空对象
|
|
353
|
+
|
|
354
|
+
- `object`: 目标对象。
|
|
355
|
+
|
|
356
|
+
```javascript
|
|
357
|
+
const o = isEmptyObject({ name: "阿宇" });
|
|
358
|
+
const o2 = isEmptyObject({});
|
|
359
|
+
console.log(o, o2); // 输出: false true
|
|
360
|
+
```
|
|
361
|
+
|
|
337
362
|
#### array 模块
|
|
338
363
|
|
|
339
364
|
##### 1. `arrayRandom(arr: any[]): any[]`
|
package/dist/bundle/base.d.ts
CHANGED
|
@@ -5,11 +5,13 @@ export declare const urlSplit: IUrlSplit;
|
|
|
5
5
|
export declare const urlJoin: IUrlJoin;
|
|
6
6
|
export declare const getType: IGetType<types>;
|
|
7
7
|
export declare const getTypeByList: IGetTypeByList;
|
|
8
|
+
export declare const toKebabCase: (camelCase: string, separator?: string) => string;
|
|
8
9
|
declare const _default: {
|
|
9
10
|
randomNum: IRandomNum;
|
|
10
11
|
urlSplit: IUrlSplit;
|
|
11
12
|
urlJoin: IUrlJoin;
|
|
12
13
|
getType: IGetType<types>;
|
|
13
14
|
getTypeByList: IGetTypeByList;
|
|
15
|
+
toKebabCase: (camelCase: string, separator?: string) => string;
|
|
14
16
|
};
|
|
15
17
|
export default _default;
|
package/dist/bundle/index.d.ts
CHANGED
|
@@ -52,6 +52,7 @@ declare const _default: {
|
|
|
52
52
|
urlJoin: import("./types").IUrlJoin;
|
|
53
53
|
getType: import("./types").IGetType<import("./static").types>;
|
|
54
54
|
getTypeByList: import("./types").IGetTypeByList;
|
|
55
|
+
toKebabCase: (camelCase: string, separator?: string) => string;
|
|
55
56
|
getValue: import("./types").IGetValue;
|
|
56
57
|
setValue: import("./types").ISetValue;
|
|
57
58
|
mixIn: import("./types").IMixIn;
|