-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8c0781a
commit 049c528
Showing
3 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { lodashFpConvertOptions } from '../core/consts' | ||
import pickBy from 'lodash/fp/pickBy' | ||
import update from '../core/update' | ||
|
||
const rawPickBy = pickBy.convert(lodashFpConvertOptions) | ||
|
||
/** | ||
* Creates an object composed of the object properties predicate returns truthy | ||
* for. The predicate is invoked with two arguments: (value, key). | ||
* @function pickBy | ||
* @memberof object | ||
* @param {Object} object The object to modify. | ||
* @param {Array|string} path The path of the property to set. | ||
* @param {function} [predicate={@link https://lodash.com/docs#identity|lodash.identity}] The function invoked per iteration. | ||
* @return {Object} Returns the updated object. | ||
* @example pickBy({ nested: { a: 1, b: 2, c: 3, d: 4 } }, 'nested', v => v < 3) // => { nested: { a: 1, b: 2 } } | ||
* @see {@link core.update|update} for more information. | ||
* @see {@link https://lodash.com/docs#pickBy|lodash.pickBy} for more information. | ||
* @see {@link https://lodash.com/docs#identity|lodash.identity} for more information. | ||
* @since 0.1.12 | ||
*/ | ||
export default update(rawPickBy) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* eslint-env node, mocha */ | ||
import { expect } from 'chai' | ||
import pickBy from './pickBy' | ||
|
||
describe('PickBy', () => { | ||
|
||
const objectOne = { | ||
nested: { | ||
a: 1, | ||
b: 2, | ||
c: 3, | ||
d: 4, | ||
}, | ||
} | ||
const output = { | ||
nested: { | ||
a: 1, | ||
b: 2, | ||
}, | ||
} | ||
|
||
it('should pick all matching props by value', () => { | ||
expect(pickBy(objectOne, 'nested', v => v < 3)).to.be.deep.equal(output) | ||
}) | ||
|
||
it('should pick all matching props by key', () => { | ||
expect(pickBy(objectOne, 'nested', (v, k) => k < 'c')).to.be.deep.equal(output) | ||
}) | ||
}) |