Skip to content

Commit

Permalink
[Refactor] Use object-keys and is-arguments instead of a homegrow…
Browse files Browse the repository at this point in the history
…n shim.

Leave re-exporting lib files behind to avoid a breaking change.
  • Loading branch information
ljharb committed Apr 3, 2013
1 parent 56a7746 commit 3b503fb
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 48 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var pSlice = Array.prototype.slice;
var objectKeys = require('./lib/keys.js');
var isArguments = require('./lib/is_arguments.js');
var objectKeys = require('object-keys');
var isArguments = require('is-arguments');

var deepEqual = module.exports = function (actual, expected, opts) {
if (!opts) opts = {};
Expand Down
21 changes: 1 addition & 20 deletions lib/is_arguments.js
Original file line number Diff line number Diff line change
@@ -1,20 +1 @@
var supportsArgumentsClass = (function(){
return Object.prototype.toString.call(arguments)
})() == '[object Arguments]';

exports = module.exports = supportsArgumentsClass ? supported : unsupported;

exports.supported = supported;
function supported(object) {
return Object.prototype.toString.call(object) == '[object Arguments]';
};

exports.unsupported = unsupported;
function unsupported(object){
return object &&
typeof object == 'object' &&
typeof object.length == 'number' &&
Object.prototype.hasOwnProperty.call(object, 'callee') &&
!Object.prototype.propertyIsEnumerable.call(object, 'callee') ||
false;
};
module.exports = require('is-arguments');
10 changes: 1 addition & 9 deletions lib/keys.js
Original file line number Diff line number Diff line change
@@ -1,9 +1 @@
exports = module.exports = typeof Object.keys === 'function'
? Object.keys : shim;

exports.shim = shim;
function shim (obj) {
var keys = [];
for (var key in obj) keys.push(key);
return keys;
}
module.exports = require('object-keys');
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
"tests-only": "tape test/*.js",
"test": "npm run tests-only"
},
"dependencies": {
"is-arguments": "^1.0.4",
"object-keys": "^1.1.1"
},
"devDependencies": {
"tape": "^4.11.0"
},
Expand Down
17 changes: 0 additions & 17 deletions test/cmp.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
var test = require('tape');
var equal = require('../');
var isArguments = require('../lib/is_arguments.js');
var objectKeys = require('../lib/keys.js');

test('equal', function (t) {
t.ok(equal(
Expand Down Expand Up @@ -56,21 +54,6 @@ test('arguments class', function (t) {
t.end();
});

test('test the arguments shim', function (t) {
t.ok(isArguments.supported((function(){return arguments})()));
t.notOk(isArguments.supported([1,2,3]));

t.ok(isArguments.unsupported((function(){return arguments})()));
t.notOk(isArguments.unsupported([1,2,3]));

t.end();
});

test('test the keys shim', function (t) {
t.deepEqual(objectKeys.shim({ a: 1, b : 2 }), [ 'a', 'b' ]);
t.end();
});

test('dates', function (t) {
var d0 = new Date(1387585278000);
var d1 = new Date('Fri Dec 20 2013 16:21:18 GMT-0800 (PST)');
Expand Down

0 comments on commit 3b503fb

Please sign in to comment.