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