Need private packages and team management tools?Check out npm Teams »

strpad

1.1.0 • Public • Published

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

Install

npm i strpad

DownloadsWeekly Downloads

1

Version

1.1.0

License

GLPv3

Unpacked Size

38.1 kB

Total Files

4

Last publish

Collaborators

  • avatar