left-pad

v1.0.0arrow_drop_down
v1.0.0
v0.0.1
STATUS
Passing
DOWNLOADS
53
LICENSE
MIT
VISIBILITY
Public
subject
pad a string to the left.
2 contributors
Like
Use left-pad in your project ?
Copied
npm i @bit/bit.utils.string.left-pad
Set Bit as a scoped registryLearn more
npm config set '@bit:registry' https://node.bit.dev
Component Example
Add dependency... help_outline
Just
import
any of the 1 million components
and packages in Bit or NPM to the example.
import Button from '@bit/grommet.grommet.button';
import Lodash from 'lodash';
leftPad("foo", 5); // => " foo" leftPad("foobar", 6); // => "foobar" leftPad(1, 2, "0"); // => "01"
modified
chevron_left
chevron_right
leftPad (
str:string,
len:number,
ch:string
) : string

pad a string to the left.

Example
leftPad('foo', 5) // => "  foo"
 leftPad('foobar', 6) // => "foobar"
 leftPad(1, 2, '0') // => "01"
Arguments
str: string

string to pad

len: number

total

ch: string

char to use for padding

Returns
string

modified string

Test Summary

#leftPad() should pad string foo to a total char size of 5

Pass

#leftPad() should not pad string foobar any char as 6 is the original str length

Pass

#leftPad() should pad string 1 with one 0

Pass