qsu 1.1.1 → 1.1.3
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 +661 -591
- package/dist/index.d.ts +66 -59
- package/dist/index.js +1 -1
- package/package.json +70 -60
package/README.md
CHANGED
|
@@ -1,591 +1,661 @@
|
|
|
1
|
-
<div align="center">
|
|
2
|
-
|
|
3
|
-

|
|
4
|
-
|
|
5
|
-
###
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
#
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
function
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
_.
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
- `
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
_.
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
- `
|
|
138
|
-
|
|
139
|
-
```javascript
|
|
140
|
-
_.
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
- `
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
_.
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
_.
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
- `str::string`
|
|
239
|
-
- `
|
|
240
|
-
|
|
241
|
-
```javascript
|
|
242
|
-
_.
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
```
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
- `
|
|
316
|
-
- `
|
|
317
|
-
|
|
318
|
-
```javascript
|
|
319
|
-
_.
|
|
320
|
-
```
|
|
321
|
-
|
|
322
|
-
### `_.
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
- `
|
|
327
|
-
- `
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
_.
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
- `
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
- `
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
_.
|
|
444
|
-
```
|
|
445
|
-
|
|
446
|
-
### `_.
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
_.
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
- `
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
_.
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
```
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
_.
|
|
507
|
-
```
|
|
508
|
-
|
|
509
|
-
### `_.
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
- `
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
```
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
_.
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
```
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
### Quick & Simple Utility for NodeJS
|
|
6
|
+
|
|
7
|
+
> [](https://github.com/jooy2/qsu/blob/master/LICENSE)    [](https://www.npmjs.com/package/qsu) [](https://www.npmjs.com/package/qsu)     [](https://github.com/jooy2) 
|
|
8
|
+
|
|
9
|
+
</div>
|
|
10
|
+
|
|
11
|
+
**Qsu** is an underscore-based utility library optimized for the **[NodeJS](https://nodejs.org)** development environment. It is supported in one module without the need to separately write frequently used methods for each project.
|
|
12
|
+
|
|
13
|
+
- Lightweight and fast!
|
|
14
|
+
- Easy to install and use.
|
|
15
|
+
- 100% optimized for the latest NodeJS and ESM environments.
|
|
16
|
+
- Useful features for websites and web applications
|
|
17
|
+
|
|
18
|
+
# Installation
|
|
19
|
+
|
|
20
|
+
Qsu requires `Node.js 12.x` or higher, and the repository is serviced through **[NPM](https://npmjs.com)**.
|
|
21
|
+
|
|
22
|
+
After configuring the node environment, you can simply run the following command.
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
# via npm
|
|
26
|
+
$ npm install qsu
|
|
27
|
+
|
|
28
|
+
# via yarn
|
|
29
|
+
$ yarn add qsu
|
|
30
|
+
|
|
31
|
+
# via pnpm
|
|
32
|
+
$ pnpm install qsu
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
# How to use
|
|
36
|
+
|
|
37
|
+
### Using named import (Multiple utilities in a single require) - Recommend
|
|
38
|
+
|
|
39
|
+
```javascript
|
|
40
|
+
import { today, strCount } from 'qsu';
|
|
41
|
+
|
|
42
|
+
function main() {
|
|
43
|
+
console.log(today()); // '20xx-xx-xx'
|
|
44
|
+
console.log(strCount('123412341234', '1')); // 3
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Using whole class (multiple utilities simultaneously with one object)
|
|
49
|
+
|
|
50
|
+
```javascript
|
|
51
|
+
import _ from 'qsu';
|
|
52
|
+
|
|
53
|
+
function main() {
|
|
54
|
+
console.log(_.today()); // '20xx-xx-xx'
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
# Methods
|
|
59
|
+
|
|
60
|
+
### `_.sleep (Promise:boolean)`
|
|
61
|
+
|
|
62
|
+
Sleep function using Promise.
|
|
63
|
+
|
|
64
|
+
- `milliseconds::number`
|
|
65
|
+
|
|
66
|
+
```javascript
|
|
67
|
+
await _.sleep(1000); // 1s
|
|
68
|
+
|
|
69
|
+
_.sleep(5000).then(() => {
|
|
70
|
+
// continue
|
|
71
|
+
});
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### `_.funcTimes (any[])`
|
|
75
|
+
|
|
76
|
+
Repeat iteratee n (times argument value) times. After the return result of each function is stored in the array in order, the final array is returned.
|
|
77
|
+
|
|
78
|
+
- `times::number`
|
|
79
|
+
- `iteratee::function`
|
|
80
|
+
|
|
81
|
+
```javascript
|
|
82
|
+
function sayHi(str) {
|
|
83
|
+
return `Hi${str || ''}`;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
_.funcTimes(3, sayHi); // Returns ['Hi', 'Hi', 'Hi']
|
|
87
|
+
_.funcTimes(4, () => sayHi('!')); // Returns ['Hi!', 'Hi!', 'Hi!', 'Hi!']
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### `_.getPlatform (string)`
|
|
91
|
+
|
|
92
|
+
Returns the operating system of the currently running process as a human-friendly string.
|
|
93
|
+
|
|
94
|
+
```javascript
|
|
95
|
+
_.getPlatform(); // Returns 'Windows'
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### `_.numRandom (number)`
|
|
99
|
+
|
|
100
|
+
Returns a random number (Between min and max).
|
|
101
|
+
|
|
102
|
+
- `min::number`
|
|
103
|
+
- `max::number`
|
|
104
|
+
|
|
105
|
+
```javascript
|
|
106
|
+
_.numRandom(1, 5); // Returns 1~5
|
|
107
|
+
_.numRandom(10, 20); // Returns 10~20
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### `_.sum (number)`
|
|
111
|
+
|
|
112
|
+
Returns after adding up all the n arguments of numbers or the values of a single array of numbers.
|
|
113
|
+
|
|
114
|
+
- `numbers::...number[]`
|
|
115
|
+
|
|
116
|
+
```javascript
|
|
117
|
+
_.sum(1, 2, 3); // Returns 6
|
|
118
|
+
_.sum([1, 2, 3, 4]); // Returns 10
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### `_.mul (number)`
|
|
122
|
+
|
|
123
|
+
Returns after multiplying all n arguments of numbers or the values of a single array of numbers.
|
|
124
|
+
|
|
125
|
+
- `numbers::...number[]`
|
|
126
|
+
|
|
127
|
+
```javascript
|
|
128
|
+
_.mul(1, 2, 3); // Returns 6
|
|
129
|
+
_.mul([1, 2, 3, 4]); // Returns 24
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### `_.dayDiff (number)`
|
|
133
|
+
|
|
134
|
+
Calculates the difference between two given dates and returns the number of days.
|
|
135
|
+
|
|
136
|
+
- `date1::Date`
|
|
137
|
+
- `date2::Date?`
|
|
138
|
+
|
|
139
|
+
```javascript
|
|
140
|
+
_.daydiff(new Date('2021-01-01'), new Date('2021-01-03')); // Returns 2
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### `_.today (string)`
|
|
144
|
+
|
|
145
|
+
Returns today's date.
|
|
146
|
+
|
|
147
|
+
- `separator::string = '-'`
|
|
148
|
+
- `yearFirst::boolean = false`
|
|
149
|
+
|
|
150
|
+
```javascript
|
|
151
|
+
_.today(); // Returns YYYY-MM-DD
|
|
152
|
+
_.today('/'); // Returns YYYY/MM/DD
|
|
153
|
+
_.today('/', false); // Returns DD/MM/YYYY
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### `_.isRealDate (boolean)`
|
|
157
|
+
|
|
158
|
+
Checks if a given date actually exists. Check only in YYYY-MM-DD format.
|
|
159
|
+
|
|
160
|
+
- `date::string|Date`
|
|
161
|
+
|
|
162
|
+
```javascript
|
|
163
|
+
_.isRealDate('2021-01-01'); // Returns true
|
|
164
|
+
_.isRealDate('2021-02-30'); // Returns false
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### `_.arrShuffle (any[])`
|
|
168
|
+
|
|
169
|
+
Shuffle the order of the given array and return.
|
|
170
|
+
|
|
171
|
+
- `array::any[]`
|
|
172
|
+
|
|
173
|
+
```javascript
|
|
174
|
+
_.arrShuffle([1, 2, 3, 4]); // Returns [4, 2, 3, 1]
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### `_.arrWithDefault (any[])`
|
|
178
|
+
|
|
179
|
+
Initialize an array with a default value of a specific length.
|
|
180
|
+
|
|
181
|
+
- `defaultValue::any`
|
|
182
|
+
- `length::number || 0`
|
|
183
|
+
|
|
184
|
+
```javascript
|
|
185
|
+
_.arrWithDefault('abc', 4); // Returns ['abc', 'abc', 'abc', 'abc']
|
|
186
|
+
_.arrWithDefault(null, 3); // Returns [null, null, null]
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### `_.arrWithNumber (number[])`
|
|
190
|
+
|
|
191
|
+
Creates and returns an Array in the order of start...end values.
|
|
192
|
+
|
|
193
|
+
- `start::number`
|
|
194
|
+
- `end::number`
|
|
195
|
+
|
|
196
|
+
```javascript
|
|
197
|
+
_.arrWithNumber(1, 3); // Returns [1, 2, 3]
|
|
198
|
+
_.arrWithNumber(0, 3); // Returns [0, 1, 2, 3]
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### `_.arrUnique (any[])`
|
|
202
|
+
|
|
203
|
+
Remove duplicate values from array and two-dimensional array data. In the case of 2d arrays, json type data duplication is not removed.
|
|
204
|
+
|
|
205
|
+
- `array::any[]`
|
|
206
|
+
|
|
207
|
+
```javascript
|
|
208
|
+
_.arrUnique([1, 2, 2, 3]); // Returns [1, 2, 3]
|
|
209
|
+
_.arrUnique([[1], [1], [2]]); // Returns [[1], [2]]
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
### `_.average (number)`
|
|
213
|
+
|
|
214
|
+
Returns the average of all numeric values in an array.
|
|
215
|
+
|
|
216
|
+
- `array::number[]`
|
|
217
|
+
|
|
218
|
+
```javascript
|
|
219
|
+
_.average([1, 5, 15, 50]); // Returns 17.75
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### `_.arrMove (any[])`
|
|
223
|
+
|
|
224
|
+
Moves the position of a specific element in an array to the specified position. (Position starts from 0.)
|
|
225
|
+
|
|
226
|
+
- `array::any[]`
|
|
227
|
+
- `from::number`
|
|
228
|
+
- `to::number`
|
|
229
|
+
|
|
230
|
+
```javascript
|
|
231
|
+
_.arrMove([1, 2, 3, 4], 1, 0); // Returns [2, 1, 3, 4]
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### `_.trim (string)`
|
|
235
|
+
|
|
236
|
+
Removes leading and trailing spaces, and returns a value converted from two or more spaces between strings to one space. If the removeAllSpace value is true, all spaces including one space are removed.
|
|
237
|
+
|
|
238
|
+
- `str::string`
|
|
239
|
+
- `removeAllSpace::boolean`
|
|
240
|
+
|
|
241
|
+
```javascript
|
|
242
|
+
_.trim(' Hello Wor ld '); // Returns 'Hello World'
|
|
243
|
+
_.trim('H e l l o World', true); // Returns 'HelloWorld'
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
### `_.removeSpecialChar (string)`
|
|
247
|
+
|
|
248
|
+
Returns after removing all special characters, including spaces.
|
|
249
|
+
|
|
250
|
+
- `str::string`
|
|
251
|
+
- `withoutSpace::boolean`
|
|
252
|
+
|
|
253
|
+
```javascript
|
|
254
|
+
_.removeSpecialChar('Hello, World!'); // Returns 'HelloWorld'
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
### `_.removeNewLine (string)`
|
|
258
|
+
|
|
259
|
+
Removes `\n`, `\r` characters or replaces them with specified characters.
|
|
260
|
+
|
|
261
|
+
- `str::string`
|
|
262
|
+
- `replaceTo::string || ''`
|
|
263
|
+
|
|
264
|
+
```javascript
|
|
265
|
+
_.removeNewLine('ab\ncd'); // Returns 'abcd'
|
|
266
|
+
_.removeNewLine('ab\r\ncd', '-'); // Returns 'ab-cd'
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
### `_.capitalizeFirst (string)`
|
|
270
|
+
|
|
271
|
+
Converts the first letter of the entire string to uppercase and returns.
|
|
272
|
+
|
|
273
|
+
- `str::string`
|
|
274
|
+
|
|
275
|
+
```javascript
|
|
276
|
+
_.capitalizeFirst('abcd'); // Returns 'Abcd'
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
### `_.capitalizeEachWords (string)`
|
|
280
|
+
|
|
281
|
+
Converts every word with spaces to uppercase. If the naturally argument is true, only some special cases (such as prepositions) are kept lowercase.
|
|
282
|
+
|
|
283
|
+
- `str::string`
|
|
284
|
+
- `natural::boolean || false`
|
|
285
|
+
|
|
286
|
+
```javascript
|
|
287
|
+
_.capitalizeEachWords('abcd'); // Returns 'Abcd'
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
### `_.strCount (number)`
|
|
291
|
+
|
|
292
|
+
Returns the number of times the second String argument is contained in the first String argument.
|
|
293
|
+
|
|
294
|
+
- `str::string`
|
|
295
|
+
- `search::string`
|
|
296
|
+
|
|
297
|
+
```javascript
|
|
298
|
+
_.strCount('abcabc', 'a'); // Returns 2
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
### `_.strShuffle (string)`
|
|
302
|
+
|
|
303
|
+
Randomly shuffles the received string and returns it.
|
|
304
|
+
|
|
305
|
+
- `str::string`
|
|
306
|
+
|
|
307
|
+
```javascript
|
|
308
|
+
_.strShuffle('abcdefg'); // Returns 'bgafced'
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
### `_.strRandom (string)`
|
|
312
|
+
|
|
313
|
+
Returns a random String containing numbers or uppercase and lowercase letters of the given length. The default return length is 12.
|
|
314
|
+
|
|
315
|
+
- `length::number`
|
|
316
|
+
- `additionalCharacters::string?`
|
|
317
|
+
|
|
318
|
+
```javascript
|
|
319
|
+
_.strRandom(5); // Returns 'CHy2M'
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
### `_.strBlindRandom (string)`
|
|
323
|
+
|
|
324
|
+
Replace strings at random locations with a specified number of characters (default 1) with characters (default \*).
|
|
325
|
+
|
|
326
|
+
- `str::string`
|
|
327
|
+
- `blindLength::number`
|
|
328
|
+
- `blindStr::string || '*'`
|
|
329
|
+
|
|
330
|
+
```javascript
|
|
331
|
+
_.strBlindRandom('hello', 2, '#'); // Returns '#el#o'
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
### `_.truncate (string)`
|
|
335
|
+
|
|
336
|
+
Truncates a long string to a specified length, optionally appending an ellipsis after the string.
|
|
337
|
+
|
|
338
|
+
- `str::string`
|
|
339
|
+
- `length::number`
|
|
340
|
+
- `ellipsis::string || ''`
|
|
341
|
+
|
|
342
|
+
```javascript
|
|
343
|
+
_.truncate('hello', 3); // Returns 'hel'
|
|
344
|
+
_.truncate('hello', 2, '...'); // Returns 'he...'
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
### `_.split (string[])`
|
|
348
|
+
|
|
349
|
+
Splits a string based on the specified character and returns it as an Array. Unlike the existing split, it splits the values provided as multiple parameters (array or multiple arguments) at once.
|
|
350
|
+
|
|
351
|
+
- `str::string`
|
|
352
|
+
- `splitter::string||string[]||...string`
|
|
353
|
+
|
|
354
|
+
```javascript
|
|
355
|
+
_.split('hello% js world', '% '); // Returns ['hello', 'js world']
|
|
356
|
+
_.split('hello,js,world', ','); // Returns ['hello', 'js', 'world']
|
|
357
|
+
_.split('hello%js,world', ',', '%'); // Returns ['hello', 'js', 'world']
|
|
358
|
+
_.split('hello%js,world', [',', '%']); // Returns ['hello', 'js', 'world']
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
### `_.encrypt (string)`
|
|
362
|
+
|
|
363
|
+
Encrypt with the algorithm of your choice (algorithm default: `aes-256-cbc`, ivSize default: `16`) using a string and a secret (secret).
|
|
364
|
+
|
|
365
|
+
- `str::string`
|
|
366
|
+
- `secret::string`
|
|
367
|
+
- `algorithm::string || 'aes-256-cbc'`
|
|
368
|
+
- `ivSize::number || 16`
|
|
369
|
+
|
|
370
|
+
```javascript
|
|
371
|
+
_.encrypt('test', 'secret-key');
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
### `_.decrypt (string)`
|
|
375
|
+
|
|
376
|
+
Decrypt with the specified algorithm (default: `aes-256-cbc`) using a string and a secret (secret).
|
|
377
|
+
|
|
378
|
+
- `str::string`
|
|
379
|
+
- `secret::string`
|
|
380
|
+
- `algorithm::string || 'aes-256-cbc'`
|
|
381
|
+
|
|
382
|
+
```javascript
|
|
383
|
+
_.decrypt('61ba43b65fc...', 'secret-key');
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
### `_.md5 (string)`
|
|
387
|
+
|
|
388
|
+
Converts String data to md5 hash value and returns it.
|
|
389
|
+
|
|
390
|
+
- `str::string`
|
|
391
|
+
|
|
392
|
+
```javascript
|
|
393
|
+
_.md5('test'); // Returns '098f6bcd4621d373cade4e832627b4f6'
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
### `_.sha1 (string)`
|
|
397
|
+
|
|
398
|
+
Converts String data to sha1 hash value and returns it.
|
|
399
|
+
|
|
400
|
+
- `str::string`
|
|
401
|
+
|
|
402
|
+
```javascript
|
|
403
|
+
_.sha1('test'); // Returns 'a94a8fe5ccb19ba61c4c0873d391e987982fbbd3'
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
### `_.sha256 (string)`
|
|
407
|
+
|
|
408
|
+
Converts String data to sha256 hash value and returns it.
|
|
409
|
+
|
|
410
|
+
- `str::string`
|
|
411
|
+
|
|
412
|
+
```javascript
|
|
413
|
+
_.sha256('test'); // Returns '9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08'
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
### `_.encodeBase64 (string)`
|
|
417
|
+
|
|
418
|
+
Base64-encode the given string.
|
|
419
|
+
|
|
420
|
+
- `str::string`
|
|
421
|
+
|
|
422
|
+
```javascript
|
|
423
|
+
_.encodeBase64('this is test'); // Returns 'dGhpcyBpcyB0ZXN0'
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
### `_.decodeBase64 (string)`
|
|
427
|
+
|
|
428
|
+
Decodes an encoded base64 string to a plain string.
|
|
429
|
+
|
|
430
|
+
- `encodedStr::string`
|
|
431
|
+
|
|
432
|
+
```javascript
|
|
433
|
+
_.decodeBase64('dGhpcyBpcyB0ZXN0'); // Returns 'this is test'
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
### `_.strUnique (string)`
|
|
437
|
+
|
|
438
|
+
Remove duplicate characters from a given string and output only one.
|
|
439
|
+
|
|
440
|
+
- `str::string`
|
|
441
|
+
|
|
442
|
+
```javascript
|
|
443
|
+
_.strUnique('aaabbbcc'); // Returns 'abc'
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
### `_.isEqual (boolean)`
|
|
447
|
+
|
|
448
|
+
It compares the first argument value as the left operand and the argument values given thereafter as the right operand, and returns `true` if the values are all the same.
|
|
449
|
+
|
|
450
|
+
`isEqual` returns `true` even if the data types do not match, but `isEqualStrict` returns `true` only when the data types of all argument values match.
|
|
451
|
+
|
|
452
|
+
- `leftOperand::any`
|
|
453
|
+
- `rightOperand::any||any[]||...any`
|
|
454
|
+
|
|
455
|
+
```javascript
|
|
456
|
+
const val1 = 'Left';
|
|
457
|
+
const val2 = 1;
|
|
458
|
+
|
|
459
|
+
_.isEqual('Left', 'Left', val1); // Returns true
|
|
460
|
+
_.isEqual(1, [1, '1', 1, val2]); // Returns true
|
|
461
|
+
_.isEqual(val1, ['Right', 'Left', 1]); // Returns false
|
|
462
|
+
_.isEqual(1, 1, 1, 1); // Returns true
|
|
463
|
+
```
|
|
464
|
+
|
|
465
|
+
### `_.isEqualStrict (boolean)`
|
|
466
|
+
|
|
467
|
+
It compares the first argument value as the left operand and the argument values given thereafter as the right operand, and returns `true` if the values are all the same.
|
|
468
|
+
|
|
469
|
+
`isEqual` returns `true` even if the data types do not match, but `isEqualStrict` returns `true` only when the data types of all argument values match.
|
|
470
|
+
|
|
471
|
+
- `leftOperand::any`
|
|
472
|
+
- `rightOperand::any||any[]||...any`
|
|
473
|
+
|
|
474
|
+
```javascript
|
|
475
|
+
const val1 = 'Left';
|
|
476
|
+
const val2 = 1;
|
|
477
|
+
|
|
478
|
+
_.isEqualStrict('Left', 'Left', val1); // Returns true
|
|
479
|
+
_.isEqualStrict(1, [1, '1', 1, val2]); // Returns false
|
|
480
|
+
_.isEqualStrict(1, 1, '1', 1); // Returns false
|
|
481
|
+
```
|
|
482
|
+
|
|
483
|
+
### `_.isEmpty (boolean)`
|
|
484
|
+
|
|
485
|
+
Returns true if the passed data is empty or has a length of 0.
|
|
486
|
+
|
|
487
|
+
- `data::any?`
|
|
488
|
+
|
|
489
|
+
```javascript
|
|
490
|
+
_.isEmpty([]); // Returns true
|
|
491
|
+
_.isEmpty(''); // Returns true
|
|
492
|
+
_.isEmpty('abc'); // Returns false
|
|
493
|
+
```
|
|
494
|
+
|
|
495
|
+
### `_.isUrl (boolean)`
|
|
496
|
+
|
|
497
|
+
Returns `true` if the given data is in the correct URL format. If withProtocol is `true`, it is automatically appended to the URL when the protocol does not exist. If strict is `true`, URLs without commas (`.`) return `false`.
|
|
498
|
+
|
|
499
|
+
- `url::string`
|
|
500
|
+
- `withProtocol::boolean || false`
|
|
501
|
+
- `strict::boolean || false`
|
|
502
|
+
|
|
503
|
+
```javascript
|
|
504
|
+
_.isUrl('google.com'); // Returns false
|
|
505
|
+
_.isUrl('google.com', true); // Returns true
|
|
506
|
+
_.isUrl('https://google.com'); // Returns true
|
|
507
|
+
```
|
|
508
|
+
|
|
509
|
+
### `_.contains (boolean)`
|
|
510
|
+
|
|
511
|
+
Returns `true` if the first string argument contains the second argument "string" or "one or more of the strings listed in the array". If the exact value is `true`, it returns true only for an exact match.
|
|
512
|
+
|
|
513
|
+
- `str::any[]|string`
|
|
514
|
+
- `search::any[]|string`
|
|
515
|
+
- `exact::boolean || false`
|
|
516
|
+
|
|
517
|
+
```javascript
|
|
518
|
+
_.contains('abc', 'a'); // Returns true
|
|
519
|
+
_.contains('abc', 'd'); // Returns false
|
|
520
|
+
_.contains('abc', ['a', 'd']); // Returns true
|
|
521
|
+
```
|
|
522
|
+
|
|
523
|
+
### `_.is2dArray (boolean)`
|
|
524
|
+
|
|
525
|
+
Returns `true` if the given array is a two-dimensional array.
|
|
526
|
+
|
|
527
|
+
- `array::any[]`
|
|
528
|
+
|
|
529
|
+
```javascript
|
|
530
|
+
_.is2dArray([1]); // Returns false
|
|
531
|
+
_.is2dArray([[1], [2]]); // Returns true
|
|
532
|
+
```
|
|
533
|
+
|
|
534
|
+
### `_.between (boolean)`
|
|
535
|
+
|
|
536
|
+
Returns `true` if the first argument is in the range of the second argument (`[min, max]`). To allow the minimum and maximum values to be in the range, pass `true` for the third argument.
|
|
537
|
+
|
|
538
|
+
- `range::[number, number]`
|
|
539
|
+
- `number::number`
|
|
540
|
+
- `inclusive::boolean || false`
|
|
541
|
+
|
|
542
|
+
```javascript
|
|
543
|
+
_.between([10, 20], 10); // Returns false
|
|
544
|
+
_.between([10, 20], 10, true); // Returns true
|
|
545
|
+
```
|
|
546
|
+
|
|
547
|
+
### `_.len (number)`
|
|
548
|
+
|
|
549
|
+
Returns the length of any type of data. If the argument value is `null` or `undefined`, `0` is returned.
|
|
550
|
+
|
|
551
|
+
- `data::any`
|
|
552
|
+
|
|
553
|
+
```javascript
|
|
554
|
+
_.len('12345'); // Returns 5
|
|
555
|
+
_.len([1, 2, 3]); // Returns 3
|
|
556
|
+
```
|
|
557
|
+
|
|
558
|
+
### `_.isBotAgent (boolean)`
|
|
559
|
+
|
|
560
|
+
Analyze the user agent value to determine if it's a bot for a search engine. Returns `true` if it's a bot.
|
|
561
|
+
|
|
562
|
+
- `userAgent::string`
|
|
563
|
+
|
|
564
|
+
```javascript
|
|
565
|
+
_.isBotAgent('Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)'); // Returns true
|
|
566
|
+
```
|
|
567
|
+
|
|
568
|
+
### `_.numberFormat (string)`
|
|
569
|
+
|
|
570
|
+
Return number format including comma symbol.
|
|
571
|
+
|
|
572
|
+
- `number::number`
|
|
573
|
+
|
|
574
|
+
```javascript
|
|
575
|
+
_.numberFormat(1234567); // Returns 1,234,567
|
|
576
|
+
```
|
|
577
|
+
|
|
578
|
+
### `_.fileName (string)`
|
|
579
|
+
|
|
580
|
+
Extract the file name from the path. Include the extension if withExtension is `true`.
|
|
581
|
+
|
|
582
|
+
- `filePath::string`
|
|
583
|
+
- `withExtension::boolean || false`
|
|
584
|
+
|
|
585
|
+
```javascript
|
|
586
|
+
_.fileName('C:Temphello.txt'); // Returns 'hello.txt'
|
|
587
|
+
_.fileName('C:Temp\file.mp3', true); // Returns 'file.mp3'
|
|
588
|
+
```
|
|
589
|
+
|
|
590
|
+
### `_.fileSize (string)`
|
|
591
|
+
|
|
592
|
+
Converts the file size in bytes to human-readable and returns it. The return value is a String and includes the file units (Bytes, MB, GB...). If the second optional argument value is included, you can display as many decimal places as you like.
|
|
593
|
+
|
|
594
|
+
- `bytes::number`
|
|
595
|
+
- `decimals::number || 2`
|
|
596
|
+
|
|
597
|
+
```javascript
|
|
598
|
+
_.fileSize(2000, 3); // Returns '1.953 KB'
|
|
599
|
+
_.fileSize(250000000); // Returns '238.42 MB'
|
|
600
|
+
```
|
|
601
|
+
|
|
602
|
+
### `_.fileExt (string)`
|
|
603
|
+
|
|
604
|
+
Returns only the extensions in the file path. If unknown, returns 'Unknown'.
|
|
605
|
+
|
|
606
|
+
- `filePath::string`
|
|
607
|
+
|
|
608
|
+
```javascript
|
|
609
|
+
_.fileExt('C:Temphello.txt'); // Returns 'txt'
|
|
610
|
+
_.fileExt('this-is-file.mp3'); // Returns 'mp3'
|
|
611
|
+
```
|
|
612
|
+
|
|
613
|
+
### `_.msToTime (string)`
|
|
614
|
+
|
|
615
|
+
Converts milliseconds to hours, minutes, seconds, and milliseconds and returns. If the second argument is true, milliseconds are also printed. You can put any separator (String) between hours, minutes, and seconds in the third argument.
|
|
616
|
+
|
|
617
|
+
- `milliseconds::number`
|
|
618
|
+
- `withMilliseconds::boolean || false`
|
|
619
|
+
- `separator::string || ':'`
|
|
620
|
+
|
|
621
|
+
```javascript
|
|
622
|
+
_.msToTime(100000); // 'Returns '00:01:40'
|
|
623
|
+
_.msToTime(100000, true, '-'); // Returns '00-01-40.0'
|
|
624
|
+
```
|
|
625
|
+
|
|
626
|
+
### `_.secToTime (string)`
|
|
627
|
+
|
|
628
|
+
Converts seconds to hours, minutes, seconds and returns. You can put any separator (String) between hours, minutes, and seconds in the third argument.
|
|
629
|
+
|
|
630
|
+
- `seconds::number`
|
|
631
|
+
- `onlyHour::boolean || false`
|
|
632
|
+
- `separator::string || ':'`
|
|
633
|
+
|
|
634
|
+
```javascript
|
|
635
|
+
_.secToTime(3800); // Returns '01:03:20'
|
|
636
|
+
_.secToTime(60, '-'); // Returns '00-01-00'
|
|
637
|
+
```
|
|
638
|
+
|
|
639
|
+
### `_.license (string)`
|
|
640
|
+
|
|
641
|
+
Returns text in a specific license format based on the author information of the given argument. The argument uses the Object type.
|
|
642
|
+
|
|
643
|
+
- `options::LicenseOption{ author: string, email: string?, yearStart: string|number, yearEnd: string?, htmlBr: boolean?, type: 'mit' | 'apache20' }`
|
|
644
|
+
|
|
645
|
+
```javascript
|
|
646
|
+
_.license({
|
|
647
|
+
holder: 'example',
|
|
648
|
+
email: 'example@example.com',
|
|
649
|
+
yearStart: 2020,
|
|
650
|
+
yearEnd: 2021,
|
|
651
|
+
htmlBr: true
|
|
652
|
+
});
|
|
653
|
+
```
|
|
654
|
+
|
|
655
|
+
# Contribute
|
|
656
|
+
|
|
657
|
+
You can report issues on [GitHub Issue Tracker](https://github.com/jooy2/qsu/issues). You can also request a pull to fix bugs and add frequently used features.
|
|
658
|
+
|
|
659
|
+
# License
|
|
660
|
+
|
|
661
|
+
Copyright © 2021-2022 Jooy2 Released under the MIT license.
|