What is string.prototype.trimend?
The string.prototype.trimend package provides functionality to remove whitespace from the end of a string without altering the original string. It is a polyfill for the String.prototype.trimEnd method, which is part of the ECMAScript 2019 (ES10) standard. This package ensures compatibility across different JavaScript environments where the native trimEnd method may not be available.
What are string.prototype.trimend's main functionalities?
Trimming whitespace from the end of a string
This feature allows you to remove any trailing whitespace from a string. The code sample demonstrates how to use the trimEnd method to trim whitespace from the end of the string ' Hello World! ', resulting in ' Hello World!'.
" Hello World! ".trimEnd()
Other packages similar to string.prototype.trimend
lodash.trimend
Lodash's trimEnd function offers similar functionality to string.prototype.trimend by removing whitespace from the end of a string. Lodash is a more comprehensive utility library that includes a wide range of functions for manipulating strings, arrays, objects, and more, making it a heavier dependency if you only need string trimming functionality.
string.prototype.trimright
The string.prototype.trimright package is another polyfill that provides similar functionality to string.prototype.trimend. The difference lies in the naming convention, as 'trimRight' is an alias for 'trimEnd' in the ECMAScript specification. This package ensures compatibility with environments that recognize 'trimRight' instead of 'trimEnd'.
String.prototype.trimEnd
An ES2019-spec-compliant String.prototype.trimEnd
shim. Invoke its "shim" method to shim String.prototype.trimEnd
if it is unavailable.
This package implements the es-shim API interface. It works in an ES3-supported environment and complies with the spec. In an ES6 environment, it will also work properly with Symbol
s.
Most common usage:
var trimEnd = require('string.prototype.trimend');
assert(trimEnd(' \t\na \t\n') === 'a \t\n');
if (!String.prototype.trimEnd) {
trimEnd.shim();
}
assert(trimEnd(' \t\na \t\n ') === ' \t\na \t\n '.trimEnd());
Tests
Simply clone the repo, npm install
, and run npm test