strpad
v1.1.0
Published
Combine left, right and center pad modules in lack of a working alternative
Downloads
35
Maintainers
Readme
strpad
Combine left, right and center pad modules in lack of a working alternative
See String.prototype.padStart() (left) and String.prototype.padEnd() (right) for builtin functions.
Install
$ 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