All files / boundless/packages/boundless-utils-omit-keys index.js

100% Statements 4/4
100% Branches 3/3
100% Functions 2/2
100% Lines 4/4
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23                            2x 4x 3x     4x      
/**
 * Returns a modified version of the supplied object without the given keys.
 *
 * ## Example Usage
 *
 * ```js
 * import omitKeys from 'boundless-utils-omit-keys';
 *
 * const obj = {foo: 'bar', bar: 'baz'};
 *
 * omitKeys(obj, ['bar']); // returns `{foo: 'bar'}`
 * ```
 */
export default function omitKeysFromSourceObject(source, omittedKeys = []) {
    return Object.keys(source).reduce(function relocateAcceptedKeys(hash, key) {
        if (omittedKeys.indexOf(key) === -1) {
            hash[key] = source[key];
        }
 
        return hash;
    }, {});
}