Skip to main content

pad

$pad

Pads a string to a minimum width.

Parameters

  • width (number, required): Target minimum length.
  • char (string, optional): Pad character. Defaults to ' '.
  • side ('left'|'right', optional): Which side to pad. Defaults to 'left'.

Example

// Zero-pad a numeric string to 6 digits
new Schema('string').transformer({$pad: {width: 6, char: '0'}})
// '42' → '000042'

// Right-pad a string to fill a fixed-width column
new Schema('string').transformer({$pad: {width: 20, side: 'right'}})
// 'Alice' → 'Alice '

// Pad a month/day to 2 digits
new Schema('number').transformer(['$string', {$pad: {width: 2, char: '0'}}])
// 3 → '03'