https://github.com/jneidel/strpad
Combine left right and center pad modules in lack of a working alternative
https://github.com/jneidel/strpad
javascript node-module pad padding str string-manipulation
Last synced: 10 months ago
JSON representation
Combine left right and center pad modules in lack of a working alternative
- Host: GitHub
- URL: https://github.com/jneidel/strpad
- Owner: jneidel
- License: gpl-3.0
- Created: 2018-04-09T04:32:36.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2019-07-08T18:05:46.000Z (over 6 years ago)
- Last Synced: 2025-03-24T15:59:56.626Z (10 months ago)
- Topics: javascript, node-module, pad, padding, str, string-manipulation
- Language: JavaScript
- Size: 22.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# strpad
> Combine left, right and center pad modules in lack of a working alternative
[](https://travis-ci.org/jneidel/strpad)
[](https://github.com/jneidel/strpad/blob/master/licence)
[](https://www.npmjs.com/package/strpad)
See [String.prototype.padStart()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart) (left) and [String.prototype.padEnd()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padEnd) (right) for builtin functions.
## Install
[](https://www.npmjs.com/package/strpad)
```
$ npm install strpad
```
## Usage
```js
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] )
```js
strpad.left( "foo", 5 );
//=> " foo"
strpad.left( "bar", 5, "-" );
//=> "--bar"
```
See bultin function: [String.prototype.padStart()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart).
### strpad.right( str, padding, [filler] )
```js
strpad.right( "foo", 5 );
//=> "foo "
strpad.right( "bar", 5, "-" );
//=> "bar--"
```
See builtin function: [String.prototype.padEnd()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padEnd).
### strpad.center( str, padding, [filler] )
```js
strpad.center( "foo", 5 );
//=> " foo "
strpad.center( "bar", 5, "-" );
//=> "-bar-"
```
See original module: [@fav/text.pad](https://github.com/sttk/fav-text.pad).
## Test
```
$ npm run test
```
## License
GPLv3 © [Jonathan Neidel](http://jneidel.com)