Name |
Date |
Size |
#Lines |
LOC |
||
---|---|---|---|---|---|---|
.. | - | - | ||||
CHANGELOG.md | D | 12-May-2024 | 1,017 | 37 | 16 | |
LICENSE | D | 12-May-2024 | 731 | 14 | 11 | |
README.md | D | 12-May-2024 | 2.8 KiB | 80 | 44 | |
index.js | D | 12-May-2024 | 1.3 KiB | 62 | 46 | |
package.json | D | 12-May-2024 | 1.6 KiB | 71 | 70 |
README.md
1# ansi-align 2 3> align-text with ANSI support for CLIs 4 5[](https://travis-ci.org/nexdrew/ansi-align) 6[](https://coveralls.io/github/nexdrew/ansi-align?branch=master) 7[](https://github.com/conventional-changelog/standard-version) 8 9Easily center- or right- align a block of text, carefully ignoring ANSI escape codes. 10 11E.g. turn this: 12 13<img width="281" alt="ansi text block no alignment :(" src="https://cloud.githubusercontent.com/assets/1929625/14937509/7c3076dc-0ed7-11e6-8c16-4f6a4ccc8346.png"> 14 15Into this: 16 17<img width="278" alt="ansi text block center aligned!" src="https://cloud.githubusercontent.com/assets/1929625/14937510/7c3ca0b0-0ed7-11e6-8f0a-541ca39b6e0a.png"> 18 19## Install 20 21```sh 22npm install --save ansi-align 23``` 24 25```js 26var ansiAlign = require('ansi-align') 27``` 28 29## API 30 31### `ansiAlign(text, [opts])` 32 33Align the given text per the line with the greatest [`string-width`](https://github.com/sindresorhus/string-width), returning a new string (or array). 34 35#### Arguments 36 37- `text`: required, string or array 38 39 The text to align. If a string is given, it will be split using either the `opts.split` value or `'\n'` by default. If an array is given, a different array of modified strings will be returned. 40 41- `opts`: optional, object 42 43 Options to change behavior, see below. 44 45#### Options 46 47- `opts.align`: string, default `'center'` 48 49 The alignment mode. Use `'center'` for center-alignment, `'right'` for right-alignment, or `'left'` for left-alignment. Note that the given `text` is assumed to be left-aligned already, so specifying `align: 'left'` just returns the `text` as is (no-op). 50 51- `opts.split`: string or RegExp, default `'\n'` 52 53 The separator to use when splitting the text. Only used if text is given as a string. 54 55- `opts.pad`: string, default `' '` 56 57 The value used to left-pad (prepend to) lines of lesser width. Will be repeated as necessary to adjust alignment to the line with the greatest width. 58 59### `ansiAlign.center(text)` 60 61Alias for `ansiAlign(text, { align: 'center' })`. 62 63### `ansiAlign.right(text)` 64 65Alias for `ansiAlign(text, { align: 'right' })`. 66 67### `ansiAlign.left(text)` 68 69Alias for `ansiAlign(text, { align: 'left' })`, which is a no-op. 70 71## Similar Packages 72 73- [`center-align`](https://github.com/jonschlinkert/center-align): Very close to this package, except it doesn't support ANSI codes. 74- [`left-pad`](https://github.com/camwest/left-pad): Great for left-padding but does not support center alignment or ANSI codes. 75- Pretty much anything by the [chalk](https://github.com/chalk) team 76 77## License 78 79ISC © Contributors 80