es-shims/es-to-primitive

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

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

es-to-primitive Version Badge

Build Status dependency status dev dependency status License Downloads

npm badge

browser support

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.

Example
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);
Tests

Simply clone the repo, npm install, and run npm test


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.