Add omitBy (#60)
This commit is contained in:
parent
37cf81dd83
commit
fce13afbf6
20
README.md
20
README.md
@ -395,6 +395,26 @@ var result = u({ user: u.omit(['authToken', 'SSN']) }, user);
|
||||
expect(result).to.eql({ user: { email: 'john@aol.com', username: 'john123' } });
|
||||
```
|
||||
|
||||
### `u.omitBy(predicate(, object))`
|
||||
|
||||
Remove properties. See [`_.omitBy`](https://lodash.com/docs#omitBy).
|
||||
|
||||
```js
|
||||
var user = {
|
||||
user: {
|
||||
email: 'john@aol.com',
|
||||
username: 'john123',
|
||||
authToken: '1211..',
|
||||
SSN: 5551234
|
||||
}
|
||||
};
|
||||
|
||||
function isSensitive(value, key) { return key == 'SSN' }
|
||||
var result = u({ user: u.omitBy(isSensitive, user);
|
||||
|
||||
expect(result).to.eql({ user: { email: 'john@aol.com', username: 'john123', authToken: '1211..' } });
|
||||
```
|
||||
|
||||
### `u.reject(predicate(, object))`
|
||||
|
||||
Reject items from an array. See [`_.reject`](https://lodash.com/docs#reject).
|
||||
|
@ -5,6 +5,7 @@ import _if from './if';
|
||||
import ifElse from './ifElse';
|
||||
import map from './map';
|
||||
import omit from './omit';
|
||||
import omitBy from './omitBy';
|
||||
import reject from './reject';
|
||||
import update from './update';
|
||||
import updateIn from './updateIn';
|
||||
@ -21,6 +22,7 @@ u.is = is;
|
||||
u.freeze = freeze;
|
||||
u.map = map;
|
||||
u.omit = omit;
|
||||
u.omitBy = omitBy;
|
||||
u.reject = reject;
|
||||
u.update = update;
|
||||
u.updateIn = updateIn;
|
||||
|
8
lib/omitBy.js
Normal file
8
lib/omitBy.js
Normal file
@ -0,0 +1,8 @@
|
||||
import _omitBy from 'lodash/omitBy';
|
||||
import wrap from './wrap';
|
||||
|
||||
function omitBy(predicate, collection) {
|
||||
return _omitBy(collection, predicate);
|
||||
}
|
||||
|
||||
export default wrap(omitBy);
|
15
test/omitBy-spec.js
Normal file
15
test/omitBy-spec.js
Normal file
@ -0,0 +1,15 @@
|
||||
import { expect } from 'chai';
|
||||
import u from '../lib';
|
||||
|
||||
describe('u.omitBy', () => {
|
||||
it('can omitBy with a function', () => {
|
||||
const predicate = (value, key) => (value === 7 && key === 'bar');
|
||||
const result = u({ foo: u.omitBy(predicate) }, { foo: { bar: 7, baz: 'a' } });
|
||||
|
||||
expect(result).to.eql({ foo: { baz: 'a' } });
|
||||
});
|
||||
|
||||
it('freezes the result', () => {
|
||||
expect(Object.isFrozen(u.omit('a', {}))).to.be.true;
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user