Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/iarna/wide-align
https://github.com/iarna/wide-align
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/iarna/wide-align
- Owner: iarna
- License: isc
- Created: 2015-12-16T05:32:58.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2021-10-18T12:33:10.000Z (almost 3 years ago)
- Last Synced: 2024-05-18T13:41:19.769Z (4 months ago)
- Language: JavaScript
- Size: 51.8 KB
- Stars: 20
- Watchers: 3
- Forks: 14
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
wide-align
----------A wide-character aware text alignment function for use in terminals / on the
console.### Usage
```
var align = require('wide-align')// Note that if you view this on a unicode console, all of the slashes are
// aligned. This is because on a console, all narrow characters are
// an en wide and all wide characters are an em. In browsers, this isn't
// held to and wide characters like "古" can be less than two narrow
// characters even with a fixed width font.console.log(align.center('abc', 10)) // ' abc '
console.log(align.center('古古古', 10)) // ' 古古古 '
console.log(align.left('abc', 10)) // 'abc '
console.log(align.left('古古古', 10)) // '古古古 '
console.log(align.right('abc', 10)) // ' abc'
console.log(align.right('古古古', 10)) // ' 古古古'
```### Functions
#### `align.center(str, length)` → `str`
Returns *str* with spaces added to both sides such that that it is *length*
chars long and centered in the spaces.#### `align.left(str, length)` → `str`
Returns *str* with spaces to the right such that it is *length* chars long.
### `align.right(str, length)` → `str`
Returns *str* with spaces to the left such that it is *length* chars long.
### Origins
These functions were originally taken from
[cliui](https://npmjs.com/package/cliui). Changes include switching to the
MUCH faster pad generation function from
[lodash](https://npmjs.com/package/lodash), making center alignment pad
both sides and adding left alignment.