JSPM

  • Created
  • Published
  • Downloads 245026
  • Score
    100M100P100Q155817F
  • License BSD-3-Clause

Left and right string padding

Package Exports

  • pad
  • pad/lib/colors

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (pad) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Node.js pad

Build Status

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

Usage

pad('pad', 5)      // "pad  "
pad(5, 'pad')      // "  pad"
pad('pad', 5, '+') // "pad++"
pad(5, 'pad', '+') // "++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".

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

Left padding occurs when the first argument is a number and the second argument is a string.

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

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

Right padding occurs when the first argument is a string and the second argument is a number.

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

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