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