Pads the given string on the left and right sides if it's shorter than the given length.

Syntax

TypeScript
import { pad } from '@opentf/std';

pad(str: string, length = 0, chars = ' '): string;

length must be a non-negative finite integer.

Examples

TypeScript
pad('abc', 8) //=> '  abc   '

pad('abc', 8, '_-') //=> '_-abc_-_'

pad('abc', 3) //=> 'abc'
Last updated on
Edit this page