Add reconvert method to fp functions.

This commit is contained in:
Esa-Matti Suuronen
2016-03-03 17:34:32 +00:00
committed by John-David Dalton
parent 9e11ebb62a
commit c406e33fcc
2 changed files with 23 additions and 3 deletions

View File

@@ -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;
};

View File

@@ -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.
Thats when the `convert` module comes in handy.
you may want to customize the conversion. Thats 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());
```
Its even customizable.
Its customizable too.
```js
// Every option is `true` by default.
var filter = convert('filter', _.filter, {