Padding
Adds padding to given string.
padStart
Section titled “padStart”Pads the start (left) of a string with a specified fill string a certain number of times.
Parameters
Section titled “Parameters”val
:string
- The original string.fillString?
:string
- The string to use for padding (default is ’ ’ |U+0020
| single whitespace ).repeatCount?
:number
- The number of times to repeat the fill string (default is 1).maxLen
:number
|undefined
- The maximum length of the resulting string.
Returns: string
Section titled “Returns: string”- The start/left padded string.
function padStart( val: string, fillString?: string, repeatCount?: number, maxLen?: number): string
// Basic UsagepadStart('hello', '+', 3) // +++hello
// Limiting total lengthpadStart('hello', '-', 4, 8) // ---hello
padEnd
Section titled “padEnd”Pads the end (right) of a string with a specified fill string a certain number of times.
Parameters
Section titled “Parameters”val
:string
- The original string.fillString?
:string
- The string to use for padding (default is ’ ’ |U+0020
| single whitespace ).repeatCount?
:number
- The number of times to repeat the fill string (default is 1).maxLen
:number
|undefined
- The maximum length of the resulting string.
Returns: string
Section titled “Returns: string”- The end/right padded string.
function padEnd( val: string, fillString?: string, repeatCount?: number, maxLen?: number): string
// Basic UsagepadEnd('hello', '+', 3) // +++hello
// Limiting total lengthpadEnd('hello', '-', 4, 8) // ---hello
padBidirectional
Section titled “padBidirectional”Pads a string with a specified fill string a certain number of times on both ends.
Parameters
Section titled “Parameters”val
:string
- The original string.fillString?
:string
- The string to use for padding (default is ’ ’ |U+0020
| single whitespace ).PaddingOptions.repeatCount?
:number
- The number of times to repeat the fill string (default is 1).PaddingOptions.maxLen?
:number
|undefined
- The maximum length of the resulting string.PaddingOptions.bias
:PaddingBias
- To control the distribution of padding on both sides (default is PaddingBias.END).
Returns: string
Section titled “Returns: string”- The padded string.
enum PaddingBias { START = 0, END = 1}
interface PaddingOptions { repeatCount?: number maxLen?: number bias?: PaddingBias}
function padBidirectional( val: string, fillString?: string, paddingOptions?: PaddingOptions): string
// Basic usagepadBidirectional('hello', '*', {repeatCount: 2}); // '**hello**'
// Limiting total lengthpadBidirectional('world', '-', {repeatCount: 3, maxLen: 10}); // '--world---'
// Controlling padding distributionpadBidirectional('example', '*', {repeatCount: 2, maxLen: 10, bias: PaddingBias.START}); // '**example*'