Skip to content

Commit

Permalink
Normative: Add String.prototype.{trimStart/trimEnd} (+ trimLeft/trimR…
Browse files Browse the repository at this point in the history
…ight) (#1275)
  • Loading branch information
evilpie authored and bterlson committed Feb 20, 2019
1 parent 3e2943d commit 517f09a
Showing 1 changed file with 60 additions and 4 deletions.
64 changes: 60 additions & 4 deletions spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -28831,14 +28831,54 @@ <h1>String.prototype.trim ( )</h1>
<p>This function interprets a String value as a sequence of UTF-16 encoded code points, as described in <emu-xref href="#sec-ecmascript-language-types-string-type"></emu-xref>.</p>
<p>The following steps are taken:</p>
<emu-alg>
1. Let _O_ be ? RequireObjectCoercible(*this* value).
1. Let _S_ be ? ToString(_O_).
1. Let _T_ be the String value that is a copy of _S_ with both leading and 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 &ldquo;Space_Separator&rdquo; (&ldquo;Zs&rdquo;), code unit sequences are interpreted as UTF-16 encoded code point sequences as specified in <emu-xref href="#sec-ecmascript-language-types-string-type"></emu-xref>.
1. Return _T_.
1. Let _S_ be *this* value.
1. Return ? TrimString(_S_, `"start+end"`).
</emu-alg>
<emu-note>
<p>The `trim` 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.</p>
</emu-note>

<emu-clause id="sec-trimstring" aoid="TrimString">
<h1>Runtime Semantics: TrimString ( _string_, _where_ )</h1>
<p>The abstract operation TrimString is called with arguments _string_ and _where_, and interprets the String value _string_ as a sequence of UTF-16 encoded code points, as described in <emu-xref href="#sec-ecmascript-language-types-string-type"></emu-xref>. It performs the following steps:</p>
<emu-alg>
1. Let _str_ be ? RequireObjectCoercible(_string_).
1. Let _S_ be ? ToString(_str_).
1. If _where_ is `"start"`, let _T_ be a String value that is a copy of _S_ with leading white space removed.
1. Else if _where_ is `"end"`, let _T_ be a String value that is a copy of _S_ with trailing white space removed.
1. Else,
1. Assert: _where_ is `"start+end"`.
1. Let _T_ be a String value that is a copy of _S_ with both leading and trailing white space removed.
1. Return _T_.
</emu-alg>
<p>The definition of white space is the union of |WhiteSpace| and |LineTerminator|. When determining whether a Unicode code point is in Unicode general category &ldquo;Space_Separator&rdquo; (&ldquo;Zs&rdquo;), code unit sequences are interpreted as UTF-16 encoded code point sequences as specified in <emu-xref href="#sec-ecmascript-language-types-string-type"></emu-xref>.</p>
</emu-clause>
</emu-clause>

<emu-clause id="sec-string.prototype.trimend">
<h1>String.prototype.trimEnd ( )</h1>
<p>This function interprets a String value as a sequence of UTF-16 encoded code points, as described in <emu-xref href="#sec-ecmascript-language-types-string-type"></emu-xref>.</p>
<p>The following steps are taken:</p>
<emu-alg>
1. Let _S_ be *this* value.
1. Return ? TrimString(_S_, `"end"`).
</emu-alg>
<emu-note>
<p>The `trimEnd` 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.</p>
</emu-note>
</emu-clause>

<emu-clause id="sec-string.prototype.trimstart">
<h1>String.prototype.trimStart ( )</h1>
<p>This function interprets a String value as a sequence of UTF-16 encoded code points, as described in <emu-xref href="#sec-ecmascript-language-types-string-type"></emu-xref>.</p>
<p>The following steps are taken:</p>
<emu-alg>
1. Let _S_ be *this* value.
1. Return ? TrimString(_S_, `"start"`).
</emu-alg>
<emu-note>
<p>The `trimStart` 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.</p>
</emu-note>
</emu-clause>

<emu-clause id="sec-string.prototype.valueof">
Expand Down Expand Up @@ -40480,6 +40520,22 @@ <h1>String.prototype.sup ( )</h1>
1. Return ? CreateHTML(_S_, `"sup"`, `""`, `""`).
</emu-alg>
</emu-annex>

<emu-annex id="String.prototype.trimleft">
<h1>String.prototype.trimLeft ( )</h1>
<emu-note>
<p>The property `trimStart` is preferred. The `trimLeft` property is provided principally for compatibility with old code. It is recommended that the `trimStart` property be used in new ECMAScript code.</p>
</emu-note>
<p>The initial value of the `trimLeft` property is the same function object as the initial value of the `String.prototype.trimStart` property.</p>
</emu-annex>

<emu-annex id="String.prototype.trimright">
<h1>String.prototype.trimRight ( )</h1>
<emu-note>
<p>The property `trimEnd` is preferred. The `trimRight` property is provided principally for compatibility with old code. It is recommended that the `trimEnd` property be used in new ECMAScript code.</p>
</emu-note>
<p>The initial value of the `trimRight` property is the same function object as the initial value of the `String.prototype.trimEnd` property.</p>
</emu-annex>
</emu-annex>

<emu-annex id="sec-additional-properties-of-the-date.prototype-object">
Expand Down

0 comments on commit 517f09a

Please sign in to comment.