Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/pokeprop.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ const createPickedObject = pathValueList => (
R.reduce(mergePathValueList, {}, pathValueList)
)

const pokeprop = (propsPathList, obj) => (
R.pipe(createPathValueList(obj), createPickedObject)(propsPathList)
)
const pokeprop = (propsPathList, obj) => {
if (!R.is(Object, obj)) return obj
return R.pipe(createPathValueList(obj), createPickedObject)(propsPathList)
}

module.exports = R.curry(pokeprop)
14 changes: 10 additions & 4 deletions test/pokeprop.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
const { test } = require('ava')
const pokeprop = require('../src/pokeprop')

test('pokeprop: pick lib property from an object with one property', t => {
test('pick lib property from an object with one property', t => {
const object = { lib: 'pokeprop' }
const picked = pokeprop(['lib'], object)
t.deepEqual(picked, object)
})

test('pokeprop: pick lib.name property from an object with nested property', t => {
test('pick lib.name property from an object with nested property', t => {
const object = { lib: { name: 'pokeprop' } }
const picked = pokeprop(['lib.name'], object)
t.deepEqual(picked, object)
})

test('pokeprop: pick multiplies properties from an object with multiples properties', t => {
test('pick multiplies properties from an object with multiples properties', t => {
const object = {
company: {
facebook: {
Expand Down Expand Up @@ -52,8 +52,14 @@ test('pokeprop: pick multiplies properties from an object with multiples propert
})
})

test('pokeprop: pick lib property from an object with one property using curried pokeprop', t => {
test('pick lib property from an object with one property using curried pokeprop', t => {
const object = { lib: 'pokeprop' }
const picked = pokeprop(['lib'])(object)
t.deepEqual(picked, object)
})

test('try to pick lib property from a string', t => {
const string = 'pokeprop'
const picked = pokeprop(['lib'])(string)
t.deepEqual(picked, string)
})