Skip to content

Instantly share code, notes, and snippets.

@evilpie
Last active April 29, 2016 19:05
Show Gist options
  • Save evilpie/54f04ae251ece314dd2a15c93b1b5f13 to your computer and use it in GitHub Desktop.
Save evilpie/54f04ae251ece314dd2a15c93b1b5f13 to your computer and use it in GitHub Desktop.

String.prototype.trimStart / String.prototype.trimEnd

ECMAScript proposal, specs, tests, and reference implementation for String.prototype.trimStart/trimEnd (plus trimLeft/trimRight).

This initial proposal was drafted by @sebmarkbage and the updated spec was drafted by @evilpie with input from @ljharb.

This proposal is currently at stage 1 of the process.

Designated TC39 reviewers: ?

Rationale

ES5 standardized String.prototype.trim. All major engines have also implemented corresponding trimLeft and trimRight functions - without any standard specification. For consinstency with padStart/padRight we propose trimStart and trimEnd and trimLeft/trimRight as aliases required for web compatibility.

Spec

You can view the spec in markdown format or rendered as HTML.

Naming / Aliasing

For consinstency 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment