mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 06:07:21 +01:00
16 lines
475 B
JavaScript
16 lines
475 B
JavaScript
// An utility to pick deep properties from an object.
|
|
// Works like _.pick but supports nested props (ie pickDeep(obj, ['deep.property']))
|
|
|
|
import each from 'lodash/each';
|
|
import set from 'lodash/set';
|
|
import get from 'lodash/get';
|
|
|
|
export default function pickDeep (obj, properties) {
|
|
if (!Array.isArray(properties)) throw new Error('"properties" must be an array');
|
|
|
|
const result = {};
|
|
each(properties, prop => set(result, prop, get(obj, prop)));
|
|
|
|
return result;
|
|
}
|