Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ES7 Proposal: String.prototype.trimLeft(), String.prototype.trimRight()

String.prototype.trimRight()

This function interprets a string value as a sequence of code points, as described in 6.1.4.

The following steps are taken:

  1. Let O be CheckObjectCoercible(this value).
  2. Let S be ToString(O).
  3. ReturnIfAbrupt(S).
  4. Let T be a String value that is a copy of S with trailing white space removed. The definition of white space is the union of WhiteSpace and )LineTerminator. When determining whether a Unicode code point is in Unicode general category “Zs”, code unit sequences are interpreted as UTF-16 encoded code point sequences as specified in 6.1.4.
  5. Return T.

NOTE The trimRight function is intentionally generic; it does not require that its this value be a String object. Therefore, it can be transferred to other kinds of objects for use as a method.

String.prototype.trimLeft()

This function interprets a string value as a sequence of code points, as described in 6.1.4.

The following steps are taken:

  1. Let O be CheckObjectCoercible(this value).
  2. Let S be ToString(O).
  3. ReturnIfAbrupt(S).
  4. Let T be a String value that is a copy of S with leading white space removed. The definition of white space is the union of WhiteSpace and )LineTerminator. When determining whether a Unicode code point is in Unicode general category “Zs”, code unit sequences are interpreted as UTF-16 encoded code point sequences as specified in 6.1.4.
  5. Return T.

NOTE The trimRight function is intentionally generic; it does not require that its this value be a String object. Therefore, it can be transferred to other kinds of objects for use as a method.

@bterlson

This comment has been minimized.

Copy link

@bterlson bterlson commented Apr 16, 2014

👍

@ianwjhalliday

This comment has been minimized.

Copy link

@ianwjhalliday ianwjhalliday commented Apr 21, 2014

Typo ")LineTerminator"?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.