UNPKG

1.7 kBMarkdownView Raw
1[![Build Status](https://secure.travis-ci.org/wdavidw/node-pad.png)](http://travis-ci.org/wdavidw/node-pad)
2
3Node Pad is a simple function to pad strings in both left and right directions.
4
5## Exemples
6
7```javascript
8pad('pad', 5) # "pad "
9pad(5, 'pad') # " pad"
10pad('pad', 5, '+') # "pad++"
11pad(5, 'pad', '+') # "++pad"
12```
13
14## Left padding: `pad(length, text, [options])`
15
16Left padding occurs when the first argument is a number and the second
17argument is a string.
18
19```javascript
20var pad = require('pad');
21pad(5, 'pad', '-').should.eql('-pad');
22```
23
24## Right padding: `pad(text, length, [options])`
25
26Right padding occurs when the first argument is a string and the second
27argument is a number.
28
29```javascript
30var pad = require('pad');
31pad('pad', 6).should.eql('pad ');
32```
33
34## Options
35
36Options are provided as a third argument and are all optional. A string argument
37it 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
50Via [npm](http://github.com/isaacs/npm):
51
52```bash
53npm install pad
54```
55
56Via git (or downloaded tarball), copy or link the project from a discoverable Node directory:
57
58```bash
59git clone http://github.com/wdavidw/node-pad.git
60```
61
62## Testing
63
64Clone the repo, install the development dependencies and run the suite:
65
66```bash
67git clone http://github.com/wdavidw/node-pad.git .
68npm install
69make test
70```