New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

es6-shim

Package Overview
Dependencies
Maintainers
1
Versions
90
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

es6-shim - npm Package Compare versions

Comparing version 0.2.1 to 0.3.0

.npmignore

9

CHANGELOG.md

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

## 0.2.1 / 2012-01-07
## es6-shim 0.3.0 (January 27, 2012)
* Added Number.isFinite() and Object.isnt().
## es6-shim 0.2.1 (January 07, 2012)
* Fixed a bug in String#endsWith().
## 0.2.0 / 2011-12-25
## es6-shim 0.2.0 (December 25, 2011)
* Added browser support.

@@ -9,3 +12,3 @@ * Added tests.

## 0.1.0 / 2011-12-25
## es6-shim 0.1.0 (December 25, 2011)
* Initial release

@@ -8,3 +8,2 @@ ({define: (typeof define === 'function')

var globall = (typeof global === 'undefined') ? window : global;
var global_isNaN = globall.isNaN;
var global_isFinite = globall.isFinite;

@@ -38,6 +37,6 @@

endsWith: function(s) {
var t = String(s);
var index = this.lastIndexOf(t)
return index >= 0 && index === this.length - t.length;
endsWith: function(substring) {
var substr = String(substring);
var index = this.lastIndexOf(substr)
return index >= 0 && index === this.length - substr.length;
},

@@ -74,4 +73,8 @@

defineProperties(Number, {
isFinite: function(value) {
return typeof value === 'number' && global_isFinite(value);
},
isInteger: function(value) {
return typeof value === 'number' && global_isFinite(value) &&
return Number.isFinite(value) &&
value > -9007199254740992 && value < 9007199254740992 &&

@@ -82,10 +85,10 @@ Math.floor(value) === value;

isNaN: function(value) {
return typeof value === 'number' && global_isNaN(value);
return Object.is(value, NaN);
},
toInteger: function(value) {
var n = +value;
if (isNaN(n)) return +0;
if (n === 0 || !global_isFinite(n)) return n;
return Math.sign(n) * Math.floor(Math.abs(n));
var number = +value;
if (Object.is(number, NaN)) return +0;
if (number === 0 || !Number.isFinite(number)) return number;
return Math.sign(number) * Math.floor(Math.abs(number));
}

@@ -131,3 +134,7 @@ });

// 0 === -0, but they are not identical
return x !== 0 || 1 / x === 1 / y;
if (x === 0) {
return 1 / x === 1 / y;
} else {
return true;
}
}

@@ -141,2 +148,6 @@

return x !== x && y !== y;
},
isnt: function(x, y) {
return !Object.is(x, y);
}

@@ -148,3 +159,3 @@ });

var number = +value;
if (global_isNaN(number) || number === 0) return number;
if (Object.is(number, NaN) || number === 0) return number;
return (number < 0) ? -1 : 1;

@@ -184,2 +195,7 @@ }

if (index < 0) index = keys.length;
if (value === void 0) {
keys.splice(index, 1);
values.splice(index, 1);
return;
}
keys[index] = key;

@@ -199,2 +215,3 @@ values[index] = value;

});
return Map;

@@ -219,3 +236,3 @@ })(),

'delete': function(key) {
return this.map.delete(key);
return this.map['delete'](key);
}

@@ -227,17 +244,2 @@ });

});
/*defineProperties(globall.Set, {
of: function(iterable) {
var object = Object(iterable);
var set = Set();
for (var key = 0, length = object.length >>> 0; key < length; key++) {
if (key in object && !(set.has(key))) {
set.add(object[key]);
}
}
return set;
}
});*/
});

