Security News
Introducing the Socket Python SDK
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
string.prototype.trimend
Advanced tools
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.
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()
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.
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'.
This is a polyfill for the proposed String
API trimEnd
by @sebmarkbage, @evilpie and @ljharb.
As the proposal says this API will trim the whitespaces from a string just like the trim
function but only from the end of the string leaving any white space at the beginning. This is implemented by some browsers (like FireFox and Chrome) under the name trimRight
which is not a standard API by the ECMA.
Here's a basic example for the usage of this API:
var str = ' foo ';
str = str.trimEnd();
console.log(str.length); // 6
console.log(str); // ' foo'
This polyfill will fallback on the trimRight
if it's found, since they're doing the same thing, and if not it will do a work around with the help of trim
function.
Note: for older browsers you need to polyfill trim
, I didn't do that because my target was browsers with the trim
support already since this API is going to take sometime to get accepted.
This project is under the MIT License.
FAQs
ES2019 spec-compliant String.prototype.trimEnd shim.
The npm package string.prototype.trimend receives a total of 28,326,814 weekly downloads. As such, string.prototype.trimend popularity was classified as popular.
We found that string.prototype.trimend demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.
Security News
A new Rust RFC proposes "Trusted Publishing" for Crates.io, introducing short-lived access tokens via OIDC to improve security and reduce risks associated with long-lived API tokens.