├── .gitignore ├── README.md ├── build.sh ├── package.json └── spec.emu /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | npm-debug.log 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # String.prototype.trimStart / String.prototype.trimEnd 2 | 3 | ECMAScript proposal, specs, tests, and reference implementation for String.prototype.trimStart/trimEnd (plus **trimLeft/trimRight**). 4 | 5 | **Stage 4** 6 | 7 | This proposal is complete and already merged into [ECMA262 specification](https://tc39.es/ecma262/). See the specification text here. 8 | 9 | ## Rationale 10 | ES5 standardized `String.prototype.trim`. All major engines have also implemented corresponding `trimLeft` and `trimRight` functions - without any standard specification. 11 | For consistency with `padStart`/`padEnd` we propose `trimStart` and `trimEnd` and `trimLeft`/`trimRight` as aliases required for web compatibility. 12 | 13 | ## Specification 14 | You can view the spec in [ecmarkup](spec.emu) or rendered as [HTML](https://tc39.github.io/proposal-string-left-right-trim/). 15 | 16 | ## Naming / Aliasing 17 | For consistency with `padStart`/`padEnd` the standard functions will be `trimStart` and `trimEnd`, however for web compatilibity `trimLeft` will alias `trimStart` and `trimRight` will alias `trimEnd`. This means `String.prototype.trimRight.name` will change from `"trimRight"` to `"trimEnd"` in most engines. The spec author does not expect this to cause any breakage. 18 | 19 | ## Test262 Coverage 20 | 21 | [PR open](https://github.com/tc39/test262/pull/1246) 22 | 23 | ## Status of This Proposal 24 | 25 | This initial proposal was drafted by [@sebmarkbage](https://github.com/sebmarkbage) and the updated spec was drafted by [@evilpie](https://github.com/evilpie/) with input from [@ljharb](https://github.com/ljharb). 26 | 27 | This proposal is currently at [stage 4](https://github.com/tc39/ecma262) of the [process](https://tc39.github.io/process-document/). 28 | 29 | Designated TC39 reviewers: Jordan Harband + Daniel Ehrenberg 30 | 31 | ## Implementations 32 | 33 | - [V8](https://bugs.chromium.org/p/v8/issues/detail?id=6530), in Chrome 66+ 34 | - [SpiderMonkey](https://bugzilla.mozilla.org/show_bug.cgi?id=1434007#c12), in Firefox 61+ 35 | - [JSC](https://bugs.webkit.org/show_bug.cgi?id=26590), in Safari 12+ 36 | - [ChakraCore](https://github.com/Microsoft/ChakraCore/pull/5693) 37 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | BUILD_DIR=`mktemp -dt ecmascript-string-left-right` || exit 1 6 | trap "rm -rf $BUILD_DIR" EXIT 7 | mkdir "$BUILD_DIR/out" 8 | 9 | ./node_modules/.bin/ecmarkup \ 10 | spec.emu \ 11 | "$BUILD_DIR/out/index.html" \ 12 | --js "$BUILD_DIR/out/spec.js" \ 13 | --css "$BUILD_DIR/out/spec.css" 14 | 15 | # Replace gh-pages with a new commit without touching the working directory. 16 | GIT_WORK_TREE="$BUILD_DIR/out" GIT_INDEX_FILE="$BUILD_DIR/index" \ 17 | git add index.html spec.js spec.css 18 | TREE=`GIT_WORK_TREE="$BUILD_DIR/out" GIT_INDEX_FILE="$BUILD_DIR/index" \ 19 | git write-tree` 20 | COMMIT=`git commit-tree "$TREE" -m 'build gh-pages'` 21 | git branch -f gh-pages $COMMIT 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ecmascript-string-left-right-trim", 3 | "repository": { 4 | "type": "git", 5 | "url": "git+https://github.com/sebmarkbage/ecmascript-string-left-right-trim" 6 | }, 7 | "keywords": [ 8 | "ecmascript", 9 | "string", 10 | "test262", 11 | "string.prototype.trimLeft", 12 | "string.prototype.trimRight", 13 | "string.prototype.trimStart", 14 | "string.prototype.trimEnd" 15 | ], 16 | "author": "Tom Schuster", 17 | "license": "MIT", 18 | "devDependencies": { 19 | "ecmarkup": "^3.2.6" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /spec.emu: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |
7 | title: String.prototype.trimStart/trimEnd (plus trimLeft/trimRight) 8 | stage: 3 9 | contributors: Sebastian Markbåge, Tom Schuster 10 |11 | 12 |
The following steps are taken:
15 |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.
31 |The following steps are taken:
37 |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.
43 |The following steps are taken:
49 |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.
55 |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
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
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.
81 |The initial value of the `trimLeft` property is the same function object as the initial value of the `String.prototype.trimStart` property.
83 |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.
89 |The initial value of the `trimRight` property is the same function object as the initial value of the `String.prototype.trimEnd` property.
91 |