diff --git a/keys.js b/keys.js new file mode 100644 index 0000000..66ddcb1 --- /dev/null +++ b/keys.js @@ -0,0 +1,15 @@ +/** + * @module object-loops/keys + */ + +/** + * Equivalent to `Object.keys`. Implemented specifically for chain. + * @function module:object-loops/keys + * @param {object} [obj] - object to get hasOwnProperty enumerable keys from + * @returns {array} keys + */ +module.exports = keys + +function keys (obj) { + return Object.keys(obj) +} diff --git a/test/test-keys.js b/test/test-keys.js new file mode 100644 index 0000000..0a2d79a --- /dev/null +++ b/test/test-keys.js @@ -0,0 +1,43 @@ +var Code = require('code') +var Lab = require('lab') +var lab = exports.lab = Lab.script() + +var describe = lab.describe +var it = lab.it +var before = lab.before +var after = lab.after +var expect = Code.expect + +var keys = require('../keys') + +describe('keys', function () { + function Person (name) { + this.name = name + } + Person.prototype.getName = function () { + return this.name + } + + describe('prototype', function () { + before(function (done) { + require('../index')() + done() + }) + after(require('./fixtures/reset-object-prototype')) + it('should get all direct enumerables keys from object', function (done) { + var objKeys = new Person('hey').keys() + // assertions + expect(objKeys).to.deep.equal(['name']) + done() + }) + }) + + describe('require', function () { + it('should get all direct enumerables keys from object', function (done) { + var objKeys = keys(new Person('hey')) + // assertions + expect(objKeys).to.deep.equal(['name']) + done() + }) + }) +})