@@ -29,36 +29,37 @@ import string from '@poppinss/string'
29
29
30
30
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
31
31
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
32
+
32
33
** Table of Contents**
33
34
34
- - [ excerpt] ( #excerpt )
35
- - [ truncate] ( #truncate )
36
- - [ slug] ( #slug )
37
- - [ interpolate] ( #interpolate )
38
- - [ plural] ( #plural )
39
- - [ singular] ( #singular )
40
- - [ pluralize] ( #pluralize )
41
- - [ isPlural] ( #isplural )
42
- - [ isSingular] ( #issingular )
43
- - [ camelCase] ( #camelcase )
44
- - [ capitalCase] ( #capitalcase )
45
- - [ dashCase] ( #dashcase )
46
- - [ dotCase] ( #dotcase )
47
- - [ noCase] ( #nocase )
48
- - [ pascalCase] ( #pascalcase )
49
- - [ sentenceCase] ( #sentencecase )
50
- - [ snakeCase] ( #snakecase )
51
- - [ titleCase] ( #titlecase )
52
- - [ wordWrap] ( #wordwrap )
53
- - [ htmlEscape] ( #htmlescape )
54
- - [ random] ( #random )
55
- - [ toSentence] ( #tosentence )
56
- - [ condenseWhitespace] ( #condensewhitespace )
57
- - [ ordinal] ( #ordinal )
58
- - [ seconds.(parse/format)] ( #secondsparseformat )
59
- - [ milliseconds.(parse/format)] ( #millisecondsparseformat )
60
- - [ bytes.(parse/format)] ( #bytesparseformat )
61
- - [ String builder] ( #string-builder )
35
+ - [ excerpt] ( #excerpt )
36
+ - [ truncate] ( #truncate )
37
+ - [ slug] ( #slug )
38
+ - [ interpolate] ( #interpolate )
39
+ - [ plural] ( #plural )
40
+ - [ singular] ( #singular )
41
+ - [ pluralize] ( #pluralize )
42
+ - [ isPlural] ( #isplural )
43
+ - [ isSingular] ( #issingular )
44
+ - [ camelCase] ( #camelcase )
45
+ - [ capitalCase] ( #capitalcase )
46
+ - [ dashCase] ( #dashcase )
47
+ - [ dotCase] ( #dotcase )
48
+ - [ noCase] ( #nocase )
49
+ - [ pascalCase] ( #pascalcase )
50
+ - [ sentenceCase] ( #sentencecase )
51
+ - [ snakeCase] ( #snakecase )
52
+ - [ titleCase] ( #titlecase )
53
+ - [ wordWrap] ( #wordwrap )
54
+ - [ htmlEscape] ( #htmlescape )
55
+ - [ random] ( #random )
56
+ - [ toSentence] ( #tosentence )
57
+ - [ condenseWhitespace] ( #condensewhitespace )
58
+ - [ ordinal] ( #ordinal )
59
+ - [ seconds.(parse/format)] ( #secondsparseformat )
60
+ - [ milliseconds.(parse/format)] ( #millisecondsparseformat )
61
+ - [ bytes.(parse/format)] ( #bytesparseformat )
62
+ - [ String builder] ( #string-builder )
62
63
- [ Contributing] ( #contributing )
63
64
- [ Code of Conduct] ( #code-of-conduct )
64
65
- [ License] ( #license )
@@ -564,6 +565,59 @@ Following are some examples.
564
565
| ` htmlEscape('<ta\'&g">') ` | ` '<ta'&g">' ` |
565
566
| ` htmlEscape('foo<<bar') ` | ` 'foo<<bar' ` |
566
567
568
+ ### justify
569
+
570
+ Justify text of multiple columns as per the define max width. Columns smaller than the provided max width will be padded with empty spaces or the provided ` indent ` char.
571
+
572
+ ``` ts
573
+ import string from ' @poppinss/string'
574
+
575
+ const output = string .justify ([' help' , ' serve' , ' make:controller' ], {
576
+ width: 20 ,
577
+ })
578
+
579
+ /**
580
+ [
581
+ 'help ',
582
+ 'serve ',
583
+ 'make:controller ',
584
+ ]
585
+ */
586
+ ```
587
+
588
+ By default the columns are left aligned. However, they can also be right aligned using the ` align ` option.
589
+
590
+ ``` ts
591
+ const output = string .justify ([' help' , ' serve' , ' make:controller' ], {
592
+ width: 20 ,
593
+ align: ' right' ,
594
+ })
595
+
596
+ /**
597
+ [
598
+ ' help',
599
+ ' serve',
600
+ ' make:controller',
601
+ ]
602
+ */
603
+ ```
604
+
605
+ If the columns contains ANSI escape sequences, then you must specify a custom ` getLength ` method to compute the column length without counting ANSI escape sequences.
606
+
607
+ ``` ts
608
+ import stringWidth from ' string-width'
609
+
610
+ const output = string .justify ([' help' , ' serve' , ' make:controller' ], {
611
+ width: 20 ,
612
+ align: ' right' ,
613
+ /**
614
+ * The `string-width` package returns the length of the string
615
+ * without accounting for ANSI escape sequences
616
+ */
617
+ getLength : (chunk ) => stringWidth (chunk ),
618
+ })
619
+ ```
620
+
567
621
### random
568
622
569
623
Generate a cryptographically secure random string of a given length. The output value is URL safe base64 encoded string.
0 commit comments