3d03ea251f5080703d46301c29e4001421233cd94196a262b2dbad8955864cc6b9db8d043b436b9bbe6be113932c93e4fb8c7d591463da45b331a85bfdac05 2.3 KB

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