@stdlib/string-base-right-pad
v0.2.2
Published
Right pad a string.
Downloads
315
Readme
rpad
Right pad a string.
Installation
npm install @stdlib/string-base-right-pad
Usage
var rpad = require( '@stdlib/string-base-right-pad' );
rpad( str, len, pad )
Right pads a string such that the padded string has a length of at least len
.
var str = rpad( 'a', 5, ' ' );
// returns 'a '
str = rpad( 'beep', 10, 'b' );
// returns 'beepbbbbbb'
str = rpad( 'boop', 12, 'beep' );
// returns 'boopbeepbeep'
Notes
An output string is not guaranteed to have a length of exactly
len
, but to have a length of at leastlen
. To generate a padded string having a length equal tolen
var str = rpad( 'boop', 10, 'beep' ); // => length 12 // returns 'boopbeepbeep' str = str.substring( 0, 10 ); // => length 10 // returns 'boopbeepbe' str = str.substring( str.length-10 ); // => length 10 // returns 'opbeepbeep'
Examples
var discreteUniform = require( '@stdlib/random-array-discrete-uniform' );
var papply = require( '@stdlib/utils-papply' );
var papplyRight = require( '@stdlib/utils-papply-right' );
var naryFunction = require( '@stdlib/utils-nary-function' );
var map = require( '@stdlib/utils-map' );
var logEach = require( '@stdlib/console-log-each' );
var rpad = require( '@stdlib/string-base-right-pad' );
// Define a string to pad:
var str = 'beep';
// Generate random lengths:
var lens = discreteUniform( 10, str.length, str.length+10 );
// Create a function for creating padded strings:
var fcn = naryFunction( papply( papplyRight( rpad, 'b' ), str ), 1 );
// Generate padded strings:
var out = map( lens, fcn );
// Print results:
logEach( '%s', out );
Notice
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
Community
License
See LICENSE.
Copyright
Copyright © 2016-2024. The Stdlib Authors.