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

object-keys

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

object-keys - npm Package Compare versions

Comparing version 0.0.1 to 0.1.0

.npmignore

44

index.js

@@ -0,44 +1,2 @@

module.exports = Object.keys || require('./shim');
// modified from https://github.com/kriskowal/es5-shim
var has = Object.prototype.hasOwnProperty,
hasDontEnumBug = true,
dontEnums = [
"toString",
"toLocaleString",
"valueOf",
"hasOwnProperty",
"isPrototypeOf",
"propertyIsEnumerable",
"constructor"
],
dontEnumsLength = dontEnums.length;
for (var key in {"toString": null}) { hasDontEnumBug = false; }
var keysShim = function keys(object) {
if ((typeof object !== "object" && typeof object !== "function") || object === null) {
throw new TypeError("Object.keys called on a non-object");
}
var keys = [];
for (var name in object) {
if (has.call(object, name)) {
keys.push(name);
}
}
if (hasDontEnumBug) {
for (var i = 0, ii = dontEnumsLength; i < ii; i++) {
var dontEnum = dontEnums[i];
if (has.call(dontEnums, dontEnum)) {
keys.push(dontEnum);
}
}
}
return keys;
};
module.exports = {
keys: Object.keys || keysShim,
shim: keysShim
};
{
"name": "object-keys",
"version": "0.0.1",
"version": "0.1.0",
"author": "Jordan Harband",

@@ -13,3 +13,3 @@ "description": "An Object.keys replacement, in case Object.keys is not available. From https://github.com/kriskowal/es5-shim",

"type": "git",
"url": "git://github.com/ljharb/objectkeys.git"
"url": "git://github.com/ljharb/object-keys.git"
},

@@ -23,3 +23,4 @@ "keywords": [

"devDependencies": {
"tap": "~0.4.1"
"tap": "~0.4.1",
"tape": "~0.3.2"
},

@@ -29,12 +30,14 @@ "testling": {

"browsers": [
"ie/6..latest",
"firefox/3..latest",
"iexplore/6.0..latest",
"firefox/3.0",
"firefox/15.0..latest",
"firefox/nightly",
"chrome/4..latest",
"chrome/4.0",
"chrome/22.0..latest",
"chrome/canary",
"opera/10..latest",
"opera/10.0..latest",
"opera/next",
"safari/5..latest",
"ipad/6..latest",
"iphone/6..latest"
"safari/5.0.5..latest",
"ipad/6.0..latest",
"iphone/6.0..latest"
]

@@ -41,0 +44,0 @@ }

@@ -23,1 +23,4 @@ #object-keys

Implementation taken directly from https://github.com/kriskowal/es5-shim/blob/master/es5-shim.js#L542-589
## Tests
Tests currently use tape - which doesn't work in node 0.10, but works in browserify. Rest assured, they pass.

@@ -1,3 +0,4 @@

var test = require('tap').test;
var keys = require('./index.js').shim;
var test = require('tape'); // require('tap').test; // tape works in browserify, tap works in node 0.10
var shimmedKeys = require('./index.js');
var keys = require('./shim.js');

@@ -10,4 +11,22 @@ test('works', function (t) {

};
var objKeys = ['a', 'b', 'c'];
var obj = {
"str": "boz",
"obj": {},
"arr": [],
"bool": true,
"num": 42,
"null": null,
"undefined": undefined
};
var objKeys = ['str', 'obj', 'arr', 'bool', 'num', 'null', 'undefined'];
t.test('exports a function', function (st) {
st.plan(1);
if (Object.keys) {
st.equal(Object.keys, shimmedKeys, 'Object.keys is supported and exported');
} else {
st.equal(keys, shimmedKeys, 'Object.keys is not supported; shim is exported');
}
});
t.test('working with actual shim', function (st) {

@@ -19,9 +38,37 @@ st.plan(1);

t.test('works with an object literal', function (st) {
st.plan(2);
var theKeys = keys(obj);
st.equal(Array.isArray(theKeys), true, 'returns an array');
st.deepEqual(theKeys, objKeys, 'Object has expected keys');
});
t.test('returns names which are own properties', function (st) {
keys(obj).forEach(function (name) {
st.equal(obj.hasOwnProperty(name), true);
});
st.end();
});
t.test('returns names which are enumerable', function (st) {
var loopedValues = [];
for (var k in obj) {
loopedValues.push(k);
}
keys(obj).forEach(function (name) {
st.notEqual(loopedValues.indexOf(name), -1, name + ' is not enumerable');
});
st.end();
});
t.test('throws an error for a non-object', function (st) {
st.plan(1);
st.deepEqual(keys(obj), objKeys, 'Object has expected keys');
st.throws(function () {
return keys(42);
}, new RangeError(), 'throws on a non-object');
});
t.end();
});
test('works with an object instance', function (t) {
t.plan(1);
t.plan(2);
var Prototype = function () {};

@@ -31,4 +78,6 @@ Prototype.prototype.foo = true;

obj.bar = true;
t.deepEqual(keys(obj), ['bar'], 'Instance has expected keys');
var theKeys = keys(obj);
t.equal(Array.isArray(theKeys), true, 'returns an array');
t.deepEqual(theKeys, ['bar'], 'Instance has expected keys');
});
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