1 | [![Build Status](https://secure.travis-ci.org/wdavidw/node-pad.png)](http://travis-ci.org/wdavidw/node-pad)
|
2 |
|
3 | Node Pad is a simple function to pad strings in both left and right directions.
|
4 |
|
5 | ## Exemples
|
6 |
|
7 | ```javascript
|
8 | pad('pad', 5) # "pad "
|
9 | pad(5, 'pad') # " pad"
|
10 | pad('pad', 5, '+') # "pad++"
|
11 | pad(5, 'pad', '+') # "++pad"
|
12 | ```
|
13 |
|
14 | ## Left padding: `pad(length, text, [options])`
|
15 |
|
16 | Left padding occurs when the first argument is a number and the second
|
17 | argument is a string.
|
18 |
|
19 | ```javascript
|
20 | var pad = require('pad');
|
21 | pad(5, 'pad', '-').should.eql('-pad');
|
22 | ```
|
23 |
|
24 | ## Right padding: `pad(text, length, [options])`
|
25 |
|
26 | Right padding occurs when the first argument is a string and the second
|
27 | argument is a number.
|
28 |
|
29 | ```javascript
|
30 | var pad = require('pad');
|
31 | pad('pad', 6).should.eql('pad ');
|
32 | ```
|
33 |
|
34 | ## Options
|
35 |
|
36 | Options are provided as a third argument and are all optional. A string argument
|
37 | it is interpreted as the "char" option. Accepted options include:
|
38 |
|
39 | * `char` (string)
|
40 | The character used to fill the gap.
|
41 | * `colors` (boolean)
|
42 | Ajust to hidden terminal color characters, you may also use
|
43 | `require 'pad/lib/colors'` to avoid passing this option.
|
44 | * `strip` (boolean)
|
45 | Remove characters from text if length smaller than text length, default to
|
46 | "false".
|
47 |
|
48 | ## Installing
|
49 |
|
50 | Via [npm](http://github.com/isaacs/npm):
|
51 |
|
52 | ```bash
|
53 | npm install pad
|
54 | ```
|
55 |
|
56 | Via git (or downloaded tarball), copy or link the project from a discoverable Node directory:
|
57 |
|
58 | ```bash
|
59 | git clone http://github.com/wdavidw/node-pad.git
|
60 | ```
|
61 |
|
62 | ## Testing
|
63 |
|
64 | Clone the repo, install the development dependencies and run the suite:
|
65 |
|
66 | ```bash
|
67 | git clone http://github.com/wdavidw/node-pad.git .
|
68 | npm install
|
69 | make test
|
70 | ```
|