# es-to-primitive

> ECMAScript “ToPrimitive” algorithm. Provides ES5 and ES2015 versions.

Latest version **1.3.4** (published 2026-06-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install es-to-primitive
pnpm add es-to-primitive
yarn add es-to-primitive
bun add es-to-primitive
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 1.3.4 |
| Published | 2026-06-26 |
| First published | 2015-03-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >= 0.4 |
| Dependencies | 6 |
| Unpacked size | 46.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 21 |
| Author | Jordan Harband |
| Maintainers | ljharb |
| Keywords | primitive, abstract, ecmascript, es5, es6, es2015, toPrimitive, coerce, type, object, string, number, boolean, symbol, null, undefined |

## Links

- npm: https://www.npmjs.com/package/es-to-primitive
- Repository: https://github.com/ljharb/es-to-primitive
- Homepage: https://github.com/ljharb/es-to-primitive#readme
- Issues: https://github.com/ljharb/es-to-primitive/issues
- Funding: https://github.com/sponsors/ljharb
- npm.io page: https://npm.io/package/es-to-primitive

## Dependencies (6)

- [es-errors](https://npm.io/package/es-errors.md) ^1.3.0
- [is-symbol](https://npm.io/package/is-symbol.md) ^1.1.1
- [is-callable](https://npm.io/package/is-callable.md) ^1.2.7
- [is-date-object](https://npm.io/package/is-date-object.md) ^1.1.0
- [es-abstract-get](https://npm.io/package/es-abstract-get.md) ^1.0.0
- [es-define-property](https://npm.io/package/es-define-property.md) ^1.0.1

## Alternatives

- [random-seedable](https://npm.io/package/random-seedable.md) — 27.9K weekly downloads
- [n2words](https://npm.io/package/n2words.md) — 22.2K weekly downloads
- [@stdlib/math-base-special-factorialln](https://npm.io/package/@stdlib/math-base-special-factorialln.md) — 5.7K weekly downloads
- [@stdlib/math-base-special-abs2](https://npm.io/package/@stdlib/math-base-special-abs2.md) — 1.7K weekly downloads
- [commons-math-interpolation](https://npm.io/package/commons-math-interpolation.md) — 1.4K weekly downloads

## Recent versions

- 1.3.4 (latest) — 2026-06-26
- 1.3.3 — 2026-06-25
- 1.3.2 — 2026-06-25
- 1.3.1 — 2026-06-16
- 1.3.0 — 2024-11-26
- 1.2.1 — 2019-11-09
- 1.2.0 — 2018-09-27
- 1.1.1 — 2016-01-04
- 1.0.1 — 2016-01-04
- 1.1.0 — 2015-12-27
- 1.0.0 — 2015-03-19

## README

# es-to-primitive <sup>[![Version Badge][npm-version-svg]][package-url]</sup>

[![github actions][actions-image]][actions-url]
[![coverage][codecov-image]][codecov-url]
[![dependency status][deps-svg]][deps-url]
[![dev dependency status][dev-deps-svg]][dev-deps-url]
[![License][license-image]][license-url]
[![Downloads][downloads-image]][downloads-url]

[![npm badge][npm-badge-png]][package-url]

ECMAScript “ToPrimitive” algorithm. Provides ES5 and ES2015 versions.
When different versions of the spec conflict, the default export will be the latest version of the abstract operation.
Alternative versions will also be available under an `es5`/`es2015` exported property if you require a specific version.

## Example

```js
var toPrimitive = require('es-to-primitive');
var assert = require('assert');

assert(toPrimitive(function () {}) === String(function () {}));

var date = new Date();
assert(toPrimitive(date) === String(date));

assert(toPrimitive({ valueOf: function () { return 3; } }) === 3);

assert(toPrimitive(['a', 'b', 3]) === String(['a', 'b', 3]));

var sym = Symbol();
assert(toPrimitive(Object(sym)) === sym);
```

## Tests
Simply clone the repo, `npm install`, and run `npm test`

[package-url]: https://npmjs.org/package/es-to-primitive
[npm-version-svg]: https://versionbadg.es/ljharb/es-to-primitive.svg
[deps-svg]: https://david-dm.org/ljharb/es-to-primitive.svg
[deps-url]: https://david-dm.org/ljharb/es-to-primitive
[dev-deps-svg]: https://david-dm.org/ljharb/es-to-primitive/dev-status.svg
[dev-deps-url]: https://david-dm.org/ljharb/es-to-primitive#info=devDependencies
[npm-badge-png]: https://nodei.co/npm/es-to-primitive.png?downloads=true&stars=true
[license-image]: https://img.shields.io/npm/l/es-to-primitive.svg
[license-url]: LICENSE
[downloads-image]: https://img.shields.io/npm/dm/es-to-primitive.svg
[downloads-url]: https://npm-stat.com/charts.html?package=es-to-primitive
[codecov-image]: https://codecov.io/gh/ljharb/es-to-primitive/branch/main/graphs/badge.svg
[codecov-url]: https://app.codecov.io/gh/ljharb/es-to-primitive/
[actions-image]: https://img.shields.io/github/check-runs/ljharb/es-to-primitive/main
[actions-url]: https://github.com/ljharb/es-to-primitive/actions

---
_Source: https://npm.io/package/es-to-primitive · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
