UNPKG

3.76 kBMarkdownView Raw
1# center-align [![NPM version](https://img.shields.io/npm/v/center-align.svg?style=flat)](https://www.npmjs.com/package/center-align) [![NPM monthly downloads](https://img.shields.io/npm/dm/center-align.svg?style=flat)](https://npmjs.org/package/center-align) [![NPM total downloads](https://img.shields.io/npm/dt/center-align.svg?style=flat)](https://npmjs.org/package/center-align) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/center-align.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/center-align)
2
3> Center-align the text in a string.
4
5## Install
6
7Install with [npm](https://www.npmjs.com/):
8
9```sh
10$ npm install --save center-align
11```
12
13## Usage
14
15```js
16var center = require('center-align');
17center(val, width);
18```
19
20**Params**
21
22* `val` **{String|Array}**: the string or array of strings to center align
23* `width` **{Number}** (optional): the total width of each line in the expected result, after it's centered.
24
25## Examples
26
27```js
28console.log(center('foo')); //=> 'foo' (does nothing)
29console.log(center('foo', 12)); //=> ' foo '
30console.log(center('foo', 10)); //=> ' foo '
31console.log(center('foo', 8)); //=> ' foo '
32```
33
34### Multiple lines
35
36If expected `width` is not provided, the _length of the longest line_ will be used.
37
38**Example**
39
40If used on the following:
41
42```js
43// value can be a string, or an array of strings
44center([
45 'Lorem ipsum dolor sit amet,',
46 'consectetur adipiscing',
47 'elit, sed do eiusmod tempor incididunt',
48 'ut labore et dolore',
49 'magna aliqua. Ut enim ad minim',
50 'veniam, quis'
51]);
52```
53
54The result would be:
55
56```
57 Lorem ipsum dolor sit amet,
58 consectetur adipiscing
59elit, sed do eiusmod tempor incididunt
60 ut labore et dolore
61 magna aliqua. Ut enim ad minim
62 veniam, quis
63```
64
65## About
66
67### Related projects
68
69* [align-text](https://www.npmjs.com/package/align-text): Align the text in a string. | [homepage](https://github.com/jonschlinkert/align-text "Align the text in a string.")
70* [justified](https://www.npmjs.com/package/justified): Wrap words to a specified length and justified the text. | [homepage](https://github.com/jonschlinkert/justified "Wrap words to a specified length and justified the text.")
71* [right-align](https://www.npmjs.com/package/right-align): Right-align the text in a string. | [homepage](https://github.com/jonschlinkert/right-align "Right-align the text in a string.")
72* [word-wrap](https://www.npmjs.com/package/word-wrap): Wrap words to a specified length. | [homepage](https://github.com/jonschlinkert/word-wrap "Wrap words to a specified length.")
73
74### Contributing
75
76Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
77
78### Building docs
79
80_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
81
82To generate the readme, run the following command:
83
84```sh
85$ npm install -g verbose/verb#dev verb-generate-readme && verb
86```
87
88### Running tests
89
90Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
91
92```sh
93$ npm install && npm test
94```
95
96### Author
97
98**Jon Schlinkert**
99
100* [github/jonschlinkert](https://github.com/jonschlinkert)
101* [twitter/jonschlinkert](https://twitter.com/jonschlinkert)
102
103### License
104
105Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert).
106Released under the [MIT License](LICENSE).
107
108***
109
110_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on May 26, 2017._
\No newline at end of file