UNPKG

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