Name: es-to-primitive
Owner: ECMAScript Shims
Description: ECMAScript "ToPrimitive" algorithm. Provides ES5 and ES6 versions.
Created: 2015-05-25 22:55:08.0
Updated: 2018-03-22 10:21:32.0
Pushed: 2018-03-22 10:21:31.0
Homepage: null
Size: 61
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
ECMAScript ?ToPrimitive? algorithm. Provides ES5 and ES6 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
/es6
/es7
exported property if you require a specific version.
toPrimitive = require('es-to-primitive');
assert = require('assert');
rt(toPrimitive(function () {}) === String(function () {}));
date = new Date();
rt(toPrimitive(date) === String(date));
rt(toPrimitive({ valueOf: function () { return 3; } }) === 3);
rt(toPrimitive(['a', 'b', 3]) === String(['a', 'b', 3]));
sym = Symbol();
rt(toPrimitive(Object(sym)) === sym);
Simply clone the repo, npm install
, and run npm test