Skip to content
This repository has been archived by the owner on Jan 6, 2025. It is now read-only.

Add lodash object functions #83

Merged
merged 7 commits into from
Sep 3, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
✨ Add object.omitBy
  • Loading branch information
nlepage committed Sep 3, 2017
commit 27d126befab527ab9a0613043af78a050ba1ff17
2 changes: 2 additions & 0 deletions src/object/index.js
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ import { mapKeys } from './mapKeys'
import { mapValues } from './mapValues'
import { merge } from './merge'
import { omit } from './omit'
import { omitBy } from './omitBy'
import { pickBy } from './pickBy'
import { set } from './set'
import { unset } from './unset'
@@ -21,6 +22,7 @@ export {
mapValues,
merge,
omit,
omitBy,
pickBy,
set,
unset,
17 changes: 17 additions & 0 deletions src/object/omitBy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import _omitBy from 'lodash/omitBy'
import { convert } from 'util/convert'

/**
* Replaces by an object omitting properties that <code>predicate</code> doesn't return truthy for.
* @function
* @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 property.
* @return {Object} Returns the updated object.
* @example omitBy({ nested: { a: 1, b: 2, c: 3 } }, 'nested', v => v === 2) // => { nested: { a:1, c: 3 } }
* @see {@link https://lodash.com/docs#omitBy|lodash.omitBy} for more information.
* @since 0.3.0
*/
const omitBy = convert(_omitBy)
export { omitBy, omitBy as default }
31 changes: 31 additions & 0 deletions src/object/omitBy.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* eslint-env jest */
import { immutaTest } from 'test.utils'
import { omitBy } from './omitBy'

describe('OmitBy', () => {

it('should omit properties matching predicate', () => {
immutaTest((input, path) => {
const output = omitBy(input, path, v => v === 2)
expect(output).toEqual({
nested: {
prop: {
a: 1,
c: 3,
},
},
other: {},
})
return output
}, {
nested: {
prop: {
a: 1,
b: 2,
c: 3,
},
},
other: {},
}, 'nested.prop')
})
})