Pads a string
- Calling Convention:
The number of characters to pad the string by. If this value is positive the characters will be added to the end of the string. If negative they will be added to the beginning of the string. If the string is longer than this number, the returned string will be unchanged.
Note, if you pass a non-numeric value, this WILL throw an error.
- character Optional
- The character to be repeated. If omitted a space will be used. Should you pass a string longer than one character to this routine, only the first character of that string will be used!
- The new padded string result.
console.log(String('test').pad(8, 'x')); // 'testxxxx' console.log(String('test').pad(-8, 'x')); // 'xxxxtest'