Method code for $string.center()

[Turn off line numbering]
  1: arg text, width, @args;
  2: var fill, sides;
  3: 
  4: // args[1] <op> == what to fill the left|right side with.
  5: // args[2] <op> == if exists also fill the right side.
  6: [(fill ?= " "), (sides ?= 'left)] = args;
  7: if (sides == 'both)
  8:     return strfmt("%*{" + fill + "}c", width, text);
  9: else
 10:     return pad("", (width - strlen(text)) / 2, fill) + text;

// Created 27-Mar-1995 as a part of ColdCore, see: @help Credit

Tlon