Skip to content

Commit

Permalink
added values-in w/ tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tjmehta committed Aug 21, 2016
1 parent d1c38c3 commit 24b51e0
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
43 changes: 43 additions & 0 deletions test/values-in.js
Original file line number Diff line number Diff line change
@@ -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 valuesIn = require('../values-in')

describe('valuesIn', 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 valuesIn from object', function (done) {
var objValues = new Person('hey').valuesIn()
// assertions
expect(objValues).to.deep.equal(['hey', Person.prototype.getName])
done()
})
})

describe('require', function () {
it('should get all direct enumerables valuesIn from object', function (done) {
var objValues = valuesIn(new Person('hey'))
// assertions
expect(objValues).to.deep.equal(['hey', Person.prototype.getName])
done()
})
})
})
17 changes: 17 additions & 0 deletions values-in.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* @module object-loops/values-in
*/
var keysIn = require('101/keys-in')
/**
* Like `keysIn`, but for values. Includes enumerable key's values from the prototype chain.
* @function module:object-loops/values-in
* @param {object} [obj] - object to get all (incl prototype) enumerable key's values from
* @returns {array} values
*/
module.exports = valuesIn

function valuesIn (obj) {
return keysIn(obj).map(function (key) {
return obj[key]
})
}

0 comments on commit 24b51e0

Please sign in to comment.