Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@rowanmanning
Created January 19, 2014 10:57
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rowanmanning/8503266 to your computer and use it in GitHub Desktop.
Save rowanmanning/8503266 to your computer and use it in GitHub Desktop.
Example README for talk: "UX For Your Node Modules"

Paddington

A small library for padding strings in JavaScript. Marmalade-free.

NOTE: PADDINGTON IS NO LONGER UNDER ACTIVE DEVELOPMENT.
If you're interested in maintaining Paddington, please get in touch via GitHub.

Current Version: 1.0.0
Node Support: 0.10.x, 0.11.x
Browser Support: Chrome, Firefox 4+, IE 6+, Safari 4+
Build Status: Travis CI Status

paddington.pad('foo', 5, '_');   // '_foo_'
paddington.left('foo', 5, '_');  // '__foo'
paddington.right('foo', 5, '_'); // 'foo__'

Install

Install Paddington with npm, Bower, or Component:

$ npm install paddington
$ bower install paddington
$ component install rowanmanning/paddington

Alternatively, just include paddington.js via a <script/> in your page.

Usage

If you're using Paddington with Node.js or Component, you can require the module:

var paddington = require('paddington');

In-browser, paddington is available as a global variable.

Paddington exposes the following methods:

paddington.pad( string, length [, char = ' '] )

Return string padded to length by distributing char equally on the left and right.

paddington.left( string, length [, char = ' '] )

Return string padded to length by adding char to the left side of it.

paddington.right( string, length [, char = ' '] )

Return string padded to length by adding char to the right side of it.

Contributing

To contribute to Paddington, clone this repo locally and commit your code on a separate branch.

Please write unit tests for your code, and check that everything works by running the following before opening a pull-request:

$ npm test

License

Paddington is licensed under the MIT license.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment