Left and right string padding for NodeJs
CoffeeScript
Latest commit 711cc45 Sep 1, 2016 @wdavidw bump to version 1.0.1

README.md

Build Status

 _   _           _        _____          _ 
| \ | |         | |      |  __ \        | |
|  \| | ___   __| | ___  | |__) |_ _  __| |
| . ` |/ _ \ / _` |/ _ \ |  ___/ _` |/ _` |
| |\  | (_) | (_| |  __/ | |  | (_| | (_| |
|_| \_|\___/ \__,_|\___| |_|   \__,_|\__,_| New BSD License

Node Pad is a simple function to pad strings in the left and right directions.

pad(length, text, [options]): Left padding

Node Pad does left padding when the first argument is a number and the second argument is a string.

var pad = require('pad');
pad(5, 'pad', '--').should.eql('--pad');

pad(text, length, [options]): Right padding

Node Pad does right padding when the first argument is a string and the second argument is a number.

var pad = require('pad');
pad('pad', 6).should.eql('pad   ');

Options

Options are provided as a third argument and are all optional. A string argument it is interpreted as the "char" option. Accepted options include:

  • char (string)
    The character used to fill the gap.
  • colors (boolean)
    Ajust to hidden terminal color characters, you may also use require 'pad/lib/colors' to avoid passing this option.
  • strip (boolean)
    Remove characters from text if length smaller than text length, default to "false".

Installing

Via npm:

npm install pad

Via git (or downloaded tarball), copy or link the project from a discoverable Node directory:

git clone http://github.com/wdavidw/node-pad.git

Testing

Clone the repo, install the development dependencies and run the suite:

git clone http://github.com/wdavidw/node-pad.git .
npm install
make test