Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

es-abstract

Package Overview
Dependencies
Maintainers
1
Versions
83
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

es-abstract - npm Package Compare versions

Comparing version 1.4.2 to 1.4.3

7

CHANGELOG.md

@@ -0,1 +1,8 @@

1.4.3 / 2015-11-04
=================
* [Fix] `ES6.ToNumber`: should give `NaN` for explicitly signed hex strings (#4)
* [Refactor] `ES6.ToNumber`: No need to double-trim
* [Refactor] group tests better
* [Tests] should still pass on `node` `v0.8`
1.4.2 / 2015-11-02

@@ -2,0 +9,0 @@ =================

6

es6.js

@@ -24,2 +24,4 @@ 'use strict';

var hasNonWS = bind.call(Function.call, RegExp.prototype.test, nonWSregex);
var invalidHexLiteral = /^[\-\+]0x[0-9a-f]+$/i;
var isInvalidHexLiteral = bind.call(Function.call, RegExp.prototype.test, invalidHexLiteral);

@@ -72,3 +74,3 @@ // whitespace from: http://es5.github.io/#x15.5.4.20

return this.ToNumber(parseInteger(strSlice(value, 2), 8));
} else if (hasNonWS(value)) {
} else if (hasNonWS(value) || isInvalidHexLiteral(value)) {
return NaN;

@@ -78,3 +80,3 @@ } else {

if (trimmed !== value) {
return this.ToNumber(trim(value));
return this.ToNumber(trimmed);
}

@@ -81,0 +83,0 @@ }

{
"name": "es-abstract",
"version": "1.4.2",
"version": "1.4.3",
"author": {

@@ -5,0 +5,0 @@ "name": "Jordan Harband",

@@ -53,14 +53,26 @@ 'use strict';

t.equal(true, ES.ToBoolean(true), 'true returns true');
forEach([0, -0, NaN], function (falsyNumber) {
t.equal(false, ES.ToBoolean(falsyNumber), 'falsy number ' + falsyNumber + ' coerces to false');
t.test('numbers', function (st) {
forEach([0, -0, NaN], function (falsyNumber) {
st.equal(false, ES.ToBoolean(falsyNumber), 'falsy number ' + falsyNumber + ' coerces to false');
});
forEach([Infinity, 42, 1, -Infinity], function (truthyNumber) {
st.equal(true, ES.ToBoolean(truthyNumber), 'truthy number ' + truthyNumber + ' coerces to true');
});
st.end();
});
forEach([Infinity, 42, 1, -Infinity], function (truthyNumber) {
t.equal(true, ES.ToBoolean(truthyNumber), 'truthy number ' + truthyNumber + ' coerces to true');
});
t.equal(false, ES.ToBoolean(''), 'empty string coerces to false');
t.equal(true, ES.ToBoolean('foo'), 'nonempty string coerces to true');
forEach(objects, function (obj) {
t.equal(true, ES.ToBoolean(obj), 'object coerces to true');
t.test('objects', function (st) {
forEach(objects, function (obj) {
st.equal(true, ES.ToBoolean(obj), 'object coerces to true');
});
st.equal(true, ES.ToBoolean(uncoercibleObject), 'uncoercibleObject coerces to true');
st.end();
});
t.equal(true, ES.ToBoolean(uncoercibleObject), 'uncoercibleObject coerces to true');
t.end();

@@ -74,25 +86,48 @@ });

t.equal(1, ES.ToNumber(true), 'true coerces to 1');
t.ok(is(NaN, ES.ToNumber(NaN)), 'NaN returns itself');
forEach([0, -0, 42, Infinity, -Infinity], function (num) {
t.equal(num, ES.ToNumber(num), num + ' returns itself');
t.test('numbers', function (st) {
st.ok(is(NaN, ES.ToNumber(NaN)), 'NaN returns itself');
forEach([0, -0, 42, Infinity, -Infinity], function (num) {
st.equal(num, ES.ToNumber(num), num + ' returns itself');
});
forEach(['foo', '0', '4a', '2.0', 'Infinity', '-Infinity'], function (numString) {
st.ok(is(+numString, ES.ToNumber(numString)), '"' + numString + '" coerces to ' + Number(numString));
});
st.end();
});
forEach(['foo', '0', '4a', '2.0', 'Infinity', '-Infinity'], function (numString) {
t.ok(is(+numString, ES.ToNumber(numString)), '"' + numString + '" coerces to ' + Number(numString));
t.test('objects', function (st) {
forEach(objects, function (object) {
st.ok(is(ES.ToNumber(object), ES.ToNumber(ES.ToPrimitive(object))), 'object ' + object + ' coerces to same as ToPrimitive of object does');
});
st.throws(function () { return ES.ToNumber(uncoercibleObject); }, TypeError, 'uncoercibleObject throws');
st.end();
});
forEach(objects, function (object) {
t.ok(is(ES.ToNumber(object), ES.ToNumber(ES.ToPrimitive(object))), 'object ' + object + ' coerces to same as ToPrimitive of object does');
t.test('binary literals', function (st) {
st.equal(ES.ToNumber('0b10'), 2, '0b10 is 2');
st.equal(ES.ToNumber({ toString: function () { return '0b11'; } }), 3, 'Object that toStrings to 0b11 is 3');
st.equal(true, is(ES.ToNumber('0b12'), NaN), '0b12 is NaN');
st.equal(true, is(ES.ToNumber({ toString: function () { return '0b112'; } }), NaN), 'Object that toStrings to 0b112 is NaN');
st.end();
});
t.throws(function () { return ES.ToNumber(uncoercibleObject); }, TypeError, 'uncoercibleObject throws');
t.equal(ES.ToNumber('0b10'), 2, '0b10 is 2');
t.equal(ES.ToNumber({ toString: function () { return '0b11'; } }), 3, 'Object that toStrings to 0b11 is 3');
t.test('octal literals', function (st) {
st.equal(ES.ToNumber('0o10'), 8, '0o10 is 8');
st.equal(ES.ToNumber({ toString: function () { return '0o11'; } }), 9, 'Object that toStrings to 0o11 is 9');
t.equal(true, is(ES.ToNumber('0b12'), NaN), '0b12 is NaN');
t.equal(true, is(ES.ToNumber({ toString: function () { return '0b112'; } }), NaN), 'Object that toStrings to 0b112 is NaN');
st.equal(true, is(ES.ToNumber('0o18'), NaN), '0o18 is NaN');
st.equal(true, is(ES.ToNumber({ toString: function () { return '0o118'; } }), NaN), 'Object that toStrings to 0o118 is NaN');
st.end();
});
t.equal(ES.ToNumber('0o10'), 8, '0o10 is 8');
t.equal(ES.ToNumber({ toString: function () { return '0o11'; } }), 9, 'Object that toStrings to 0o11 is 9');
t.test('signed hex numbers', function (st) {
st.equal(true, is(ES.ToNumber('-0xF'), NaN), '-0xF is NaN');
st.equal(true, is(ES.ToNumber(' -0xF '), NaN), 'space-padded -0xF is NaN');
st.equal(true, is(ES.ToNumber('+0xF'), NaN), '+0xF is NaN');
st.equal(true, is(ES.ToNumber(' +0xF '), NaN), 'space-padded +0xF is NaN');
t.equal(true, is(ES.ToNumber('0o18'), NaN), '0o18 is NaN');
t.equal(true, is(ES.ToNumber({ toString: function () { return '0o118'; } }), NaN), 'Object that toStrings to 0o118 is NaN');
st.end();
});

@@ -99,0 +134,0 @@ t.test('trimming of whitespace and non-whitespace characters', function (st) {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc