mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-03 00:27:50 +00:00
Add reconvert method to fp functions.
This commit is contained in:
committed by
John-David Dalton
parent
9e11ebb62a
commit
c406e33fcc
@@ -279,6 +279,9 @@ function baseConvert(util, name, func, options) {
|
||||
setPlaceholder = true;
|
||||
func.placeholder = result.placeholder = placeholder;
|
||||
}
|
||||
result.convert = function(options) {
|
||||
return baseConvert(util, name, func, options);
|
||||
};
|
||||
return result;
|
||||
};
|
||||
|
||||
|
||||
@@ -26,8 +26,25 @@ var extend = require('lodash/fp/extend');
|
||||
## Convert
|
||||
|
||||
Although `lodash/fp` & its method modules come pre-converted, there are times when
|
||||
you may want to convert another lodash package or create a customized conversion.
|
||||
That’s when the `convert` module comes in handy.
|
||||
you may want to customize the conversion. That’s when the `convert` method comes in handy.
|
||||
|
||||
|
||||
```js
|
||||
// Disable capping of the iteratee arguments so it is possible to access
|
||||
// the `key` argument
|
||||
var mapValuesWithKey = require("lodash/fp/mapValues").convert({cap: false});
|
||||
|
||||
mapValuesWithKey(function(value, key) {
|
||||
if (key === "foo") {
|
||||
return -1;
|
||||
}
|
||||
return value;
|
||||
}, {foo: 1, bar: 1});
|
||||
// => {foo: -1, bar: 1}
|
||||
```
|
||||
|
||||
It's also possible to use the convert function directly to convert functions or
|
||||
objects manually.
|
||||
|
||||
```js
|
||||
var convert = require('lodash/fp/convert');
|
||||
@@ -45,7 +62,7 @@ var fp = convert({
|
||||
var fp = convert(lodash.runInContext());
|
||||
```
|
||||
|
||||
It’s even customizable.
|
||||
It’s customizable too.
|
||||
```js
|
||||
// Every option is `true` by default.
|
||||
var filter = convert('filter', _.filter, {
|
||||
|
||||
Reference in New Issue
Block a user