Create a gist now

Instantly share code, notes, and snippets.

Writing a Friendly README. This a companion-gist to the post: http://rowanmanning.com/posts/writing-a-friendly-readme/

Paddington

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

NPM version Node.js version support Build status Code coverage Dependencies MIT licensed

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

Table of Contents

Requirements

Paddington requires the following to run:

Usage

Paddington is easiest to use when installed with npm:

npm install paddington

Then you can load the module into your code with a require call:

var paddington = require('paddington');

The paddington object has the following methods.

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

Pad a string, distributing the padding equally on the left and right.

string is the string we want to pad (String).
length is the length we want to pad it to (Number).
character is an optional character to pad with (String, defaults to " ").
return is the padded string (String).

// Example
paddington.pad('foo', 5); // returns " foo "
paddington.pad('foo', 5, '_'); // returns "_foo_"

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

Pad a string on the left hand side. This method has the same signature as paddington.pad.

// Example
paddington.left('foo', 5); // returns " foo"
paddington.left('foo', 5, '_'); // returns "__foo"

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

Pad a string on the right hand side. This method has the same signature as paddington.pad.

// Example
paddington.right('foo', 5); // returns "foo  "
paddington.right('foo', 5, '_'); // returns "foo__"

Longer strings

When a string is longer than the specified pad length, it will not be trimmed. In this case the string will be returned as-is:

paddington.pad('foobar', 5); // returns "foobar"

Error handling

All of the methods documented above will throw a TypeError if an argument is not of the expected type.

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 run the linter before opening a pull-request:

make test  # run all unit tests
make lint  # run the linter

You can find more detail in our contributing guide. Participation in this open source project is subject to a Code of Conduct.

Support and Migration

Paddington major versions are normally supported for 6 months after their last minor release. This means that patch-level changes will be added and bugs will be fixed. The table below outlines the end-of-support dates for major versions, and the last minor release for that version.

We also maintain a migration guide to help you migrate.

Major Version Last Minor Release Support End Date
❤️ 3 N/A N/A
⌛️ 2 2.1 2016-07-04
🚫 1 1.4 2015-01-26

If you're opening issues related to these, please mention the version that the issue relates to.

License

Paddington is licensed under the MIT license.
Copyright © 2016, Rowan Manning

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 run the linter before opening a pull-request:

make test  # run all unit tests
make lint  # run the linter

You can find more detail in our contributing guide. Participation in this open source project is subject to a Code of Conduct.

Paddington

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

Paddington

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

NPM version Node.js version support Build status Code coverage Dependencies MIT licensed

Paddington

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

NPM version Node.js version support Build status Code coverage Dependencies MIT licensed

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

License

Paddington is licensed under the MIT license.
Copyright © 2016, Rowan Manning

Requirements

Paddington requires the following to run:

Support and Migration

Paddington major versions are normally supported for 6 months after their last minor release. This means that patch-level changes will be added and bugs will be fixed. The table below outlines the end-of-support dates for major versions, and the last minor release for that version.

We also maintain a migration guide to help you migrate.

Major Version Last Minor Release Support End Date
❤️ 3 N/A N/A
⌛️ 2 2.1 2016-07-04
🚫 1 1.4 2015-01-26

If you're opening issues related to these, please mention the version that the issue relates to.

Usage

Paddington is easiest to use when installed with npm:

npm install paddington

Then you can load the module into your code with a require call:

var paddington = require('paddington');

The paddington object has the following methods.

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

Pad a string, distributing the padding equally on the left and right.

string is the string we want to pad (String).
length is the length we want to pad it to (Number).
character is an optional character to pad with (String, defaults to " ").
return is the padded string (String).

// Example
paddington.pad('foo', 5); // returns " foo "
paddington.pad('foo', 5, '_'); // returns "_foo_"

Longer strings

When a string is longer than the specified pad length, it will not be trimmed. In this case the string will be returned as-is:

paddington.pad('foobar', 5); // returns "foobar"

Error handling

All of the methods documented above will throw a TypeError if an argument is not of the expected type.

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