string.prototype.trimend
Advanced tools
Comparing version 0.1.0 to 1.0.0
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 |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
12906
16
111
1
48
2
7
1
1
+ Addeddefine-properties@^1.1.3
+ Addedes-abstract@^1.17.5
+ Addedarray-buffer-byte-length@1.0.1(transitive)
+ Addedarraybuffer.prototype.slice@1.0.3(transitive)
+ Addedavailable-typed-arrays@1.0.7(transitive)
+ Addedcall-bind@1.0.7(transitive)
+ Addeddata-view-buffer@1.0.1(transitive)
+ Addeddata-view-byte-length@1.0.1(transitive)
+ Addeddata-view-byte-offset@1.0.0(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addeddefine-properties@1.2.1(transitive)
+ Addedes-abstract@1.23.3(transitive)
+ Addedes-define-property@1.0.0(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedes-object-atoms@1.0.0(transitive)
+ Addedes-set-tostringtag@2.0.3(transitive)
+ Addedes-to-primitive@1.2.1(transitive)
+ Addedfor-each@0.3.3(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedfunction.prototype.name@1.1.6(transitive)
+ Addedfunctions-have-names@1.2.3(transitive)
+ Addedget-intrinsic@1.2.4(transitive)
+ Addedget-symbol-description@1.0.2(transitive)
+ Addedglobalthis@1.0.4(transitive)
+ Addedgopd@1.0.1(transitive)
+ Addedhas-bigints@1.0.2(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-proto@1.0.3(transitive)
+ Addedhas-symbols@1.0.3(transitive)
+ Addedhas-tostringtag@1.0.2(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedinternal-slot@1.0.7(transitive)
+ Addedis-array-buffer@3.0.4(transitive)
+ Addedis-bigint@1.0.4(transitive)
+ Addedis-boolean-object@1.1.2(transitive)
+ Addedis-callable@1.2.7(transitive)
+ Addedis-data-view@1.0.1(transitive)
+ Addedis-date-object@1.0.5(transitive)
+ Addedis-negative-zero@2.0.3(transitive)
+ Addedis-number-object@1.0.7(transitive)
+ Addedis-regex@1.1.4(transitive)
+ Addedis-shared-array-buffer@1.0.3(transitive)
+ Addedis-string@1.0.7(transitive)
+ Addedis-symbol@1.0.4(transitive)
+ Addedis-typed-array@1.1.13(transitive)
+ Addedis-weakref@1.0.2(transitive)
+ Addedisarray@2.0.5(transitive)
+ Addedobject-inspect@1.13.2(transitive)
+ Addedobject-keys@1.1.1(transitive)
+ Addedobject.assign@4.1.5(transitive)
+ Addedpossible-typed-array-names@1.0.0(transitive)
+ Addedregexp.prototype.flags@1.5.3(transitive)
+ Addedsafe-array-concat@1.1.2(transitive)
+ Addedsafe-regex-test@1.0.3(transitive)
+ Addedset-function-length@1.2.2(transitive)
+ Addedset-function-name@2.0.2(transitive)
+ Addedside-channel@1.0.6(transitive)
+ Addedstring.prototype.trim@1.2.9(transitive)
+ Addedstring.prototype.trimend@1.0.8(transitive)
+ Addedstring.prototype.trimstart@1.0.8(transitive)
+ Addedtyped-array-buffer@1.0.2(transitive)
+ Addedtyped-array-byte-length@1.0.1(transitive)
+ Addedtyped-array-byte-offset@1.0.2(transitive)
+ Addedtyped-array-length@1.0.6(transitive)
+ Addedunbox-primitive@1.0.2(transitive)
+ Addedwhich-boxed-primitive@1.0.2(transitive)
+ Addedwhich-typed-array@1.1.15(transitive)