This repository was archived by the owner on Dec 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathspec.emu
93 lines (85 loc) · 4.9 KB
/
spec.emu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<!doctype html>
<meta charset="utf8">
<link rel="stylesheet" href="./spec.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/styles/github.min.css">
<script src="./spec.js"></script>
<pre class="metadata">
title: String.prototype.trimStart/trimEnd (plus trimLeft/trimRight)
stage: 3
contributors: Sebastian Markbåge, Tom Schuster
</pre>
<emu-clause id="String.prototype.trim">
<h1>String.prototype.trim ( )</h1>
<p>The following steps are taken:</p>
<del class="block">
<emu-alg>
1. Let _O_ be ? RequireObjectCoercible(*this* value).
1. Let _S_ be ? ToString(_O_).
1. Let _T_ be a 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 “Space_Separator” (“Zs”), 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_.
</emu-alg>
</del>
<ins class="block">
<emu-alg>
1. Let _S_ be *this* value.
1. Return ? TrimString(_S_, `"start+end"`).
</emu-alg>
</ins>
<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>
<emu-clause id="String.prototype.trimStart">
<h1>String.prototype.trimStart ( )</h1>
<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="String.prototype.trimEnd">
<h1>String.prototype.trimEnd ( )</h1>
<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-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 “Zs”, 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-annex id="sec-additional-ecmascript-features-for-web-browsers" namespace=annexB normative>
<h1>Additional ECMAScript Features for Web Browsers</h1>
<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>