Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

strpad

jneidel37GLPv31.1.0

Combine left, right and center pad modules in lack of a working alternative

stringpad, string, pad, padding, leftpad, left-pad, left, rightpad, right-pad, right, centerpad, center-pad, center

readme

strpad

Combine left, right and center pad modules in lack of a working alternative

Travis Build Status Licence GPLv3 Npm Downloads

See String.prototype.padStart() (left) and String.prototype.padEnd() (right) for builtin functions.

Install

Npm Version

$ npm install strpad

Usage

const strpad = require( "strpad" );

strpad.left( "foo", 5 );
//=> "  foo"

strpad.right( "foo", 5 );
//=> "foo  "

strpad.center( "foo", 5 );
//=> " foo "

/* With filler: */

strpad.left( "bar", 5, "-" );
//=> "--bar"

strpad.right( "bar", 5, "-" );
//=> "bar--"

strpad.center( "bar", 5, "-" );
//=> "-bar-"

API

strpad.left( str, padding, [filler] )

strpad.left( "foo", 5 );
//=> "  foo"

strpad.left( "bar", 5, "-" );
//=> "--bar"

See bultin function: String.prototype.padStart().

strpad.right( str, padding, [filler] )

strpad.right( "foo", 5 );
//=> "foo  "

strpad.right( "bar", 5, "-" );
//=> "bar--"

See builtin function: String.prototype.padEnd().

strpad.center( str, padding, [filler] )

strpad.center( "foo", 5 );
//=> " foo "

strpad.center( "bar", 5, "-" );
//=> "-bar-"

See original module: @fav/text.pad.

Test

$ npm run test

License

GPLv3 © Jonathan Neidel