Skip to content

padCenter ​

Pads both sides of a string to center it within a target length.

padCenter ​

Signature ​

typescript
function padCenter(str: string, length: number, char?: string): string

Parameters ​

  • str - The string to pad
  • length - The target length
  • char - The character to pad with (default: space)

Returns ​

Centered string.

Examples ​

typescript
import { padCenter } from 'strio'

padCenter('hello', 11)
// "   hello   "

padCenter('test', 10, '-')
// "---test---"

See Also ​

Released under the MIT License.