qsu 1.1.8 → 1.2.0

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,13 +1,9 @@
1
- <div align="center">
2
-
3
1
  ![logo](logo.webp)
4
2
 
5
- ### Quick & Simple Utility for NodeJS
3
+ # Qsu: Quick & Simple Utility for NodeJS
6
4
 
7
5
  > [![license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/jooy2/qsu/blob/master/LICENSE) ![Programming Language Usage](https://img.shields.io/github/languages/top/jooy2/qsu) ![Commit Count](https://img.shields.io/github/commit-activity/y/jooy2/qsu) ![Line Count](https://img.shields.io/tokei/lines/github/jooy2/qsu) [![npm downloads](https://img.shields.io/npm/dm/qsu.svg)](https://www.npmjs.com/package/qsu) [![npm latest package](https://img.shields.io/npm/v/qsu/latest.svg)](https://www.npmjs.com/package/qsu) ![npm maintenance](https://img.shields.io/npms-io/maintenance-score/qsu) ![npm quality](https://img.shields.io/npms-io/quality-score/qsu) ![minified size](https://img.shields.io/bundlephobia/min/qsu) ![github repo size](https://img.shields.io/github/repo-size/jooy2/qsu) [![Followers](https://img.shields.io/github/followers/jooy2?style=social)](https://github.com/jooy2) ![Stars](https://img.shields.io/github/stars/jooy2/qsu?style=social)
8
6
 
9
- </div>
10
-
11
7
  **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
8
 
13
9
  - Lightweight and fast!
@@ -15,780 +11,14 @@
15
11
  - 100% optimized for the latest NodeJS and ESM environments.
16
12
  - Useful features for websites and web applications
17
13
 
18
- # Installation
19
-
20
- Qsu requires `Node.js 14.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
- ### `_.sub (number)`
133
-
134
- Returns after subtracting all n arguments of numbers or the values of a single array of numbers.
135
-
136
- - `numbers::...number[]`
137
-
138
- ```javascript
139
- _.sub(10, 1, 5); // Returns 4
140
- _.sub([1, 2, 3, 4]); // Returns -8
141
- ```
142
-
143
- ### `_.div (number)`
144
-
145
- Returns after dividing all n arguments of numbers or the values of a single array of numbers.
146
-
147
- - `numbers::...number[]`
148
-
149
- ```javascript
150
- _.div(10, 5, 2); // Returns 1
151
- _.div([100, 2, 2, 5]); // Returns 5
152
- ```
153
-
154
- ### `_.dayDiff (number)`
155
-
156
- Calculates the difference between two given dates and returns the number of days.
157
-
158
- - `date1::Date`
159
- - `date2::Date?`
160
-
161
- ```javascript
162
- _.daydiff(new Date('2021-01-01'), new Date('2021-01-03')); // Returns 2
163
- ```
164
-
165
- ### `_.today (string)`
166
-
167
- Returns today's date.
168
-
169
- - `separator::string = '-'`
170
- - `yearFirst::boolean = false`
171
-
172
- ```javascript
173
- _.today(); // Returns YYYY-MM-DD
174
- _.today('/'); // Returns YYYY/MM/DD
175
- _.today('/', false); // Returns DD/MM/YYYY
176
- ```
177
-
178
- ### `_.isValidDate (boolean)`
179
-
180
- Checks if a given date actually exists. Check only in `YYYY-MM-DD` format.
181
-
182
- - `date::string`
183
-
184
- ```javascript
185
- _.isValidDate('2021-01-01'); // Returns true
186
- _.isValidDate('2021-02-30'); // Returns false
187
- ```
188
-
189
- ### `_.dateToYYYYMMDD (string)`
190
-
191
- Returns the date data of a Date object in the format `YYYY-MM-DD`.
192
-
193
- - `date::Date`
194
- - `separator:string`
195
-
196
- ```javascript
197
- _.dateToYYYYMMDD(new Date(2023, 11, 31)); // Returns '2023-12-31'
198
- ```
199
-
200
- ### `_.createDateListFromRange (string[])`
201
-
202
- Create an array list of all dates from `startDate` to `endDate` in the format `YYYY-MM-DD`.
203
-
204
- - `startDate::Date`
205
- - `endDate::Date`
206
-
207
- ```javascript
208
- _.createDateListFromRange(new Date('2023-01-01T01:00:00Z'), new Date('2023-01-05T01:00:00Z'));
209
-
210
- /*
211
- Returns:
212
- [
213
- '2023-01-01',
214
- '2023-01-02',
215
- '2023-01-03',
216
- '2023-01-04',
217
- '2023-01-05'
218
- ]
219
- */
220
- ```
221
-
222
- ### `_.arrShuffle (any[])`
223
-
224
- Shuffle the order of the given array and return.
225
-
226
- - `array::any[]`
227
-
228
- ```javascript
229
- _.arrShuffle([1, 2, 3, 4]); // Returns [4, 2, 3, 1]
230
- ```
231
-
232
- ### `_.arrWithDefault (any[])`
233
-
234
- Initialize an array with a default value of a specific length.
235
-
236
- - `defaultValue::any`
237
- - `length::number || 0`
238
-
239
- ```javascript
240
- _.arrWithDefault('abc', 4); // Returns ['abc', 'abc', 'abc', 'abc']
241
- _.arrWithDefault(null, 3); // Returns [null, null, null]
242
- ```
243
-
244
- ### `_.arrWithNumber (number[])`
245
-
246
- Creates and returns an Array in the order of start...end values.
247
-
248
- - `start::number`
249
- - `end::number`
250
-
251
- ```javascript
252
- _.arrWithNumber(1, 3); // Returns [1, 2, 3]
253
- _.arrWithNumber(0, 3); // Returns [0, 1, 2, 3]
254
- ```
255
-
256
- ### `_.arrUnique (any[])`
257
-
258
- Remove duplicate values from array and two-dimensional array data. In the case of 2d arrays, json type data duplication is not removed.
259
-
260
- - `array::any[]`
261
-
262
- ```javascript
263
- _.arrUnique([1, 2, 2, 3]); // Returns [1, 2, 3]
264
- _.arrUnique([[1], [1], [2]]); // Returns [[1], [2]]
265
- ```
266
-
267
- ### `_.average (number)`
268
-
269
- Returns the average of all numeric values in an array.
270
-
271
- - `array::number[]`
272
-
273
- ```javascript
274
- _.average([1, 5, 15, 50]); // Returns 17.75
275
- ```
276
-
277
- ### `_.arrMove (any[])`
278
-
279
- Moves the position of a specific element in an array to the specified position. (Position starts from 0.)
280
-
281
- - `array::any[]`
282
- - `from::number`
283
- - `to::number`
284
-
285
- ```javascript
286
- _.arrMove([1, 2, 3, 4], 1, 0); // Returns [2, 1, 3, 4]
287
- ```
288
-
289
- ### `_.arrTo1dArray (any[])`
290
-
291
- Merges all elements of a multidimensional array into a one-dimensional array.
292
-
293
- - `array::any[]`
294
-
295
- ```javascript
296
- _.arrTo1dArray([1, 2, [3, 4]], 5); // Returns [1, 2, 3, 4, 5]
297
- ```
298
-
299
- ### `_.arrRepeat (any[])`
300
-
301
- Repeats the data of an `Array` or `Object` a specific number of times and returns it as a 1d array.
302
-
303
- - `array::any[]|object`
304
- - `count::number`
305
-
306
- ```javascript
307
- _.arrRepeat([1, 2, 3, 4], 3); // Returns [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4]
308
- _.arrRepeat({ a: 1, b: 2 }, 2); // Returns [{ a: 1, b: 2 }, { a: 1, b: 2 }]
309
- ```
310
-
311
- ### `_.arrCount (object)`
312
-
313
- Returns the number of duplicates for each unique value in the given array. The array values can only be of type `String` or `Number`.
314
-
315
- - `array::string[]|number[]`
316
- - `count::number`
317
-
318
- ```javascript
319
- _.arrCount(['a', 'a', 'a', 'b', 'c', 'b', 'a', 'd']); // Returns { a: 4, b: 2, c: 1, d: 1 }
320
- ```
321
-
322
- ### `_.trim (string)`
323
-
324
- 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.
325
-
326
- - `str::string`
327
- - `removeAllSpace::boolean`
328
-
329
- ```javascript
330
- _.trim(' Hello Wor ld '); // Returns 'Hello World'
331
- _.trim('H e l l o World', true); // Returns 'HelloWorld'
332
- ```
333
-
334
- ### `_.removeSpecialChar (string)`
335
-
336
- Returns after removing all special characters, including spaces. If you want to allow any special characters as exceptions, list them in the second argument value without delimiters. For example, if you want to allow spaces and the symbols `&` and `*`, the second argument value would be ' &\*'.
337
-
338
- - `str::string`
339
- - `exceptionCharacters::string?`
340
-
341
- ```javascript
342
- _.removeSpecialChar('Hello-qsu, World!'); // Returns 'HelloqsuWorld'
343
- _.removeSpecialChar('Hello-qsu, World!', ' -'); // Returns 'Hello-qsu World'
344
- ```
345
-
346
- ### `_.removeNewLine (string)`
347
-
348
- Removes `\n`, `\r` characters or replaces them with specified characters.
349
-
350
- - `str::string`
351
- - `replaceTo::string || ''`
352
-
353
- ```javascript
354
- _.removeNewLine('ab\ncd'); // Returns 'abcd'
355
- _.removeNewLine('ab\r\ncd', '-'); // Returns 'ab-cd'
356
- ```
357
-
358
- ### `_.capitalizeFirst (string)`
359
-
360
- Converts the first letter of the entire string to uppercase and returns.
361
-
362
- - `str::string`
363
-
364
- ```javascript
365
- _.capitalizeFirst('abcd'); // Returns 'Abcd'
366
- ```
367
-
368
- ### `_.capitalizeEachWords (string)`
369
-
370
- Converts every word with spaces to uppercase. If the naturally argument is true, only some special cases (such as prepositions) are kept lowercase.
371
-
372
- - `str::string`
373
- - `natural::boolean || false`
374
-
375
- ```javascript
376
- _.capitalizeEachWords('abcd'); // Returns 'Abcd'
377
- ```
378
-
379
- ### `_.strCount (number)`
380
-
381
- Returns the number of times the second String argument is contained in the first String argument.
382
-
383
- - `str::string`
384
- - `search::string`
385
-
386
- ```javascript
387
- _.strCount('abcabc', 'a'); // Returns 2
388
- ```
389
-
390
- ### `_.strShuffle (string)`
391
-
392
- Randomly shuffles the received string and returns it.
393
-
394
- - `str::string`
395
-
396
- ```javascript
397
- _.strShuffle('abcdefg'); // Returns 'bgafced'
398
- ```
399
-
400
- ### `_.strRandom (string)`
401
-
402
- Returns a random String containing numbers or uppercase and lowercase letters of the given length. The default return length is 12.
403
-
404
- - `length::number`
405
- - `additionalCharacters::string?`
406
-
407
- ```javascript
408
- _.strRandom(5); // Returns 'CHy2M'
409
- ```
410
-
411
- ### `_.strBlindRandom (string)`
412
-
413
- Replace strings at random locations with a specified number of characters (default 1) with characters (default \*).
414
-
415
- - `str::string`
416
- - `blindLength::number`
417
- - `blindStr::string || '*'`
418
-
419
- ```javascript
420
- _.strBlindRandom('hello', 2, '#'); // Returns '#el#o'
421
- ```
422
-
423
- ### `_.truncate (string)`
424
-
425
- Truncates a long string to a specified length, optionally appending an ellipsis after the string.
426
-
427
- - `str::string`
428
- - `length::number`
429
- - `ellipsis::string || ''`
430
-
431
- ```javascript
432
- _.truncate('hello', 3); // Returns 'hel'
433
- _.truncate('hello', 2, '...'); // Returns 'he...'
434
- ```
435
-
436
- ### `_.truncateExpect (string)`
437
-
438
- The string ignores truncation until the ending character (`endStringChar`). If the expected length is reached, return the truncated string until after the ending character.
439
-
440
- - `str::string`
441
- - `expectLength::number`
442
- - `endStringChar::string || '.'`
443
-
444
- ```javascript
445
- _.truncateExpect('hello. this is test string.', 10, '.'); // Returns 'hello. this is test string.'
446
- _.truncateExpect('hello-this-is-test-string-bye', 14, '-'); // Returns 'hello-this-is-'
447
- ```
448
-
449
- ### `_.split (string[])`
450
-
451
- 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.
452
-
453
- - `str::string`
454
- - `splitter::string||string[]||...string`
455
-
456
- ```javascript
457
- _.split('hello% js world', '% '); // Returns ['hello', 'js world']
458
- _.split('hello,js,world', ','); // Returns ['hello', 'js', 'world']
459
- _.split('hello%js,world', ',', '%'); // Returns ['hello', 'js', 'world']
460
- _.split('hello%js,world', [',', '%']); // Returns ['hello', 'js', 'world']
461
- ```
462
-
463
- ### `_.encrypt (string)`
464
-
465
- Encrypt with the algorithm of your choice (algorithm default: `aes-256-cbc`, ivSize default: `16`) using a string and a secret (secret).
466
-
467
- - `str::string`
468
- - `secret::string`
469
- - `algorithm::string || 'aes-256-cbc'`
470
- - `ivSize::number || 16`
471
-
472
- ```javascript
473
- _.encrypt('test', 'secret-key');
474
- ```
475
-
476
- ### `_.decrypt (string)`
477
-
478
- Decrypt with the specified algorithm (default: `aes-256-cbc`) using a string and a secret (secret).
479
-
480
- - `str::string`
481
- - `secret::string`
482
- - `algorithm::string || 'aes-256-cbc'`
483
-
484
- ```javascript
485
- _.decrypt('61ba43b65fc...', 'secret-key');
486
- ```
487
-
488
- ### `_.md5 (string)`
489
-
490
- Converts String data to md5 hash value and returns it.
491
-
492
- - `str::string`
493
-
494
- ```javascript
495
- _.md5('test'); // Returns '098f6bcd4621d373cade4e832627b4f6'
496
- ```
497
-
498
- ### `_.sha1 (string)`
499
-
500
- Converts String data to sha1 hash value and returns it.
501
-
502
- - `str::string`
503
-
504
- ```javascript
505
- _.sha1('test'); // Returns 'a94a8fe5ccb19ba61c4c0873d391e987982fbbd3'
506
- ```
507
-
508
- ### `_.sha256 (string)`
509
-
510
- Converts String data to sha256 hash value and returns it.
511
-
512
- - `str::string`
513
-
514
- ```javascript
515
- _.sha256('test'); // Returns '9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08'
516
- ```
517
-
518
- ### `_.encodeBase64 (string)`
519
-
520
- Base64-encode the given string.
521
-
522
- - `str::string`
523
-
524
- ```javascript
525
- _.encodeBase64('this is test'); // Returns 'dGhpcyBpcyB0ZXN0'
526
- ```
527
-
528
- ### `_.decodeBase64 (string)`
529
-
530
- Decodes an encoded base64 string to a plain string.
531
-
532
- - `encodedStr::string`
533
-
534
- ```javascript
535
- _.decodeBase64('dGhpcyBpcyB0ZXN0'); // Returns 'this is test'
536
- ```
537
-
538
- ### `_.strUnique (string)`
539
-
540
- Remove duplicate characters from a given string and output only one.
541
-
542
- - `str::string`
543
-
544
- ```javascript
545
- _.strUnique('aaabbbcc'); // Returns 'abc'
546
- ```
547
-
548
- ### `_.strToAscii (number[])`
549
-
550
- Converts the given string to ascii code and returns it as an array.
551
-
552
- - `str::string`
553
-
554
- ```javascript
555
- _.strToAscii('12345'); // Returns [49, 50, 51, 52, 53]
556
- ```
557
-
558
- ### `_.isObject (boolean)`
559
-
560
- Check whether the given data is of type `Object`. Returns `false` for other data types including `Array`.
561
-
562
- - `data::any`
563
-
564
- ```javascript
565
- _.isObject([1, 2, 3]); // Returns false
566
- _.isObject({ a: 1, b: 2 }); // Returns true
567
- ```
568
-
569
- ### `_.isEqual (boolean)`
570
-
571
- 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.
572
-
573
- `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.
574
-
575
- - `leftOperand::any`
576
- - `rightOperand::any||any[]||...any`
577
-
578
- ```javascript
579
- const val1 = 'Left';
580
- const val2 = 1;
581
-
582
- _.isEqual('Left', 'Left', val1); // Returns true
583
- _.isEqual(1, [1, '1', 1, val2]); // Returns true
584
- _.isEqual(val1, ['Right', 'Left', 1]); // Returns false
585
- _.isEqual(1, 1, 1, 1); // Returns true
586
- ```
587
-
588
- ### `_.isEqualStrict (boolean)`
589
-
590
- 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.
591
-
592
- `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.
593
-
594
- - `leftOperand::any`
595
- - `rightOperand::any||any[]||...any`
596
-
597
- ```javascript
598
- const val1 = 'Left';
599
- const val2 = 1;
600
-
601
- _.isEqualStrict('Left', 'Left', val1); // Returns true
602
- _.isEqualStrict(1, [1, '1', 1, val2]); // Returns false
603
- _.isEqualStrict(1, 1, '1', 1); // Returns false
604
- ```
605
-
606
- ### `_.isEmpty (boolean)`
607
-
608
- Returns true if the passed data is empty or has a length of 0.
609
-
610
- - `data::any?`
611
-
612
- ```javascript
613
- _.isEmpty([]); // Returns true
614
- _.isEmpty(''); // Returns true
615
- _.isEmpty('abc'); // Returns false
616
- ```
617
-
618
- ### `_.isUrl (boolean)`
619
-
620
- 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`.
621
-
622
- - `url::string`
623
- - `withProtocol::boolean || false`
624
- - `strict::boolean || false`
625
-
626
- ```javascript
627
- _.isUrl('google.com'); // Returns false
628
- _.isUrl('google.com', true); // Returns true
629
- _.isUrl('https://google.com'); // Returns true
630
- ```
631
-
632
- ### `_.contains (boolean)`
633
-
634
- 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.
635
-
636
- - `str::any[]|string`
637
- - `search::any[]|string`
638
- - `exact::boolean || false`
639
-
640
- ```javascript
641
- _.contains('abc', 'a'); // Returns true
642
- _.contains('abc', 'd'); // Returns false
643
- _.contains('abc', ['a', 'd']); // Returns true
644
- ```
645
-
646
- ### `_.is2dArray (boolean)`
647
-
648
- Returns `true` if the given array is a two-dimensional array.
649
-
650
- - `array::any[]`
651
-
652
- ```javascript
653
- _.is2dArray([1]); // Returns false
654
- _.is2dArray([[1], [2]]); // Returns true
655
- ```
656
-
657
- ### `_.between (boolean)`
658
-
659
- 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.
660
-
661
- - `range::[number, number]`
662
- - `number::number`
663
- - `inclusive::boolean || false`
664
-
665
- ```javascript
666
- _.between([10, 20], 10); // Returns false
667
- _.between([10, 20], 10, true); // Returns true
668
- ```
669
-
670
- ### `_.len (number)`
671
-
672
- Returns the length of any type of data. If the argument value is `null` or `undefined`, `0` is returned.
673
-
674
- - `data::any`
675
-
676
- ```javascript
677
- _.len('12345'); // Returns 5
678
- _.len([1, 2, 3]); // Returns 3
679
- ```
680
-
681
- ### `_.isEmail (boolean)`
682
-
683
- Checks if the given argument value is a valid email.
684
-
685
- - `email::string`
686
-
687
- ```javascript
688
- _.isEmail('abc@def.com'); // Returns true
689
- ```
690
-
691
- ### `_.isBotAgent (boolean)`
692
-
693
- Analyze the user agent value to determine if it's a bot for a search engine. Returns `true` if it's a bot.
694
-
695
- - `userAgent::string`
696
-
697
- ```javascript
698
- _.isBotAgent('Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)'); // Returns true
699
- ```
700
-
701
- ### `_.numberFormat (string)`
702
-
703
- Return number format including comma symbol.
704
-
705
- - `number::number`
706
-
707
- ```javascript
708
- _.numberFormat(1234567); // Returns 1,234,567
709
- ```
710
-
711
- ### `_.fileName (string)`
712
-
713
- Extract the file name from the path. Include the extension if withExtension is `true`.
714
-
715
- - `filePath::string`
716
- - `withExtension::boolean || false`
717
-
718
- ```javascript
719
- _.fileName('C:Temphello.txt'); // Returns 'hello.txt'
720
- _.fileName('C:Temp\file.mp3', true); // Returns 'file.mp3'
721
- ```
722
-
723
- ### `_.fileSize (string)`
724
-
725
- 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.
726
-
727
- - `bytes::number`
728
- - `decimals::number || 2`
729
-
730
- ```javascript
731
- _.fileSize(2000, 3); // Returns '1.953 KB'
732
- _.fileSize(250000000); // Returns '238.42 MB'
733
- ```
734
-
735
- ### `_.fileExt (string)`
736
-
737
- Returns only the extensions in the file path. If unknown, returns 'Unknown'.
738
-
739
- - `filePath::string`
740
-
741
- ```javascript
742
- _.fileExt('C:Temphello.txt'); // Returns 'txt'
743
- _.fileExt('this-is-file.mp3'); // Returns 'mp3'
744
- ```
745
-
746
- ### `_.msToTime (string)`
747
-
748
- 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.
749
-
750
- - `milliseconds::number`
751
- - `withMilliseconds::boolean || false`
752
- - `separator::string || ':'`
753
-
754
- ```javascript
755
- _.msToTime(100000); // 'Returns '00:01:40'
756
- _.msToTime(100000, true, '-'); // Returns '00-01-40.0'
757
- ```
758
-
759
- ### `_.secToTime (string)`
760
-
761
- Converts seconds to hours, minutes, seconds and returns. You can put any separator (String) between hours, minutes, and seconds in the third argument.
762
-
763
- - `seconds::number`
764
- - `onlyHour::boolean || false`
765
- - `separator::string || ':'`
766
-
767
- ```javascript
768
- _.secToTime(3800); // Returns '01:03:20'
769
- _.secToTime(60, '-'); // Returns '00-01-00'
770
- ```
771
-
772
- ### `_.license (string)`
773
-
774
- Returns text in a specific license format based on the author information of the given argument. The argument uses the Object type.
775
-
776
- - `options::LicenseOption{ author: string, email: string?, yearStart: string|number, yearEnd: string?, htmlBr: boolean?, type: 'mit' | 'apache20' }`
14
+ ## [Documentation (Getting Started & Method Reference)](https://qsu.jooy2.com/getting-started)
777
15
 
778
- ```javascript
779
- _.license({
780
- holder: 'example',
781
- email: 'example@example.com',
782
- yearStart: 2020,
783
- yearEnd: 2021,
784
- htmlBr: true
785
- });
786
- ```
16
+ Installing and using the package and defining all the utility methods can be found on the documentation page below: https://qsu.jooy2.com/getting-started
787
17
 
788
- # Contribute
18
+ ## Contribute
789
19
 
790
20
  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.
791
21
 
792
- # License
22
+ ## License
793
23
 
794
24
  Copyright © 2021-2023 [Jooy2](https://jooy2.com) <[jooy2.contact@gmail.com](mailto:jooy2.contact@gmail.com)> Released under the MIT license.
package/dist/index.d.ts CHANGED
@@ -1,11 +1,3 @@
1
- declare interface LicenseOption {
2
- author: string;
3
- email?: string;
4
- yearStart: string | number;
5
- yearEnd?: string;
6
- htmlBr?: boolean;
7
- type: 'mit' | 'apache20';
8
- }
9
1
  declare type PositiveNumber<N extends number> = number extends N ? N : `${N}` extends `-${string}` ? never : N;
10
2
  declare type NumberValueObject = {
11
3
  [key: string]: number;
@@ -69,14 +61,12 @@ export default class Qsu {
69
61
  static between(range: [number, number], number: number, inclusive?: boolean): boolean;
70
62
  static len(data: any): number;
71
63
  static isEmail(email: string): boolean;
72
- static isBotAgent(userAgent: string): boolean;
73
64
  static numberFormat(number: number): string;
74
65
  static fileName(filePath: string, withExtension?: boolean): string;
75
66
  static fileSize<N extends number>(bytes: PositiveNumber<N>, decimals?: number): string;
76
67
  static fileExt(filePath: string): string;
77
68
  static msToTime(milliseconds?: number, withMilliseconds?: boolean, separator?: string): string;
78
69
  static secToTime(seconds?: number, onlyHour?: boolean, separator?: string): string;
79
- static license(options: LicenseOption): string;
80
70
  }
81
71
  export { Qsu };
82
- export declare const sleep: typeof Qsu.sleep, funcTimes: typeof Qsu.funcTimes, getPlatform: typeof Qsu.getPlatform, numRandom: typeof Qsu.numRandom, sum: typeof Qsu.sum, mul: typeof Qsu.mul, sub: typeof Qsu.sub, div: typeof Qsu.div, dayDiff: typeof Qsu.dayDiff, today: typeof Qsu.today, isValidDate: typeof Qsu.isValidDate, dateToYYYYMMDD: typeof Qsu.dateToYYYYMMDD, createDateListFromRange: typeof Qsu.createDateListFromRange, arrShuffle: typeof Qsu.arrShuffle, arrWithDefault: typeof Qsu.arrWithDefault, arrUnique: typeof Qsu.arrUnique, arrWithNumber: typeof Qsu.arrWithNumber, arrRepeat: typeof Qsu.arrRepeat, arrCount: typeof Qsu.arrCount, average: typeof Qsu.average, arrMove: typeof Qsu.arrMove, arrTo1dArray: typeof Qsu.arrTo1dArray, trim: typeof Qsu.trim, removeSpecialChar: typeof Qsu.removeSpecialChar, removeNewLine: typeof Qsu.removeNewLine, capitalizeFirst: typeof Qsu.capitalizeFirst, capitalizeEachWords: typeof Qsu.capitalizeEachWords, strCount: typeof Qsu.strCount, strShuffle: typeof Qsu.strShuffle, strRandom: typeof Qsu.strRandom, strBlindRandom: typeof Qsu.strBlindRandom, truncate: typeof Qsu.truncate, truncateExpect: typeof Qsu.truncateExpect, split: typeof Qsu.split, encrypt: typeof Qsu.encrypt, decrypt: typeof Qsu.decrypt, md5: typeof Qsu.md5, sha1: typeof Qsu.sha1, sha256: typeof Qsu.sha256, encodeBase64: typeof Qsu.encodeBase64, decodeBase64: typeof Qsu.decodeBase64, strUnique: typeof Qsu.strUnique, strToAscii: typeof Qsu.strToAscii, isObject: typeof Qsu.isObject, isEqual: typeof Qsu.isEqual, isEqualStrict: typeof Qsu.isEqualStrict, isEmpty: typeof Qsu.isEmpty, isUrl: typeof Qsu.isUrl, contains: typeof Qsu.contains, is2dArray: typeof Qsu.is2dArray, between: typeof Qsu.between, len: typeof Qsu.len, isEmail: typeof Qsu.isEmail, isBotAgent: typeof Qsu.isBotAgent, numberFormat: typeof Qsu.numberFormat, fileName: typeof Qsu.fileName, fileSize: typeof Qsu.fileSize, fileExt: typeof Qsu.fileExt, msToTime: typeof Qsu.msToTime, secToTime: typeof Qsu.secToTime, license: typeof Qsu.license;
72
+ export declare const sleep: typeof Qsu.sleep, funcTimes: typeof Qsu.funcTimes, getPlatform: typeof Qsu.getPlatform, numRandom: typeof Qsu.numRandom, sum: typeof Qsu.sum, mul: typeof Qsu.mul, sub: typeof Qsu.sub, div: typeof Qsu.div, dayDiff: typeof Qsu.dayDiff, today: typeof Qsu.today, isValidDate: typeof Qsu.isValidDate, dateToYYYYMMDD: typeof Qsu.dateToYYYYMMDD, createDateListFromRange: typeof Qsu.createDateListFromRange, arrShuffle: typeof Qsu.arrShuffle, arrWithDefault: typeof Qsu.arrWithDefault, arrUnique: typeof Qsu.arrUnique, arrWithNumber: typeof Qsu.arrWithNumber, arrRepeat: typeof Qsu.arrRepeat, arrCount: typeof Qsu.arrCount, average: typeof Qsu.average, arrMove: typeof Qsu.arrMove, arrTo1dArray: typeof Qsu.arrTo1dArray, trim: typeof Qsu.trim, removeSpecialChar: typeof Qsu.removeSpecialChar, removeNewLine: typeof Qsu.removeNewLine, capitalizeFirst: typeof Qsu.capitalizeFirst, capitalizeEachWords: typeof Qsu.capitalizeEachWords, strCount: typeof Qsu.strCount, strShuffle: typeof Qsu.strShuffle, strRandom: typeof Qsu.strRandom, strBlindRandom: typeof Qsu.strBlindRandom, truncate: typeof Qsu.truncate, truncateExpect: typeof Qsu.truncateExpect, split: typeof Qsu.split, encrypt: typeof Qsu.encrypt, decrypt: typeof Qsu.decrypt, md5: typeof Qsu.md5, sha1: typeof Qsu.sha1, sha256: typeof Qsu.sha256, encodeBase64: typeof Qsu.encodeBase64, decodeBase64: typeof Qsu.decodeBase64, strUnique: typeof Qsu.strUnique, strToAscii: typeof Qsu.strToAscii, isObject: typeof Qsu.isObject, isEqual: typeof Qsu.isEqual, isEqualStrict: typeof Qsu.isEqualStrict, isEmpty: typeof Qsu.isEmpty, isUrl: typeof Qsu.isUrl, contains: typeof Qsu.contains, is2dArray: typeof Qsu.is2dArray, between: typeof Qsu.between, len: typeof Qsu.len, isEmail: typeof Qsu.isEmail, numberFormat: typeof Qsu.numberFormat, fileName: typeof Qsu.fileName, fileSize: typeof Qsu.fileSize, fileExt: typeof Qsu.fileExt, msToTime: typeof Qsu.msToTime, secToTime: typeof Qsu.secToTime;
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{basename as t,extname as e,win32 as r}from"path";import{randomBytes as a,createCipheriv as o,createDecipheriv as n,createHash as i}from"crypto";export default class s{static sleep(t){return new Promise((e=>{setTimeout(e,t)}))}static funcTimes(t,e){const r=[];for(let a=0;a<t;a+=1)r[a]="function"==typeof e?e.call():e;return r}static getPlatform(){switch(process.platform){case"win32":return"Windows";case"darwin":return"macOS";case"linux":case"aix":case"sunos":case"netbsd":case"openbsd":case"freebsd":case"cygwin":case"android":return"Linux";default:return"Unknown"}}static numRandom(t,e){if(!t&&!e)return Math.random()>.5?1:0;const r=e||t,a=!e||t>=e?null:t;return Math.floor(Math.random()*(a?r-a+1:r+1))+(a||0)}static sum(...t){const e=t.length>0&&"object"==typeof t[0]?t[0]:t;let r=0;for(let t=0,a=e.length;t<a;t+=1)"number"==typeof e[t]&&(r+=e[t]);return r}static mul(...t){const e=t.length>0&&"object"==typeof t[0]?t[0]:t;let r=e[0];for(let t=1,a=e.length;t<a;t+=1)"number"==typeof e[t]&&(r*=e[t]);return r}static sub(...t){const e=t.length>0&&"object"==typeof t[0]?t[0]:t;let r=e[0];for(let t=1,a=e.length;t<a;t+=1)"number"==typeof e[t]&&(r-=e[t]);return r}static div(...t){const e=t.length>0&&"object"==typeof t[0]?t[0]:t;let r=e[0];for(let t=1,a=e.length;t<a;t+=1)"number"==typeof e[t]&&(r/=e[t]);return r}static dayDiff(t,e){const r=e||new Date;return Math.ceil(Math.abs(r.getTime()-t.getTime())/864e5)}static today(t="-",e=!0){const r=new Date,a=r.getMonth()+1,o=r.getDate(),n=[`${a<10?"0":""}${a}`,`${o<10?"0":""}${o}`];return e?n.unshift(r.getFullYear().toString()):n.push(r.getFullYear().toString()),n.join(t)}static isValidDate(t){if(!/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/.test(t))throw new Error("The date format must be 'YYYY-MM-DD'");const e=t.split("-");return/^(?=\d)(?:(?:31(?!.(?:0?[2469]|11))|(?:30|29)(?!.0?2)|29(?=.0?2.(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00)))(?:\x20|$))|(?:2[0-8]|1\d|0?[1-9]))([-./])(?:1[012]|0?[1-9])\1(?:1[6-9]|[2-9]\d)?\d\d(?:(?=\x20\d)\x20|$))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\x20[AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$/.test(`${parseInt(e[2],10)}-${parseInt(e[1],10)}-${parseInt(e[0],10)}`)}static dateToYYYYMMDD(t,e="-"){const r=t.getMonth()+1,a=t.getDate();return`${t.getFullYear()}${e}${r<10?`0${r}`:r}${e}${a<10?`0${a}`:a}`}static createDateListFromRange(t,e){if(!s.isValidDate(s.dateToYYYYMMDD(t))||!s.isValidDate(s.dateToYYYYMMDD(e)))throw new Error("Either the start date or end date is an invalid date.");if(Math.floor((Date.parse(e.toString())-Date.parse(t.toString()))/864e5)<0)throw new Error("The start date is more recent than the end date.");const r=s.dateToYYYYMMDD(e),a=[];let o=t.getFullYear(),n=t.getMonth()+1,i=t.getDate(),c="";const l=(t,e,r)=>`${t}-${e<10?"0":""}${e}-${r<10?"0":""}${r}`;for(;r!==c;){-1!==c.indexOf("-12-31")&&(o+=1,n=1,i=1);const t=l(o,n,i);s.isValidDate(t)?(i+=1,a.push(t),c=t):(n+=1,i=1,c=l(o,n,i))}return a}static arrShuffle(t){if(1===t.length)return t[0];const e=t;for(let r=t.length-1;r>0;r-=1){const a=Math.floor(Math.random()*(r+1));[e[r],e[a]]=[t[a],t[r]]}return e}static arrWithDefault(t,e=0){return e<1?[]:Array(e).fill(t)}static arrUnique(t){return s.is2dArray(t)?t.map((t=>JSON.stringify(t))).reverse().filter(((t,e,r)=>-1===r.indexOf(t,e+1))).reverse().map((t=>JSON.parse(t))):[...new Set(t)]}static arrWithNumber(t,e){if(t>e)throw new Error("`end` is greater than start.");return Array.from({length:e-t+1},((e,r)=>r+t))}static average(t){return t.reduce(((t,e)=>t+e),0)/t.length}static arrMove(t,e,r){const a=t.length;if(a<=e||a<=r)throw new Error("Invalid move params");return t.splice(r,0,t.splice(e,1)[0]),t}static arrTo1dArray(t){const e=t=>{const r=[],a=t.length;for(let o=0;o<a;o+=1)"object"!=typeof t[o]?r.push(t[o]):s.is2dArray(t[o])?r.push(...e(t[o])):r.push(...t[o]);return r};return e(t)}static arrRepeat(t,e){if(!t||e<1||"object"!=typeof t)return[];const r=s.isObject(t),a=[];for(let o=0,n=e;o<n;o+=1)r?a.push(t):a.push(...t);return a}static arrCount(t){const e={};return t.forEach((t=>{e[t]=(e[t]||0)+1})),e}static trim(t,e=!1){return t.trim().replace(e?/\s+/g:/\s{2,}/g,"")}static removeSpecialChar(t,e){return t?t.replace(new RegExp(`[^a-zA-Z가-힣ㄱ-ㅎㅏ-ㅣ0-9぀-ヿ㐀-䶿一-鿿豈-﫿ヲ-゚${e??""}]`,"gi"),""):""}static removeNewLine(t,e=""){return t?t.replace(/(\r\n|\n|\r)/gm,e).trim():""}static capitalizeFirst(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""}static capitalizeEachWords(t,e){if(!t)return"";const r=t.trim().toLowerCase().split(" ");for(let t=0,a=r.length;t<a;t+=1)e&&s.contains(r[t],["in","on","the","at","and","or","of","for","to","that","a","by","it","is","as","are","were","was","nor","an"],!0)||(r[t]=s.capitalizeFirst(r[t]));return s.capitalizeFirst(r.join(" "))}static strCount(t,e){if(!t||!e)return 0;let r=0,a=t.indexOf(e);for(;a>-1;)r+=1,a=t.indexOf(e,a+=e.length);return r}static strShuffle(t){return t?[...t].sort((()=>Math.random()-.5)).join(""):""}static strRandom(t,e){const r=`abcdefghijklmnopqrstuvwxyz0123456789${e}`,a=r.length;let o,n="";for(let e=0;e<t;e+=1)o=r.charAt(Math.floor(Math.random()*a)),o=Math.random()<.5?o.toUpperCase():o,n+=o;return n}static strBlindRandom(t,e,r="*"){if(!t)return"";let a=t,o=0,n=0,i=0;const c=a.length;for(;o<e&&i<c;)n=s.numRandom(0,c),/[a-zA-Z가-힣]/.test(a.substring(n,n+1))&&(a=`${a.substring(0,n+1)}${r}${a.substring(n+2)}`,o+=1),i+=1;return a}static truncate(t,e,r=""){if(!t)return"";let a=t;return t.length>e&&(a=t.substring(0,e)+r),a}static truncateExpect(t,e,r="."){if(!t)return"";let a="";const o=t.split(r);let n=0;for(;a.length<e;)a+=`${o[n]}${r}`,n+=1;return a}static split(t,...e){if(!t)return[];const r=e.length>0&&"object"==typeof e[0]?e[0]:e,a=r.length;let o="",n="";for(let t=0;t<a;t+=1){const e=r[t];e.length>1?n+=`${n.length<1?"":"|"}${e.replace(/\\/g,"\\\\").replace(/\[/g,"\\[").replace(/]/g,"\\]").replace(/\?/g,"\\?").replace(/\./g,"\\.").replace(/\{/g,"\\{").replace(/}/g,"\\}").replace(/\+/g,"\\+")}`:o+="-"===e||"["===e||"]"===e?`\\${e}`:e}return o.length<1&&n.length<1?[t]:(o.length>0&&(o=`[${o}]`,n.length>0&&(n=`|${n}`)),t.split(new RegExp(`${o}${n}+`,"gi")))}static encrypt(t,e,r="aes-256-cbc",n=16){if(!t||t.length<1)return"";const i=a(n),s=o(r,e,i);let c=s.update(t);return c=Buffer.concat([c,s.final()]),`${i.toString("hex")}:${c.toString("hex")}`}static decrypt(t,e,r="aes-256-cbc"){if(!t||t.length<1)return"";const a=t.split(":"),o=n(r,e,Buffer.from(a.shift(),"hex"));let i=o.update(Buffer.from(a.join(":"),"hex"));return i=Buffer.concat([i,o.final()]),i.toString()}static md5(t){return i("md5").update(t).digest("hex")}static sha1(t){return i("sha1").update(t).digest("hex")}static sha256(t){return i("sha256").update(t).digest("hex")}static encodeBase64(t){return Buffer.from(t,"utf8").toString("base64")}static decodeBase64(t){return Buffer.from(t,"base64").toString("utf8")}static strToAscii(t){const e=[];for(let r=0;r<t.length;r+=1)e.push(t.charCodeAt(r));return e}static strUnique(t){return t?[...new Set(t)].join(""):""}static isObject(t){return"object"==typeof t&&!Array.isArray(t)&&null!==t}static isEqual(t,...e){const r=e.length>0&&"object"==typeof e[0]?e[0]:e,a=r.length;for(let e=0;e<a;e+=1)if(r[e]!=t)return!1;return!0}static isEqualStrict(t,...e){const r=e.length>0&&"object"==typeof e[0]?e[0]:e,a=r.length;for(let e=0;e<a;e+=1)if(r[e]!==t)return!1;return!0}static isEmpty(t){if(!t)return!0;switch(typeof t){case"string":return t.length<1;case"object":return Array.isArray(t)?t.length<1:Object.keys(t).length<1;default:return!1}}static isUrl(t,e=!1,r=!1){if(r&&-1===t.indexOf("."))return!1;try{new URL(`${e&&-1===t.indexOf("://")?"https://":""}${t}`).toString()}catch(t){return!1}return!0}static contains(t,e,r=!1){if("string"==typeof e)return!(t.length<1)&&-1!==t.indexOf(e);for(let a=0,o=e.length;a<o;a+=1)if(r){if(t===e[a])return!0}else if(-1!==t.indexOf(e[a]))return!0;return!1}static is2dArray(t){return t.filter(Array.isArray).length>0}static between(t,e,r=!1){const a=Math.min.apply(Math,[t[0],t[1]]),o=Math.max.apply(Math,[t[0],t[1]]);return r?e>=a&&e<=o:e>a&&e<o}static len(t){if(!t)return 0;switch(typeof t){case"object":return Array.isArray(t)?t.length:Object.keys(t).length;case"number":case"bigint":return t.toString().length;case"boolean":return t?4:5;case"function":return t().length;default:return t.length}}static isEmail(t){return/^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/.test(t)}static isBotAgent(t){return/bot|naverbot|google|Googlebot|Googlebot-Mobile|Googlebot-Image|Google favicon|Chrome-Lighthouse|Mediapartners-Google|bingbot|slurp|java|wget|curl|Commons-HttpClient|Python-urllib|libwww|httpunit|nutch|phpcrawl|msnbot|jyxobot|FAST-WebCrawler|FAST Enterprise Crawler|biglotron|teoma|convera|seekbot|gigablast|exabot|ngbot|ia_archiver|GingerCrawler|webmon |httrack|webcrawler|grub.org|UsineNouvelleCrawler|antibot|netresearchserver|speedy|fluffy|bibnum.bnf|findlink|msrbot|panscient|yacybot|AISearchBot|IOI|ips-agent|tagoobot|MJ12bot|dotbot|woriobot|yanga|buzzbot|mlbot|yandexbot|purebot|Linguee Bot|Voyager|CyberPatrol|voilabot|baiduspider|citeseerxbot|spbot|twengabot|postrank|turnitinbot|scribdbot|page2rss|sitebot|linkdex|Adidxbot|blekkobot|ezooms|Mail.RU_Bot|discobot|heritrix|findthatfile|europarchive.org|NerdByNature.Bot|sistrix crawler|ahrefsbot|Aboundex|domaincrawler|wbsearchbot|summify|ccbot|edisterbot|seznambot|ec2linkfinder|gslfbot|aihitbot|intelium_bot|facebookexternalhit|yeti|RetrevoPageAnalyzer|lb-spider|sogou|lssbot|careerbot|wotbox|wocbot|ichiro|DuckDuckBot|lssrocketcrawler|drupact|webcompanycrawler|acoonbot|openindexspider|gnam gnam spider|web-archive-net.com.bot|backlinkcrawler|coccoc|integromedb|content crawler spider|toplistbot|seokicks-robot|it2media-domain-crawler|ip-web-crawler.com|siteexplorer.info|elisabot|proximic|changedetection|blexbot|arabot|WeSEE:Search|niki-bot|CrystalSemanticsBot|rogerbot|360Spider|psbot|InterfaxScanBot|Lipperhey SEO Service|CC Metadata Scaper|g00g1e.net|GrapeshotCrawler|urlappendbot|brainobot|fr-crawler|binlar|SimpleCrawler|Livelapbot|Twitterbot|cXensebot|smtbot|bnf.fr_bot|A6-Indexer|ADmantX|Facebot|OrangeBot|memorybot|AdvBot|MegaIndex|SemanticScholarBot|ltx71|nerdybot|xovibot|BUbiNG|Qwantify|archive.org_bot|Applebot|TweetmemeBot|crawler4j|findxbot|SemrushBot|yoozBot|lipperhey|y!j-asr|Domain Re-Animator Bot|AddThis/i.test(t)}static numberFormat(t){return(new Intl.NumberFormat).format(t)}static fileName(a,o=!1){return a?-1===a.indexOf("/")?o?r.basename(a):r.basename(a,e(a)):o?t(a):t(a,e(a)):""}static fileSize(t,e=2){if(!t||0===t||t<0)return"0 Bytes";const r=Math.floor(Math.log(t)/Math.log(1024));return`${parseFloat((t/1024**r).toFixed(e<0?0:e))} ${["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"][r]}`}static fileExt(t){if(-1===t.indexOf("."))return"Unknown";const e=t.trim().toLowerCase().split(".");return e.length>0?e[e.length-1]:"Unknown"}static msToTime(t=0,e=!1,r=":"){const a=Math.floor(t%1e3/100);let o=Math.floor(t/1e3%60),n=Math.floor(t/6e4%60),i=Math.floor(t/36e5);return i=i<10?`0${i}`:i,n=n<10?`0${n}`:n,o=o<10?`0${o}`:o,`${i}${r}${n}${r}${o}${e?`.${a}`:""}`}static secToTime(t=0,e=!1,r=":"){let a=Math.floor(t%60),o=Math.floor(t/60%60),n=Math.floor(t/3600);return n=n<10?`0${n}`:n,o=o<10?`0${o}`:o,a=a<10?`0${a}`:a,e?n.toString():`${n}${r}${o}${r}${a}`}static license(t){const e=t.htmlBr?"<br/>":"\n",r=`${t.yearStart}${t.yearEnd?`-${t.yearEnd}`:""}`,a=`${t.author}${t.email?` <${t.email}>`:""}`;return"apache20"===t.type.replace(/\.-_,\s/g,"").toLowerCase()?`Copyright ${r} ${a}${e}${e}Licensed under the Apache License, Version 2.0 (the "License");${e}you may not use this file except in compliance with the License.${e}You may obtain a copy of the License at${e}${e} http://www.apache.org/licenses/LICENSE-2.0${e}${e}Unless required by applicable law or agreed to in writing, software${e}distributed under the License is distributed on an "AS IS" BASIS,${e}WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.${e}See the License for the specific language governing permissions and${e}limitations under the License.`:`Copyright (c) ${r} ${a}${e}${e}Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:${e}${e}The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.${e}${e}THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.`}}export{s as Qsu};export const{sleep:sleep,funcTimes:funcTimes,getPlatform:getPlatform,numRandom:numRandom,sum:sum,mul:mul,sub:sub,div:div,dayDiff:dayDiff,today:today,isValidDate:isValidDate,dateToYYYYMMDD:dateToYYYYMMDD,createDateListFromRange:createDateListFromRange,arrShuffle:arrShuffle,arrWithDefault:arrWithDefault,arrUnique:arrUnique,arrWithNumber:arrWithNumber,arrRepeat:arrRepeat,arrCount:arrCount,average:average,arrMove:arrMove,arrTo1dArray:arrTo1dArray,trim:trim,removeSpecialChar:removeSpecialChar,removeNewLine:removeNewLine,capitalizeFirst:capitalizeFirst,capitalizeEachWords:capitalizeEachWords,strCount:strCount,strShuffle:strShuffle,strRandom:strRandom,strBlindRandom:strBlindRandom,truncate:truncate,truncateExpect:truncateExpect,split:split,encrypt:encrypt,decrypt:decrypt,md5:md5,sha1:sha1,sha256:sha256,encodeBase64:encodeBase64,decodeBase64:decodeBase64,strUnique:strUnique,strToAscii:strToAscii,isObject:isObject,isEqual:isEqual,isEqualStrict:isEqualStrict,isEmpty:isEmpty,isUrl:isUrl,contains:contains,is2dArray:is2dArray,between:between,len:len,isEmail:isEmail,isBotAgent:isBotAgent,numberFormat:numberFormat,fileName:fileName,fileSize:fileSize,fileExt:fileExt,msToTime:msToTime,secToTime:secToTime,license:license}=s;
1
+ import{basename as t,extname as e,win32 as r}from"path";import{randomBytes as a,createCipheriv as n,createDecipheriv as i,createHash as s}from"crypto";export default class o{static sleep(t){return new Promise((e=>{setTimeout(e,t)}))}static funcTimes(t,e){const r=[];for(let a=0;a<t;a+=1)r[a]="function"==typeof e?e.call():e;return r}static getPlatform(){switch(process.platform){case"win32":return"Windows";case"darwin":return"macOS";case"linux":case"aix":case"sunos":case"netbsd":case"openbsd":case"freebsd":case"cygwin":case"android":return"Linux";default:return"Unknown"}}static numRandom(t,e){if(!t&&!e)return Math.random()>.5?1:0;const r=e||t,a=!e||t>=e?null:t;return Math.floor(Math.random()*(a?r-a+1:r+1))+(a||0)}static sum(...t){const e=t.length>0&&"object"==typeof t[0]?t[0]:t;let r=0;for(let t=0,a=e.length;t<a;t+=1)"number"==typeof e[t]&&(r+=e[t]);return r}static mul(...t){const e=t.length>0&&"object"==typeof t[0]?t[0]:t;let r=e[0];for(let t=1,a=e.length;t<a;t+=1)"number"==typeof e[t]&&(r*=e[t]);return r}static sub(...t){const e=t.length>0&&"object"==typeof t[0]?t[0]:t;let r=e[0];for(let t=1,a=e.length;t<a;t+=1)"number"==typeof e[t]&&(r-=e[t]);return r}static div(...t){const e=t.length>0&&"object"==typeof t[0]?t[0]:t;let r=e[0];for(let t=1,a=e.length;t<a;t+=1)"number"==typeof e[t]&&(r/=e[t]);return r}static dayDiff(t,e){const r=e||new Date;return Math.ceil(Math.abs(r.getTime()-t.getTime())/864e5)}static today(t="-",e=!0){const r=new Date,a=r.getMonth()+1,n=r.getDate(),i=[`${a<10?"0":""}${a}`,`${n<10?"0":""}${n}`];return e?i.unshift(r.getFullYear().toString()):i.push(r.getFullYear().toString()),i.join(t)}static isValidDate(t){if(!/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/.test(t))throw new Error("The date format must be 'YYYY-MM-DD'");const e=t.split("-");return/^(?=\d)(?:(?:31(?!.(?:0?[2469]|11))|(?:30|29)(?!.0?2)|29(?=.0?2.(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00)))(?:\x20|$))|(?:2[0-8]|1\d|0?[1-9]))([-./])(?:1[012]|0?[1-9])\1(?:1[6-9]|[2-9]\d)?\d\d(?:(?=\x20\d)\x20|$))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\x20[AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$/.test(`${parseInt(e[2],10)}-${parseInt(e[1],10)}-${parseInt(e[0],10)}`)}static dateToYYYYMMDD(t,e="-"){const r=t.getMonth()+1,a=t.getDate();return`${t.getFullYear()}${e}${r<10?`0${r}`:r}${e}${a<10?`0${a}`:a}`}static createDateListFromRange(t,e){if(!o.isValidDate(o.dateToYYYYMMDD(t))||!o.isValidDate(o.dateToYYYYMMDD(e)))throw new Error("Either the start date or end date is an invalid date.");if(Math.floor((Date.parse(e.toString())-Date.parse(t.toString()))/864e5)<0)throw new Error("The start date is more recent than the end date.");const r=o.dateToYYYYMMDD(e),a=[];let n=t.getFullYear(),i=t.getMonth()+1,s=t.getDate(),c="";const l=(t,e,r)=>`${t}-${e<10?"0":""}${e}-${r<10?"0":""}${r}`;for(;r!==c;){-1!==c.indexOf("-12-31")&&(n+=1,i=1,s=1);const t=l(n,i,s);o.isValidDate(t)?(s+=1,a.push(t),c=t):(i+=1,s=1,c=l(n,i,s))}return a}static arrShuffle(t){if(1===t.length)return t[0];const e=t;for(let r=t.length-1;r>0;r-=1){const a=Math.floor(Math.random()*(r+1));[e[r],e[a]]=[t[a],t[r]]}return e}static arrWithDefault(t,e=0){return e<1?[]:Array(e).fill(t)}static arrUnique(t){return o.is2dArray(t)?t.map((t=>JSON.stringify(t))).reverse().filter(((t,e,r)=>-1===r.indexOf(t,e+1))).reverse().map((t=>JSON.parse(t))):[...new Set(t)]}static arrWithNumber(t,e){if(t>e)throw new Error("`end` is greater than start.");return Array.from({length:e-t+1},((e,r)=>r+t))}static average(t){return t.reduce(((t,e)=>t+e),0)/t.length}static arrMove(t,e,r){const a=t.length;if(a<=e||a<=r)throw new Error("Invalid move params");return t.splice(r,0,t.splice(e,1)[0]),t}static arrTo1dArray(t){const e=t=>{const r=[],a=t.length;for(let n=0;n<a;n+=1)"object"!=typeof t[n]?r.push(t[n]):o.is2dArray(t[n])?r.push(...e(t[n])):r.push(...t[n]);return r};return e(t)}static arrRepeat(t,e){if(!t||e<1||"object"!=typeof t)return[];const r=o.isObject(t),a=[];for(let n=0,i=e;n<i;n+=1)r?a.push(t):a.push(...t);return a}static arrCount(t){const e={};return t.forEach((t=>{e[t]=(e[t]||0)+1})),e}static trim(t,e=!1){return t.trim().replace(e?/\s+/g:/\s{2,}/g,"")}static removeSpecialChar(t,e){return t?t.replace(new RegExp(`[^a-zA-Z가-힣ㄱ-ㅎㅏ-ㅣ0-9぀-ヿ㐀-䶿一-鿿豈-﫿ヲ-゚${e??""}]`,"gi"),""):""}static removeNewLine(t,e=""){return t?t.replace(/(\r\n|\n|\r)/gm,e).trim():""}static capitalizeFirst(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""}static capitalizeEachWords(t,e){if(!t)return"";const r=t.trim().toLowerCase().split(" ");for(let t=0,a=r.length;t<a;t+=1)e&&o.contains(r[t],["in","on","the","at","and","or","of","for","to","that","a","by","it","is","as","are","were","was","nor","an"],!0)||(r[t]=o.capitalizeFirst(r[t]));return o.capitalizeFirst(r.join(" "))}static strCount(t,e){if(!t||!e)return 0;let r=0,a=t.indexOf(e);for(;a>-1;)r+=1,a=t.indexOf(e,a+=e.length);return r}static strShuffle(t){return t?[...t].sort((()=>Math.random()-.5)).join(""):""}static strRandom(t,e){const r=`abcdefghijklmnopqrstuvwxyz0123456789${e}`,a=r.length;let n,i="";for(let e=0;e<t;e+=1)n=r.charAt(Math.floor(Math.random()*a)),n=Math.random()<.5?n.toUpperCase():n,i+=n;return i}static strBlindRandom(t,e,r="*"){if(!t)return"";let a=t,n=0,i=0,s=0;const c=a.length;for(;n<e&&s<c;)i=o.numRandom(0,c),/[a-zA-Z가-힣]/.test(a.substring(i,i+1))&&(a=`${a.substring(0,i+1)}${r}${a.substring(i+2)}`,n+=1),s+=1;return a}static truncate(t,e,r=""){if(!t)return"";let a=t;return t.length>e&&(a=t.substring(0,e)+r),a}static truncateExpect(t,e,r="."){if(!t)return"";let a="";const n=t.split(r);let i=0;for(;a.length<e;)a+=`${n[i]}${r}`,i+=1;return a}static split(t,...e){if(!t)return[];const r=e.length>0&&"object"==typeof e[0]?e[0]:e,a=r.length;let n="",i="";for(let t=0;t<a;t+=1){const e=r[t];e.length>1?i+=`${i.length<1?"":"|"}${e.replace(/\\/g,"\\\\").replace(/\[/g,"\\[").replace(/]/g,"\\]").replace(/\?/g,"\\?").replace(/\./g,"\\.").replace(/\{/g,"\\{").replace(/}/g,"\\}").replace(/\+/g,"\\+")}`:n+="-"===e||"["===e||"]"===e?`\\${e}`:e}return n.length<1&&i.length<1?[t]:(n.length>0&&(n=`[${n}]`,i.length>0&&(i=`|${i}`)),t.split(new RegExp(`${n}${i}+`,"gi")))}static encrypt(t,e,r="aes-256-cbc",i=16){if(!t||t.length<1)return"";const s=a(i),o=n(r,e,s);let c=o.update(t);return c=Buffer.concat([c,o.final()]),`${s.toString("hex")}:${c.toString("hex")}`}static decrypt(t,e,r="aes-256-cbc"){if(!t||t.length<1)return"";const a=t.split(":"),n=i(r,e,Buffer.from(a.shift(),"hex"));let s=n.update(Buffer.from(a.join(":"),"hex"));return s=Buffer.concat([s,n.final()]),s.toString()}static md5(t){return s("md5").update(t).digest("hex")}static sha1(t){return s("sha1").update(t).digest("hex")}static sha256(t){return s("sha256").update(t).digest("hex")}static encodeBase64(t){return Buffer.from(t,"utf8").toString("base64")}static decodeBase64(t){return Buffer.from(t,"base64").toString("utf8")}static strToAscii(t){const e=[];for(let r=0;r<t.length;r+=1)e.push(t.charCodeAt(r));return e}static strUnique(t){return t?[...new Set(t)].join(""):""}static isObject(t){return"object"==typeof t&&!Array.isArray(t)&&null!==t}static isEqual(t,...e){const r=e.length>0&&"object"==typeof e[0]?e[0]:e,a=r.length;for(let e=0;e<a;e+=1)if(r[e]!=t)return!1;return!0}static isEqualStrict(t,...e){const r=e.length>0&&"object"==typeof e[0]?e[0]:e,a=r.length;for(let e=0;e<a;e+=1)if(r[e]!==t)return!1;return!0}static isEmpty(t){if(!t)return!0;switch(typeof t){case"string":return t.length<1;case"object":return Array.isArray(t)?t.length<1:Object.keys(t).length<1;default:return!1}}static isUrl(t,e=!1,r=!1){if(r&&-1===t.indexOf("."))return!1;try{new URL(`${e&&-1===t.indexOf("://")?"https://":""}${t}`).toString()}catch(t){return!1}return!0}static contains(t,e,r=!1){if("string"==typeof e)return!(t.length<1)&&-1!==t.indexOf(e);for(let a=0,n=e.length;a<n;a+=1)if(r){if(t===e[a])return!0}else if(-1!==t.indexOf(e[a]))return!0;return!1}static is2dArray(t){return t.filter(Array.isArray).length>0}static between(t,e,r=!1){const a=Math.min.apply(Math,[t[0],t[1]]),n=Math.max.apply(Math,[t[0],t[1]]);return r?e>=a&&e<=n:e>a&&e<n}static len(t){if(!t)return 0;switch(typeof t){case"object":return Array.isArray(t)?t.length:Object.keys(t).length;case"number":case"bigint":return t.toString().length;case"boolean":return t?4:5;case"function":return t().length;default:return t.length}}static isEmail(t){return/^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/.test(t)}static numberFormat(t){return(new Intl.NumberFormat).format(t)}static fileName(a,n=!1){return a?-1===a.indexOf("/")?n?r.basename(a):r.basename(a,e(a)):n?t(a):t(a,e(a)):""}static fileSize(t,e=2){if(!t||0===t||t<0)return"0 Bytes";const r=Math.floor(Math.log(t)/Math.log(1024));return`${parseFloat((t/1024**r).toFixed(e<0?0:e))} ${["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"][r]}`}static fileExt(t){if(-1===t.indexOf("."))return"Unknown";const e=t.trim().toLowerCase().split(".");return e.length>0?e[e.length-1]:"Unknown"}static msToTime(t=0,e=!1,r=":"){const a=Math.floor(t%1e3/100);let n=Math.floor(t/1e3%60),i=Math.floor(t/6e4%60),s=Math.floor(t/36e5);return s=s<10?`0${s}`:s,i=i<10?`0${i}`:i,n=n<10?`0${n}`:n,`${s}${r}${i}${r}${n}${e?`.${a}`:""}`}static secToTime(t=0,e=!1,r=":"){let a=Math.floor(t%60),n=Math.floor(t/60%60),i=Math.floor(t/3600);return i=i<10?`0${i}`:i,n=n<10?`0${n}`:n,a=a<10?`0${a}`:a,e?i.toString():`${i}${r}${n}${r}${a}`}}export{o as Qsu};export const{sleep:sleep,funcTimes:funcTimes,getPlatform:getPlatform,numRandom:numRandom,sum:sum,mul:mul,sub:sub,div:div,dayDiff:dayDiff,today:today,isValidDate:isValidDate,dateToYYYYMMDD:dateToYYYYMMDD,createDateListFromRange:createDateListFromRange,arrShuffle:arrShuffle,arrWithDefault:arrWithDefault,arrUnique:arrUnique,arrWithNumber:arrWithNumber,arrRepeat:arrRepeat,arrCount:arrCount,average:average,arrMove:arrMove,arrTo1dArray:arrTo1dArray,trim:trim,removeSpecialChar:removeSpecialChar,removeNewLine:removeNewLine,capitalizeFirst:capitalizeFirst,capitalizeEachWords:capitalizeEachWords,strCount:strCount,strShuffle:strShuffle,strRandom:strRandom,strBlindRandom:strBlindRandom,truncate:truncate,truncateExpect:truncateExpect,split:split,encrypt:encrypt,decrypt:decrypt,md5:md5,sha1:sha1,sha256:sha256,encodeBase64:encodeBase64,decodeBase64:decodeBase64,strUnique:strUnique,strToAscii:strToAscii,isObject:isObject,isEqual:isEqual,isEqualStrict:isEqualStrict,isEmpty:isEmpty,isUrl:isUrl,contains:contains,is2dArray:is2dArray,between:between,len:len,isEmail:isEmail,numberFormat:numberFormat,fileName:fileName,fileSize:fileSize,fileExt:fileExt,msToTime:msToTime,secToTime:secToTime}=o;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qsu",
3
- "version": "1.1.8",
3
+ "version": "1.2.0",
4
4
  "description": "Quick and Simple Utility for JavaScript",
5
5
  "author": "Jooy2 <jooy2.contact@gmail.com>",
6
6
  "license": "MIT",
@@ -57,18 +57,18 @@
57
57
  ],
58
58
  "devDependencies": {
59
59
  "@types/mocha": "^10.0.1",
60
- "@types/node": "^20.1.3",
61
- "@typescript-eslint/eslint-plugin": "^5.59.5",
62
- "@typescript-eslint/parser": "^5.59.5",
60
+ "@types/node": "^20.3.2",
61
+ "@typescript-eslint/eslint-plugin": "^5.60.1",
62
+ "@typescript-eslint/parser": "^5.60.1",
63
63
  "date-fns": "^2.30.0",
64
- "eslint": "^8.40.0",
64
+ "eslint": "^8.43.0",
65
65
  "eslint-config-airbnb": "^19.0.4",
66
66
  "eslint-config-prettier": "^8.8.0",
67
67
  "eslint-plugin-import": "^2.27.5",
68
68
  "mocha": "^10.2.0",
69
69
  "prettier": "^2.8.8",
70
- "terser": "^5.17.3",
70
+ "terser": "^5.18.2",
71
71
  "ts-node": "^10.9.1",
72
- "typescript": "^5.0.3"
72
+ "typescript": "^5.1.6"
73
73
  }
74
74
  }
@@ -1,4 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "exclude": ["test/**/*.spec.ts"]
4
- }