1 | # String.prototype.trim <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
|
---|
2 |
|
---|
3 | [![github actions][actions-image]][actions-url]
|
---|
4 | [![coverage][codecov-image]][codecov-url]
|
---|
5 | [![dependency status][deps-svg]][deps-url]
|
---|
6 | [![dev dependency status][dev-deps-svg]][dev-deps-url]
|
---|
7 | [![License][license-image]][license-url]
|
---|
8 | [![Downloads][downloads-image]][downloads-url]
|
---|
9 |
|
---|
10 | [![npm badge][npm-badge-png]][package-url]
|
---|
11 |
|
---|
12 | An ES5 spec-compliant `String.prototype.trim` shim. Invoke its "shim" method to shim `String.prototype.trim` if it is unavailable.
|
---|
13 |
|
---|
14 | 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 (both [ES5](https://262.ecma-international.org/5.1/#sec-15.5.4.20) and [current](https://tc39.es/ecma262/#sec-string.prototype.trim)).
|
---|
15 |
|
---|
16 | Most common usage:
|
---|
17 |
|
---|
18 | ```js
|
---|
19 | var assert = require('assert');
|
---|
20 | var trim = require('string.prototype.trim');
|
---|
21 |
|
---|
22 | assert(trim(' \t\na \t\n') === 'a');
|
---|
23 |
|
---|
24 | trim.shim(); // will be a no-op if not needed
|
---|
25 |
|
---|
26 | assert(trim(' \t\na \t\n') === ' \t\na \t\n'.trim());
|
---|
27 | ```
|
---|
28 |
|
---|
29 | ## Engine Bugs
|
---|
30 | Some implementations of `String#trim` incorrectly trim zero-width spaces. This shim detects and corrects this behavior.
|
---|
31 |
|
---|
32 | ## Tests
|
---|
33 | Simply clone the repo, `npm install`, and run `npm test`
|
---|
34 |
|
---|
35 | [package-url]: https://npmjs.com/package/string.prototype.trim
|
---|
36 | [npm-version-svg]: https://versionbadg.es/es-shims/String.prototype.trim.svg
|
---|
37 | [deps-svg]: https://david-dm.org/es-shims/String.prototype.trim.svg
|
---|
38 | [deps-url]: https://david-dm.org/es-shims/String.prototype.trim
|
---|
39 | [dev-deps-svg]: https://david-dm.org/es-shims/String.prototype.trim/dev-status.svg
|
---|
40 | [dev-deps-url]: https://david-dm.org/es-shims/String.prototype.trim#info=devDependencies
|
---|
41 | [license-image]: https://img.shields.io/npm/l/string.prototype.trim.svg
|
---|
42 | [license-url]: LICENSE
|
---|
43 | [downloads-image]: https://img.shields.io/npm/dm/string.prototype.trim.svg
|
---|
44 | [downloads-url]: https://npm-stat.com/charts.html?package=string.prototype.trim
|
---|
45 | [codecov-image]: https://codecov.io/gh/es-shims/String.prototype.trim/branch/main/graphs/badge.svg
|
---|
46 | [codecov-url]: https://app.codecov.io/gh/es-shims/String.prototype.trim/
|
---|
47 | [actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/es-shims/String.prototype.trim
|
---|
48 | [actions-url]: https://github.com/es-shims/String.prototype.trim/actions
|
---|