Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

README.md 1.9 KiB

3 anni fa
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # es-to-primitive <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
  2. [![Build Status][travis-svg]][travis-url]
  3. [![dependency status][deps-svg]][deps-url]
  4. [![dev dependency status][dev-deps-svg]][dev-deps-url]
  5. [![License][license-image]][license-url]
  6. [![Downloads][downloads-image]][downloads-url]
  7. [![npm badge][npm-badge-png]][package-url]
  8. ECMAScript “ToPrimitive” algorithm. Provides ES5 and ES2015 versions.
  9. When different versions of the spec conflict, the default export will be the latest version of the abstract operation.
  10. Alternative versions will also be available under an `es5`/`es2015` exported property if you require a specific version.
  11. ## Example
  12. ```js
  13. var toPrimitive = require('es-to-primitive');
  14. var assert = require('assert');
  15. assert(toPrimitive(function () {}) === String(function () {}));
  16. var date = new Date();
  17. assert(toPrimitive(date) === String(date));
  18. assert(toPrimitive({ valueOf: function () { return 3; } }) === 3);
  19. assert(toPrimitive(['a', 'b', 3]) === String(['a', 'b', 3]));
  20. var sym = Symbol();
  21. assert(toPrimitive(Object(sym)) === sym);
  22. ```
  23. ## Tests
  24. Simply clone the repo, `npm install`, and run `npm test`
  25. [package-url]: https://npmjs.org/package/es-to-primitive
  26. [npm-version-svg]: http://versionbadg.es/ljharb/es-to-primitive.svg
  27. [travis-svg]: https://travis-ci.org/ljharb/es-to-primitive.svg
  28. [travis-url]: https://travis-ci.org/ljharb/es-to-primitive
  29. [deps-svg]: https://david-dm.org/ljharb/es-to-primitive.svg
  30. [deps-url]: https://david-dm.org/ljharb/es-to-primitive
  31. [dev-deps-svg]: https://david-dm.org/ljharb/es-to-primitive/dev-status.svg
  32. [dev-deps-url]: https://david-dm.org/ljharb/es-to-primitive#info=devDependencies
  33. [npm-badge-png]: https://nodei.co/npm/es-to-primitive.png?downloads=true&stars=true
  34. [license-image]: http://img.shields.io/npm/l/es-to-primitive.svg
  35. [license-url]: LICENSE
  36. [downloads-image]: http://img.shields.io/npm/dm/es-to-primitive.svg
  37. [downloads-url]: http://npm-stat.com/charts.html?package=es-to-primitive