4 A wide-character aware text alignment function for use in terminals / on the
10 var align = require('wide-align')
12 // Note that if you view this on a unicode console, all of the slashes are
13 // aligned. This is because on a console, all narrow characters are
14 // an en wide and all wide characters are an em. In browsers, this isn't
15 // held to and wide characters like "古" can be less than two narrow
16 // characters even with a fixed width font.
18 console.log(align.center('abc', 10)) // ' abc '
19 console.log(align.center('古古古', 10)) // ' 古古古 '
20 console.log(align.left('abc', 10)) // 'abc '
21 console.log(align.left('古古古', 10)) // '古古古 '
22 console.log(align.right('abc', 10)) // ' abc'
23 console.log(align.right('古古古', 10)) // ' 古古古'
28 #### `align.center(str, length)` → `str`
30 Returns *str* with spaces added to both sides such that that it is *length*
31 chars long and centered in the spaces.
33 #### `align.left(str, length)` → `str`
35 Returns *str* with spaces to the right such that it is *length* chars long.
37 ### `align.right(str, length)` → `str`
39 Returns *str* with spaces to the left such that it is *length* chars long.
43 These functions were originally taken from
44 [cliui](https://npmjs.com/package/cliui). Changes include switching to the
45 MUCH faster pad generation function from
46 [lodash](https://npmjs.com/package/lodash), making center alignment pad
47 both sides and adding left alignment.