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 = ; strpadleft "foo" 5 ;//=> " foo" strpadright "foo" 5 ;//=> "foo " strpad;//=> " foo " /* With filler: */ strpadleft "bar" 5 "-" ;//=> "--bar" strpadright "bar" 5 "-" ;//=> "bar--" strpad;//=> "-bar-"
API
strpad.left( str, padding, [filler] )
strpadleft "foo" 5 ;//=> " foo" strpadleft "bar" 5 "-" ;//=> "--bar"
See bultin function: String.prototype.padStart().
strpad.right( str, padding, [filler] )
strpadright "foo" 5 ;//=> "foo " strpadright "bar" 5 "-" ;//=> "bar--"
See builtin function: String.prototype.padEnd().
strpad.center( str, padding, [filler] )
strpad;//=> " foo " strpad;//=> "-bar-"
See original module: @fav/text.pad.
Test
$ npm run test
License
GPLv3 © Jonathan Neidel