@@ -88,6 +88,10 @@ await existentFile.move()
88
88
await existentFile .remove ()
89
89
await existentFile .create ()
90
90
await existentFile .getContent ()
91
+
92
+ // You can use safeRemove method to delete the file without any exception if it does no exists
93
+
94
+ await File .safeRemove (existentFile .path )
91
95
```
92
96
93
97
---
@@ -145,6 +149,93 @@ await existentFolder.copy()
145
149
await existentFolder .move ()
146
150
await existentFolder .remove ()
147
151
await existentFolder .create ()
152
+
153
+ // You can use safeRemove method to delete the folder without any exception if it does no exists
154
+
155
+ await Folder .safeRemove (existentFile .path )
156
+ ```
157
+
158
+ ---
159
+
160
+ ### Is
161
+
162
+ > Use Is to validate if value is from some type or is empty, is uuid, is cpf, is cep, etc...
163
+
164
+ ``` ts
165
+ import { Is } from ' @secjs/utils'
166
+
167
+ // Is class is a validator. It validates if the value matches the name of the function and returns a boolean
168
+
169
+ Is .Empty (' ' ) // true
170
+ Is .Empty ([]) // true
171
+ Is .Empty ([1 ]) // false
172
+ Is .Empty ({}) // true
173
+ Is .Empty ({ hello: ' world' }) // false
174
+ Is .Empty (' ' ) // true
175
+ Is .Empty (' hello' ) // false
176
+
177
+ Is .Uuid (' not-valid-uuid' ) // false
178
+ Is .Cep (' not-valid-cep' ) // false
179
+ Is .Cpf (' not-valid-cpf' ) // false
180
+ Is .Cnpj (' not-valid-cnpj' ) // false
181
+
182
+ Is .String (' value' ) // true
183
+ Is .Undefined (' value' ) // false
184
+ Is .Null (' value' ) // false
185
+ Is .Boolean (' value' ) // false
186
+ Is .Buffer (' value' ) // false
187
+ Is .Number (' value' ) // false
188
+ Is .Object (' value' ) // false
189
+ Is .Date (' value' ) // false
190
+ Is .Array (' value' ) // false
191
+ Is .Regexp (' value' ) // false
192
+ Is .Error (' value' ) // false
193
+ Is .Function (' value' ) // false
194
+ Is .Class (' value' ) // false
195
+ Is .Integer (' value' ) // false
196
+ Is .Float (' value' ) // false
197
+ ```
198
+
199
+ ---
200
+
201
+ ### String
202
+
203
+ > Use String to generate random strings, normalizations and case changes
204
+
205
+ ``` ts
206
+ import { String } from ' @secjs/utils'
207
+
208
+ // With String you can change the case of strings
209
+
210
+ const string = ' Hello world'
211
+ const capitalize = true
212
+
213
+ String .toCamelCase (string ) // 'helloWorld'
214
+ String .toPascalCase (string ) // 'HelloWorld'
215
+ String .toSnakeCase (string ) // 'hello_world'
216
+ String .toDotCase (string ) // 'hello.world'
217
+ String .toSentenceCase (string ) // 'Hello world'
218
+ String .toNoCase (string ) // 'hello world'
219
+ String .toDashCase (string ) // 'hello-world'
220
+ String .toDashCase (string , capitalize ) // 'Hello-World'
221
+
222
+ // You can generate random strings by size and random hexadecimal colors
223
+
224
+ String .generateRandom (10 ) // 'GpXuZScThi'
225
+ String .generateRandomColor () // '#d5063b'
226
+
227
+ // You can put a string in plural or in singular and in ordinal number
228
+
229
+ String .pluralize (string ) // 'Hello worlds'
230
+ String .singularize (String .pluralize (string )) // 'Hello world'
231
+ String .ordinalize (' 1' ) // '1st'
232
+ String .ordinalize (' 2' ) // '2nd'
233
+ String .ordinalize (' 3' ) // '3rd'
234
+ String .ordinalize (' 10' ) // '10th'
235
+
236
+ // And you can also normalize base64 string
237
+
238
+ String .normalizeBase64 (' +++///===' ) // '---___'
148
239
```
149
240
150
241
---
@@ -376,12 +467,29 @@ console.log(isUuid) // true
376
467
``` ts
377
468
import { Parser } from ' @secjs/utils'
378
469
470
+ // Convert a string to array using a separator
471
+
379
472
const string1 = ' 1,2,3'
380
- const parsed1 = Parser .stringToArray (string1 )
473
+ const separator = ' ,'
474
+ const parsed1 = Parser .stringToArray (string1 , separator )
381
475
382
476
console .log (parsed1 ) // ['1', '2', '3']
383
477
```
384
478
479
+ ``` ts
480
+ // Convert an array to string using separators
481
+
482
+ Parser .arrayToString ([' 1' , ' 2' , ' 3' , ' 4' ]) // '1, 2, 3 and 4'
483
+ Parser .arrayToString ([' 1' , ' 2' , ' 3' , ' 4' ], // '1|2|3-4'
484
+ { separator: ' |' , lastSeparator: ' -' }
485
+ )
486
+
487
+ // Pair separator is only for and array of two indexes
488
+ Parser .arrayToString ([' 1' , ' 2' ], { // '1_2'
489
+ pairSeparator: ' _' ,
490
+ })
491
+ ```
492
+
385
493
``` ts
386
494
const string2 = ' aaaasadzczaaa21313'
387
495
const parsed2 = Parser .stringToNumber (string2 )
@@ -406,16 +514,51 @@ console.log(parsed4) // { joao: 'joao', email: 'lenonsec7@gmail.com' }
406
514
```
407
515
408
516
``` ts
409
- const bytes = 1024 * 1024 * 1024 // 1GB
410
- const decimals = 4
517
+ const message = ' Link: https://google.com'
518
+
519
+ // Convert url to and HTML href
411
520
412
- Parser .bytesToSize ( bytes , decimals ) // Example: 1.0932 GB
521
+ console . log ( Parser .linkToHref ( message )) // Link: <a href="https://google.com">https://google.com</a>
413
522
```
414
523
415
524
``` ts
416
- const message = ' Link: https://google.com'
525
+ // Convert number size to bytes
526
+
527
+ Parser .sizeToByte (1024 ) // '1KB'
528
+ Parser .sizeToByte (1048576 ) // '1MB'
529
+ Parser .sizeToByte (1073741824 ) // '1GB'
530
+ Parser .sizeToByte (1099511627776 ) // '1TB'
531
+ Parser .sizeToByte (1125899906842624 ) // '1PB'
532
+
533
+ // Convert bytes to number size
534
+
535
+ Parser .byteToSize (' 1KB' ) // 1024
536
+ Parser .byteToSize (' 1MB' ) // 1048576
537
+ Parser .byteToSize (' 1GB' ) // 1073741824
538
+ Parser .byteToSize (' 1TB' ) // 1099511627776
539
+ Parser .byteToSize (' 1PB' ) // 1125899906842624
540
+ ```
541
+
542
+ ``` ts
543
+ // Convert time string to ms
544
+
545
+ Parser .timeToMs (' 2 days' ) // 172800000
546
+ Parser .timeToMs (' 1d' ) // 86400000
547
+ Parser .timeToMs (' 10h' ) // 36000000
548
+ Parser .timeToMs (' -10h' ) // -36000000
549
+ Parser .timeToMs (' 1 year' ) // 31557600000
550
+ Parser .timeToMs (' -1 year' ) // -31557600000
551
+
552
+ // Convert ms to time string
417
553
418
- console .log (urlify (message )) // Link: <a href="https://google.com">https://google.com</a>
554
+ const long = true
555
+
556
+ Parser .msToTime (172800000 , long ) // '2 days'
557
+ Parser .msToTime (86400000 ) // 1d
558
+ Parser .msToTime (36000000 ) // 10h
559
+ Parser .msToTime (- 36000000 ) // -10h
560
+ Parser .msToTime (31557600000 , long ) // 1 year
561
+ Parser .msToTime (- 31557600000 , long ) // -1 year
419
562
```
420
563
421
564
---
@@ -494,18 +637,6 @@ import { download } from '@secjs/utils'
494
637
495
638
---
496
639
497
- ### randomColor
498
-
499
- > Use randomColor to generate a random Hexadecimal color
500
-
501
- ``` js
502
- import { randomColor } from ' @secjs/utils'
503
-
504
- console .log (randomColor ()) // #7059c1
505
- ```
506
-
507
- ---
508
-
509
640
### scheduler
510
641
511
642
> Use scheduler to execute some function based on MS
@@ -566,20 +697,6 @@ console.log(paginate(array, total, pagination))
566
697
567
698
---
568
699
569
- ### random
570
-
571
- > Use random to generate random strings by the length you want using crypto
572
-
573
- ``` js
574
- import { random } from ' @secjs/utils'
575
-
576
- const randomStringWith10Chars = await random (10 )
577
-
578
- console .log (randomStringWith10Chars) // qwiortlkps
579
- ```
580
-
581
- ---
582
-
583
700
### sleep
584
701
585
702
> Use sleep to let you code sleep for sometime
@@ -619,44 +736,6 @@ console.log(distance) // The distance in Kilometers (KM)
619
736
620
737
---
621
738
622
- ### isCpf
623
-
624
- > Validate if is a valid CPF Document or not.
625
-
626
- ``` js
627
- import { isCpf } from ' @secjs/utils'
628
-
629
- // CPF (911.881.600-28) Generated using https://4devs.com.br
630
-
631
- console .log (isCpf (91188160028 )) // true
632
- console .log (isCpf (" 91188160028" )) // true
633
- console .log (isCpf (" 911.881.600-28" )) // true
634
-
635
- console .log (isCpf (" 911.881.600-29" )) // false
636
- console .log (isCpf (" 000.000.000-00" )) // false
637
- ```
638
-
639
- ---
640
-
641
- ### isCnpj
642
-
643
- > Validate if is a valid CNPJ Document or not.
644
-
645
- ``` js
646
- import { isCnpj } from ' @secjs/utils'
647
-
648
- // CNPJ (77.111.157/0001-19) Generated using https://4devs.com.br
649
-
650
- console .log (isCnpj (77111157000119 )) // true
651
- console .log (isCnpj (" 77111157000119" )) // true
652
- console .log (isCnpj (" 77.111.157/0001-19" )) // true
653
-
654
- console .log (isCnpj (" 77.111.157/0001-20" )) // false
655
- console .log (isCnpj (" 00.000.000/0000-00" )) // false
656
- ```
657
-
658
- ---
659
-
660
739
## License
661
740
662
741
Made with 🖤 by [ jlenon7] ( https://github.com/jlenon7 ) :wave :
0 commit comments