Update and add tests for fp convert method.

This commit is contained in:
John-David Dalton
2016-03-04 00:55:59 -08:00
parent f6df126c43
commit 4debf155d7
4 changed files with 91 additions and 57 deletions

View File

@@ -41,10 +41,12 @@ function baseConvert(util, name, func, options) {
};
var forceRearg = ('rearg' in options) && options.rearg,
placeholder = isLib ? func : fallbackHolder;
placeholder = isLib ? func : fallbackHolder,
pristine = isLib ? func.runInContext() : undefined;
var helpers = isLib ? func : {
'ary': util.ary,
'assign': util.assign,
'clone': util.clone,
'curry': util.curry,
'forEach': util.forEach,
@@ -58,6 +60,7 @@ function baseConvert(util, name, func, options) {
};
var ary = helpers.ary,
assign = helpers.assign,
clone = helpers.clone,
curry = helpers.curry,
each = helpers.forEach,
@@ -226,8 +229,19 @@ function baseConvert(util, name, func, options) {
var wrap = function(name, func) {
name = mapping.aliasToReal[name] || name;
var wrapper = wrappers[name];
var convert = function(options) {
var newUtil = isLib ? pristine.runInContext() : helpers,
newFunc = isLib ? pristine[name] : func,
newOptions = assign(assign({}, config), options);
return baseConvert(newUtil, name, newFunc, newOptions);
};
if (wrapper) {
return wrapper(func);
var result = wrapper(func);
result.convert = convert;
return result;
}
var wrapped = func;
if (config.immutable) {
@@ -241,7 +255,6 @@ function baseConvert(util, name, func, options) {
wrapped = immutWrap(func, cloneByPath);
}
}
var result;
each(aryMethodKeys, function(aryKey) {
each(mapping.aryMethod[aryKey], function(otherName) {
if (name == otherName) {
@@ -275,13 +288,16 @@ function baseConvert(util, name, func, options) {
});
result || (result = wrapped);
if (result == func) {
result = function() {
return func.apply(this, arguments);
};
}
result.convert = convert;
if (mapping.placeholder[name]) {
setPlaceholder = true;
func.placeholder = result.placeholder = placeholder;
}
result.convert = function(options) {
return baseConvert(util, name, func, options);
};
return result;
};