- Source:
Methods
pad(subject, paddingCharacter, expectedLength, fromopt) → {String}
Adds characters to strings, which are not yet of a defined expected length.
A usual use-case for this would be, to add zeroes to a number, to fit a format like ISO dates.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
subject |
String | the string to pad |
||
paddingCharacter |
String | the character to use for padding, only first character is used |
||
expectedLength |
Number | the number of characters, the result has to have at least |
||
from |
String |
<optional> |
'left' | the number of characters, the result has to have at least |
- Source:
Returns:
the padded value, will always be cast to a string
- Type
- String
Example
pad(1, '0', 4, 'right')
=> '1000'