@@ -5,3 +5,3 @@ {

"description": "ECMAScript 6 (Harmony) compatibility shims for legacy JavaScript engines",
"version": "0.2.1",
"version": "0.3.0",
"homepage": "https://github.com/paulmillr/es6-shim/",

@@ -8,0 +8,0 @@ "repository": {

@@ -18,5 +18,5 @@ # ES6 Shim

* Array.from, Array.of
* Number.isNaN, Number.toInteger, Number.isInteger
* Number.isNaN, Number.toInteger, Number.isInteger, Number.isFinite
* Object.getOwnPropertyDescriptors, Object.getPropertyDescriptor,
Object.getPropertyNames, Object.is
Object.getPropertyNames, Object.is, Object.isnt
* Math.sign

@@ -29,3 +29,3 @@

Copyright (c) 2011 Paul Miller (http://paulmillr.com)
Copyright (c) 2012 Paul Miller (http://paulmillr.com)

@@ -32,0 +32,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of

@@ -5,15 +5,33 @@ var expect = require('expect.js');

describe('Number', function() {
var integers = [5295, -5295, -9007199254740991, 9007199254740991, 0, -0];
var nonIntegers = [-9007199254740992, 9007199254740992, 5.9];
var infinities = [Infinity, -Infinity];
var nonNumbers = [void 0, true, null, {}, [], 'str'];
var expectToBeOk = function(item) {
expect(item).to.be.ok();
};
var expectToNotBeOk = function(item) {
expect(item).to.not.be.ok();
};
describe('Number.isFinite()', function() {
it('should work', function() {
integers.map(Number.isFinite).forEach(expectToBeOk);
infinities.map(Number.isFinite).forEach(expectToNotBeOk);
});
it('should not be confused by type coercion', function() {
nonNumbers.map(Number.isFinite).forEach(expectToNotBeOk);
});
});
describe('Number.isInteger()', function() {
it('should be truthy on integers', function() {
[5295, -5295, -9007199254740991, 9007199254740991, 0,
-0].forEach(function(value) {
expect(Number.isInteger(value)).to.be.ok();
});
integers.map(Number.isInteger).forEach(expectToBeOk);
});
it('should not be truthy on non-integers', function() {
['test', Infinity, -Infinity, -9007199254740992, 9007199254740992,
5.9, NaN].forEach(function(value) {
expect(Number.isInteger(value)).to.not.be.ok();
});
it('should not be confused by type coercion', function() {
nonIntegers.concat(
infinities, nonNumbers
).map(Number.isInteger).forEach(expectToNotBeOk);
});

@@ -23,10 +41,9 @@ });

describe('Number.isNaN()', function() {
it('should be truthy on NaN', function() {
it('should be truthy only on NaN', function() {
expect(Number.isNaN(NaN)).to.be.ok();
integers.concat(nonIntegers).map(Number.isNaN).forEach(expectToNotBeOk);
});
it('should be falsy on everything else', function() {
[void 0, true, null, {}, 37, [], 'str'].forEach(function(item) {
expect(Number.isNaN(item)).to.not.be.ok();
});
it('should not be confused by type coercion', function() {
nonNumbers.map(Number.isNaN).forEach(expectToNotBeOk);
});

@@ -37,13 +54,11 @@ });

it('should convert things to integer value', function() {
expect(Number.toInteger(4294967297)).to.equal(4294967297);
expect(Number.toInteger(1.5)).to.equal(1);
expect(Number.toInteger(-1.5)).to.equal(-1);
expect(Number.toInteger(1/3)).to.equal(0);
expect(Number.toInteger(Infinity)).to.equal(Infinity);
expect(Number.toInteger(Infinity)).to.equal(Infinity);
expect(Number.toInteger(Infinity)).to.equal(Infinity);
expect(Number.toInteger(NaN)).to.equal(0);
expect(Number.toInteger('thing')).to.equal(0);
integers.concat(infinities).forEach(function(item) {
expect(Number.toInteger(item)).to.equal(item);
});
[[1.5, 1], [-1.5, -1], [1/3, 0], [NaN, 0], ['str', 0]
].forEach(function(item) {
expect(Number.toInteger(item[0])).to.equal(item[1]);
});
});
});
});

@@ -7,9 +7,7 @@ var expect = require('expect.js');

it('should compare regular objects correctly', function() {
expect(Object.is(null, null)).to.be.ok();
expect(Object.is(void 0, void 0)).to.be.ok();
expect(Object.is([0], [0])).to.not.be.ok();
expect(Object.is(5, 5)).to.be.ok();
expect(Object.is('str', 'str')).to.be.ok();
var obj = {a: null};
expect(Object.is(obj, obj)).to.be.ok();
[null, void 0, [0], 5, 'str', {a: null}].map(function(item) {
return Object.is(item, item)
}).forEach(function(result) {
expect(result).to.be.ok();
});
});

@@ -25,2 +23,20 @@

});
describe('Object.isnt()', function() {
it('should compare regular objects correctly', function() {
[null, void 0, [0], 5, 'str', {a: null}].map(function(item) {
return Object.isnt(item, item)
}).forEach(function(result) {
expect(result).to.not.be.ok();
});
});
it('should compare 0 and -0 correctly', function() {
expect(Object.isnt(0, -0)).to.be.ok();
});
it('should compare NaNs correctly', function() {
expect(Object.isnt(NaN, NaN)).to.not.be.ok();
});
});

@@ -27,0 +43,0 @@ describe('Object.getOwnPropertyDescriptors()', function() {

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