mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 19:07:49 +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;
|
setPlaceholder = true;
|
||||||
func.placeholder = result.placeholder = placeholder;
|
func.placeholder = result.placeholder = placeholder;
|
||||||
}
|
}
|
||||||
|
result.convert = function(options) {
|
||||||
|
return baseConvert(util, name, func, options);
|
||||||
|
};
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -26,8 +26,25 @@ var extend = require('lodash/fp/extend');
|
|||||||
## Convert
|
## Convert
|
||||||
|
|
||||||
Although `lodash/fp` & its method modules come pre-converted, there are times when
|
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.
|
you may want to customize the conversion. That’s when the `convert` method comes in handy.
|
||||||
That’s when the `convert` module 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
|
```js
|
||||||
var convert = require('lodash/fp/convert');
|
var convert = require('lodash/fp/convert');
|
||||||
@@ -45,7 +62,7 @@ var fp = convert({
|
|||||||
var fp = convert(lodash.runInContext());
|
var fp = convert(lodash.runInContext());
|
||||||
```
|
```
|
||||||
|
|
||||||
It’s even customizable.
|
It’s customizable too.
|
||||||
```js
|
```js
|
||||||
// Every option is `true` by default.
|
// Every option is `true` by default.
|
||||||
var filter = convert('filter', _.filter, {
|
var filter = convert('filter', _.filter, {
|
||||||
|
|||||||
Reference in New Issue
Block a user