Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

es-to-primitive

ljharb102.2mMIT1.3.0TypeScript support: included

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

primitive, abstract, ecmascript, es5, es6, es2015, toPrimitive, coerce, type, object, string, number, boolean, symbol, null, undefined

readme

es-to-primitive Version Badge

github actions coverage dependency status dev dependency status License Downloads

npm badge

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

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

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

v1.3.0 - 2024-11-26

Commits

  • [actions] reuse common workflows bb72efc
  • [Tests] use es-value-fixtures a912f7b
  • [Tests] migrate tests to Github Actions 510baf0
  • [New] add types 69ba1fd
  • [meta] remove unused Makefile 4ea66e6
  • [actions] use node/install instead of node/run; use codecov action 3c31937
  • [meta] do not publish github action workflow files 389567e
  • [meta] use npmignore to autogenerate an npmignore file 9f3aa76
  • [actions] split out node 10-20, and 20+ c60d7d8
  • [Tests] run nyc on all tests; use tape runner 29cbb89
  • [meta] add auto-changelog ea744b2
  • [Dev Deps] update eslint, @ljharb/eslint-config, aud, function.prototype.name, has-symbols, object-inspect, object-is, tape e5c3c79
  • [actions] add automatic rebasing / merge commit blocking a5a6f00
  • [Dev Deps] update @ljharb/eslint-config, es-value-fixtures, function.prototype.name, npmignore, object-inspect, object-is, tape 7941fd5
  • [Dev Deps] update eslint, @ljharb/eslint-config, aud, es-value-fixtures, foreach, object-inspect, tape eb1c79c
  • [Dev Deps] update eslint, @ljharb/eslint-config, function.prototype.name, object-inspect, safe-publish-latest, tape 249b42f
  • [Dev Deps] update eslint, @ljharb/eslint-config, aud, function.prototype.name, object-inspect, object-is, tape d57d5e9
  • [actions] update codecov uploader 003b62c
  • [actions] add "Allow Edits" workflow 75ee990
  • [Dev Deps] update eslint, @ljharb/eslint-config, tape, object-is; add safe-publish-latest ba5da7b
  • [readme] remove travis badge 6f7aec7
  • [Dev Deps] update eslint, @ljharb/eslint-config, aud, object-inspect, tape 3291fd5
  • [Dev Deps] update eslint, @ljharb/eslint-config, function.prototype.name, has-symbols, object-inspect 53007f2
  • [actions] update checkout action 69640db
  • [Dev Deps] update eslint, @ljharb/eslint-config, object-is, tape; add aud c9d644e
  • [Tests] use for-each instead of foreach e9117bb
  • [readme] add github actions/codecov badges 53cd375
  • [Deps] update is-callable, is-date-object, is-symbol 8116c68
  • [Tests] fix test skipping for Symbol.toPrimitive e6268ef
  • [actions] switch Automatic Rebase workflow to pull_request_target event da41c40
  • [Deps] update is-callable, is-date-object 96fe13f
  • [Tests] replace aud with npm audit 0b53154
  • [meta] use prepublishOnly script for npm 7+ 9d7d485
  • [Deps] update is-callable 3c990b6
  • [Deps] update is-callable 9bcfff2
  • [Deps] update is-callable 1eb5478
  • [meta] only run aud on prod deps 1fcd896
  • [Deps] update is-symbol 7174a47

1.2.1 / 2019-11-08

  • [readme] remove testling URLs
  • [meta] add funding field
  • [meta] create FUNDING.yml
  • [Dev Deps] update eslint, @ljharb/eslint-config, covert, replace, semver, tape, function.prototype.name
  • [Tests] use shared travis-ci configs
  • [Tests] Add es5 tests for symbol types (#45)
  • [Tests] use npx aud instead of nsp or npm audit with hoops
  • [Tests] remove jscs

1.2.0 / 2018-09-27

  • [New] create ES2015 entry point/property, to replace ES6
  • [Fix] Ensure optional arguments are not part of the length (#29)
  • [Deps] update is-callable
  • [Dev Deps] update tape, jscs, nsp, eslint, @ljharb/eslint-config, semver, object-inspect, replace
  • [Tests] avoid util.inspect bug with new Date(NaN) on node v6.0 and v6.1.
  • [Tests] up to node v10.11, v9.11, v8.12, v6.14, v4.9

1.1.1 / 2016-01-03

  • [Fix: ES5] fix coercion logic: ES5’s ToPrimitive does not coerce any primitive value, regardless of hint (#2)

1.1.0 / 2015-12-27

  • [New] add Symbol.toPrimitive support
  • [Deps] update is-callable, is-date-object
  • [Dev Deps] update eslint, tape, semver, jscs, covert, nsp, @ljharb/eslint-config
  • [Dev Deps] remove unused deps
  • [Tests] up to node v5.3
  • [Tests] fix npm upgrades on older node versions
  • [Tests] fix testling
  • [Docs] Switch from vb.teelaun.ch to versionbadg.es for the npm version badge SVG

1.0.1 / 2016-01-03

  • [Fix: ES5] fix coercion logic: ES5’s ToPrimitive does not coerce any primitive value, regardless of hint (#2)
  • [Deps] update is-callable, is-date-object
  • [Dev Deps] update eslint, tape, semver, jscs, covert, nsp, @ljharb/eslint-config
  • [Dev Deps] remove unused deps
  • [Tests] up to node v5.3
  • [Tests] fix npm upgrades on older node versions
  • [Tests] fix testling
  • [Docs] Switch from vb.teelaun.ch to versionbadg.es for the npm version badge SVG

1.0.0 / 2015-03-19

  • Initial release.