Skip to content

Function: pad()

ts
function pad(
   value, 
   length, 
   fillString?): string;

Pads a string on both sides to a target length. 将字符串两侧填充到目标长度。

Parameters

ParameterTypeDefault valueDescription
valuestringundefinedThe source string / 源字符串
lengthnumberundefinedThe target length / 目标长度
fillStringstring' 'The padding content / 填充内容

Returns

string

The padded string / 填充后的字符串

Example

ts
pad('hi', 6)
// => '  hi  '

Since

1.2.0

Released under the MIT License.