Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

string.prototype.trimend

Package Overview
Dependencies
Maintainers
2
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

string.prototype.trimend - npm Package Compare versions

Comparing version 0.1.0 to 1.0.0

.editorconfig

28

index.js

@@ -1,10 +0,18 @@

String.prototype.trimEnd = String.prototype.trimEnd ? String.prototype.trimEnd : function() {
if(String.prototype.trimRight) {
return this.trimRight();
} else if(String.prototype.trim) {
var trimmed = this.trim();
var indexOfWord = this.indexOf(trimmed);
return this.slice(indexOfWord, this.length);
}
};
'use strict';
var callBind = require('es-abstract/helpers/callBind');
var define = require('define-properties');
var implementation = require('./implementation');
var getPolyfill = require('./polyfill');
var shim = require('./shim');
var bound = callBind(getPolyfill());
define(bound, {
getPolyfill: getPolyfill,
implementation: implementation,
shim: shim
});
module.exports = bound;
{
"name": "string.prototype.trimend",
"version": "0.1.0",
"description": "polyfill for the proposed api String.prototype.trimEnd",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"es6",
"es7",
"es8",
"javascript",
"prototype",
"polyfill",
"utility",
"trim",
"trimLeft",
"trimRight",
"trimStart",
"trimEnd",
"tc39"
],
"author": "Khaled Al-Ansari <khaledelansari@gmail.com>",
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/KhaledElAnsari/String.prototype.trimEnd.git"
},
"bugs": {
"url": "https://github.com/KhaledElAnsari/String.prototype.trimEnd/issues"
},
"homepage": "https://github.com/KhaledElAnsari/String.prototype.trimEnd#readme"
"name": "string.prototype.trimend",
"version": "1.0.0",
"description": "ES2019 spec-compliant String.prototype.trimEnd shim.",
"main": "index.js",
"scripts": {
"lint": "eslint .",
"pretest": "npm run lint && es-shim-api --bound",
"test": "npm run tests-only",
"posttest": "npx aud --production",
"tests-only": "npm run --silent test:shimmed && npm run --silent test:module",
"test:shimmed": "node test/shimmed",
"test:module": "node test",
"version": "auto-changelog && git add CHANGELOG.md",
"postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\""
},
"keywords": [
"es6",
"es7",
"es8",
"javascript",
"prototype",
"polyfill",
"utility",
"trim",
"trimLeft",
"trimRight",
"trimStart",
"trimEnd",
"tc39"
],
"author": "Khaled Al-Ansari <khaledelansari@gmail.com>",
"funding": {
"url": "https://github.com/sponsors/ljharb"
},
"license": "MIT",
"devDependencies": {
"@es-shims/api": "^2.1.2",
"@ljharb/eslint-config": "^16.0.0",
"aud": "^1.1.0",
"auto-changelog": "^1.16.3",
"eslint": "^6.8.0",
"functions-have-names": "^1.2.1",
"tape": "^5.0.0-next.5"
},
"auto-changelog": {
"output": "CHANGELOG.md",
"template": "keepachangelog",
"unreleased": false,
"commitLimit": false,
"backfillLimit": false
},
"dependencies": {
"define-properties": "^1.1.3",
"es-abstract": "^1.17.5"
}
}

@@ -1,33 +0,47 @@

## Introduction
This is a polyfill for the proposed `String` API `trimEnd` by [@sebmarkbage](https://github.com/sebmarkbage), [@evilpie](https://github.com/evilpie/) and [@ljharb](https://github.com/ljharb).
String.prototype.trimEnd <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
As the [proposal](https://github.com/tc39/proposal-string-left-right-trim) says this API will trim the whitespaces from a string just like the [`trim`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/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`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/TrimRight) which is not a standard API by the ECMA.
[![Build Status][travis-svg]][travis-url]
[![dependency status][deps-svg]][deps-url]
[![dev dependency status][dev-deps-svg]][dev-deps-url]
[![License][license-image]][license-url]
[![Downloads][downloads-image]][downloads-url]
## Usage
[![npm badge][npm-badge-png]][package-url]
You can use it with the help of npm, just type the following command:
[![browser support][testling-svg]][testling-url]
```
npm install string.prototype.trimend
```
An ES2019-spec-compliant `String.prototype.trimEnd` shim. Invoke its "shim" method to shim `String.prototype.trimEnd` if it is unavailable.
## Example
This package implements the [es-shim API](https://github.com/es-shims/api) interface. It works in an ES3-supported environment and complies with the [spec](http://www.ecma-international.org/ecma-262/6.0/#sec-object.assign). In an ES6 environment, it will also work properly with `Symbol`s.
Here's a basic example for the usage of this API:
Most common usage:
```js
var trimEnd = require('string.prototype.trimend');
```javascript
var str = ' foo ';
str = str.trimEnd();
console.log(str.length); // 6
console.log(str); // ' foo'
```
assert(trimEnd(' \t\na \t\n') === 'a \t\n');
## How it work
if (!String.prototype.trimEnd) {
trimEnd.shim();
}
This polyfill will fallback on the [`trimRight`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/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`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trim) function.
assert(trimEnd(' \t\na \t\n ') === ' \t\na \t\n '.trimEnd());
```
**Note**: for older browsers you need to polyfill [`trim`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trim), I didn't do that because my target was browsers with the [`trim`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trim) support already since this API is going to take sometime to get accepted.
## Tests
Simply clone the repo, `npm install`, and run `npm test`
## License
This project is under the MIT License.
[package-url]: https://npmjs.com/package/string.prototype.trimend
[npm-version-svg]: http://vb.teelaun.ch/es-shims/String.prototype.trimEnd.svg
[travis-svg]: https://travis-ci.org/es-shims/String.prototype.trimEnd.svg
[travis-url]: https://travis-ci.org/es-shims/String.prototype.trimEnd
[deps-svg]: https://david-dm.org/es-shims/String.prototype.trimEnd.svg
[deps-url]: https://david-dm.org/es-shims/String.prototype.trimEnd
[dev-deps-svg]: https://david-dm.org/es-shims/String.prototype.trimEnd/dev-status.svg
[dev-deps-url]: https://david-dm.org/es-shims/String.prototype.trimEnd#info=devDependencies
[testling-svg]: https://ci.testling.com/es-shims/String.prototype.trimEnd.png
[testling-url]: https://ci.testling.com/es-shims/String.prototype.trimEnd
[npm-badge-png]: https://nodei.co/npm/string.prototype.trimend.png?downloads=true&stars=true
[license-image]: http://img.shields.io/npm/l/string.prototype.trimend.svg
[license-url]: LICENSE
[downloads-image]: http://img.shields.io/npm/dm/string.prototype.trimend.svg
[downloads-url]: http://npm-stat.com/charts.html?package=string.prototype.trimend
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc