diff --git a/packages/junipero-utils/lib/core/index.js b/packages/junipero-utils/lib/core/index.js index 160b79c09..f8bccf530 100644 --- a/packages/junipero-utils/lib/core/index.js +++ b/packages/junipero-utils/lib/core/index.js @@ -3,7 +3,7 @@ export const classNames = (...args) => { args.map(arg => { if (!arg) { - return; + return false; } if (typeof arg === 'string' || typeof arg === 'number') { @@ -18,8 +18,12 @@ export const classNames = (...args) => { if (v) { classes.push(k); } + + return false; }); } + + return false; }); return classes.join(' '); @@ -81,3 +85,10 @@ export const cloneDeep = obj => res[k] = cloneDeep(v); return res; }, {}); + +export const fromPairs = (pairs = []) => + pairs.reduce((res, [k, v]) => { + res[k] = v; + + return res; + }, {}); diff --git a/packages/junipero-utils/lib/core/index.test.js b/packages/junipero-utils/lib/core/index.test.js index d4d70d088..636314a8d 100644 --- a/packages/junipero-utils/lib/core/index.test.js +++ b/packages/junipero-utils/lib/core/index.test.js @@ -10,6 +10,7 @@ import { omitBy, pick, cloneDeep, + fromPairs, } from './'; describe('core', () => { @@ -299,4 +300,14 @@ describe('core', () => { expect(error).toBeUndefined(); }); }); + + describe('fromPairs()', () => { + it('should allow to make an object from a table', () => { + const arr = [['foo', 'bar'], ['stuff', 'thing'], [0, true]]; + const obj = fromPairs(arr); + expect(obj.foo).toBe('bar'); + expect(obj.stuff).toBe('thing'); + expect(obj[0]).toBe(true); + }); + }); });