From bce9138ca6ca692ae391b896dcf1ae43611c2f79 Mon Sep 17 00:00:00 2001 From: Vitor Abner Date: Mon, 8 May 2017 00:44:35 -0300 Subject: [PATCH] invalid-value: return same value to invalid value --- src/pokeprop.js | 7 ++++--- test/pokeprop.js | 14 ++++++++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/pokeprop.js b/src/pokeprop.js index 9850c8f..e635ec1 100644 --- a/src/pokeprop.js +++ b/src/pokeprop.js @@ -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) diff --git a/test/pokeprop.js b/test/pokeprop.js index 304ceef..5572518 100644 --- a/test/pokeprop.js +++ b/test/pokeprop.js @@ -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: { @@ -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) +})