Skip to content

centerText

centerText(text, width): string

Centers the given text in a field of the given width, padding with spaces on both sides.

string

the word or phrase to center

number

the total width of the field (including text)

string

the centered string (or the original text if width ≤ text.length)