Skip to content
This repository has been archived by the owner on Apr 23, 2021. It is now read-only.

Latest commit

 

History

History
35 lines (30 loc) · 2.2 KB

File metadata and controls

35 lines (30 loc) · 2.2 KB

String.prototype.padStart( maxLength [ , fillString ] )

When the padStart method is called, the following steps are taken:

  1. Let O be ? RequireObjectCoercible(this value).
  2. Let S be ? ToString(O).
  3. Let intMaxLength be ? ToLength(maxLength).
  4. Let stringLength be the number of elements in S.
  5. If intMaxLength is not greater than stringLength, return S.
  6. If fillString is undefined, let filler be a string consisting solely of the code unit U+0020 (SPACE).
  7. Else, let filler be ? ToString(fillString).
  8. If filler is the empty String, return S.
  9. Let fillLen be intMaxLength - stringLength.
  10. Let truncatedStringFiller be a new String value consisting of repeated concatenations of filler truncated to length fillLen.
  11. Return a new String value computed by the concatenation of truncatedStringFiller and S.

Note: the first argument maxLength will be clamped such that it can be no smaller than the length of the this value. Note: The optional second argument fillString defaults to " " (a string consisting of U+0020 SPACE).

String.prototype.padEnd( maxLength [ , fillString ] )

When the padEnd method is called, the following steps are taken:

  1. Let O be ? RequireObjectCoercible(this value).
  2. Let S be ? ToString(O).
  3. Let intMaxLength be ? ToLength(maxLength).
  4. Let stringLength be the number of elements in S.
  5. If intMaxLength is not greater than stringLength, return S.
  6. If fillString is undefined, let filler be a string consisting solely of the code unit U+0020 (SPACE).
  7. Else, let filler be ? ToString(fillString).
  8. If filler is the empty String, return S.
  9. Let fillLen be intMaxLength - stringLength.
  10. Let truncatedStringFiller be a new String value consisting of repeated concatenations of filler truncated to length fillLen.
  11. Return a new String value computed by the concatenation of S and truncatedStringFiller.

Note: the first argument maxLength will be clamped such that it can be no smaller than the length of the this value. Note: The optional second argument fillString defaults to " " (a string consisting of U+0020 SPACE).