strpad

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

Usage no npm install needed!

<script type="module">
  import strpad from 'https://cdn.skypack.dev/strpad';
</script>

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