0e26a3490feaba2d78198dc3c345e3e06537b25e8e6ea61aaa14393f91388ca73f461529b31ffdc0ec2f9c3d969b7cf6972354a2b4c93e6f5e231562f748bb 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # es-to-primitive <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. ECMAScript “ToPrimitive” algorithm. Provides ES5 and ES2015 versions.
  10. When different versions of the spec conflict, the default export will be the latest version of the abstract operation.
  11. Alternative versions will also be available under an `es5`/`es2015` exported property if you require a specific version.
  12. ## Example
  13. ```js
  14. var toPrimitive = require('es-to-primitive');
  15. var assert = require('assert');
  16. assert(toPrimitive(function () {}) === String(function () {}));
  17. var date = new Date();
  18. assert(toPrimitive(date) === String(date));
  19. assert(toPrimitive({ valueOf: function () { return 3; } }) === 3);
  20. assert(toPrimitive(['a', 'b', 3]) === String(['a', 'b', 3]));
  21. var sym = Symbol();
  22. assert(toPrimitive(Object(sym)) === sym);
  23. ```
  24. ## Tests
  25. Simply clone the repo, `npm install`, and run `npm test`
  26. [package-url]: https://npmjs.org/package/es-to-primitive
  27. [npm-version-svg]: https://versionbadg.es/ljharb/es-to-primitive.svg
  28. [deps-svg]: https://david-dm.org/ljharb/es-to-primitive.svg
  29. [deps-url]: https://david-dm.org/ljharb/es-to-primitive
  30. [dev-deps-svg]: https://david-dm.org/ljharb/es-to-primitive/dev-status.svg
  31. [dev-deps-url]: https://david-dm.org/ljharb/es-to-primitive#info=devDependencies
  32. [npm-badge-png]: https://nodei.co/npm/es-to-primitive.png?downloads=true&stars=true
  33. [license-image]: https://img.shields.io/npm/l/es-to-primitive.svg
  34. [license-url]: LICENSE
  35. [downloads-image]: https://img.shields.io/npm/dm/es-to-primitive.svg
  36. [downloads-url]: https://npm-stat.com/charts.html?package=es-to-primitive
  37. [codecov-image]: https://codecov.io/gh/ljharb/es-to-primitive/branch/main/graphs/badge.svg
  38. [codecov-url]: https://app.codecov.io/gh/ljharb/es-to-primitive/
  39. [actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/ljharb/es-to-primitive
  40. [actions-url]: https://github.com/ljharb/es-to-primitive/actions