From c406e33fcccc7aeb1d8db9328a1665c259622a25 Mon Sep 17 00:00:00 2001 From: Esa-Matti Suuronen Date: Thu, 3 Mar 2016 17:34:32 +0000 Subject: [PATCH] Add reconvert method to fp functions. --- fp/_baseConvert.js | 3 +++ lib/fp/template/doc/wiki.jst | 23 ++++++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/fp/_baseConvert.js b/fp/_baseConvert.js index b07410073..75973770d 100644 --- a/fp/_baseConvert.js +++ b/fp/_baseConvert.js @@ -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; }; diff --git a/lib/fp/template/doc/wiki.jst b/lib/fp/template/doc/wiki.jst index 7b69bf584..5e29262c7 100644 --- a/lib/fp/template/doc/wiki.jst +++ b/lib/fp/template/doc/wiki.jst @@ -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, {