left-pad

v1.0.0arrow_drop_down
v1.0.0
v0.0.1
STATUS
Passing
DOWNLOADS
114
LICENSE
MIT
VISIBILITY
Public
PUBLISHED
7 years ago
SIZE
574 B
pad a string to the left.
2 contributors
Install left-pad as a package?
Copied
npm i @bit/bit.utils.string.left-pad
Set Bit as a scoped registryLearn more
npm config set '@bit:registry' https://node.bit.cloud
Component Example
React
React
Vue
Angular
React Native
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';
toggle layout
No preview available
modifieddraft
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
Help and resources