es-to-primitive (1.3.0)
Published 2026-02-24 13:56:04 +00:00 by atheaadmin
Installation
registry=npm install es-to-primitive@1.3.0"es-to-primitive": "1.3.0"About this package
es-to-primitive 
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
Dependencies
Dependencies
| ID | Version |
|---|---|
| is-callable | ^1.2.7 |
| is-date-object | ^1.0.5 |
| is-symbol | ^1.0.4 |
Development Dependencies
| ID | Version |
|---|---|
| @arethetypeswrong/cli | ^0.17.0 |
| @ljharb/eslint-config | ^21.1.1 |
| @ljharb/tsconfig | ^0.2.0 |
| @types/for-each | ^0.3.3 |
| @types/function.prototype.name | ^1.1.3 |
| @types/is-callable | ^1.1.2 |
| @types/is-date-object | ^1.0.4 |
| @types/is-symbol | ^1.0.2 |
| @types/object-inspect | ^1.13.0 |
| @types/object-is | ^1.1.0 |
| @types/tape | ^5.6.4 |
| auto-changelog | ^2.5.0 |
| encoding | ^0.1.13 |
| es-value-fixtures | ^1.5.0 |
| eslint | =8.8.0 |
| for-each | ^0.3.3 |
| function.prototype.name | ^1.1.6 |
| npmignore | ^0.3.1 |
| nyc | ^10.3.2 |
| object-inspect | ^1.13.3 |
| object-is | ^1.1.6 |
| safe-publish-latest | ^2.0.0 |
| tape | ^5.9.0 |
| typescript | next |
Keywords
primitive
abstract
ecmascript
es5
es6
es2015
toPrimitive
coerce
type
object
string
number
boolean
symbol
null
undefined
