mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 10:27:49 +00:00
Split out setWrapToString.
This commit is contained in:
38
lodash.js
38
lodash.js
@@ -145,7 +145,8 @@
|
|||||||
|
|
||||||
/** Used to match wrap detail comments. */
|
/** Used to match wrap detail comments. */
|
||||||
var reWrapComment = /\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,
|
var reWrapComment = /\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,
|
||||||
reWrapDetails = /\{\n\/\* \[wrapped with (.+)\] \*/;
|
reWrapDetails = /\{\n\/\* \[wrapped with (.+)\] \*/,
|
||||||
|
reSplitDetails = /,? & /;
|
||||||
|
|
||||||
/** Used to match non-compound words composed of alphanumeric characters. */
|
/** Used to match non-compound words composed of alphanumeric characters. */
|
||||||
var reBasicWord = /[a-zA-Z0-9]+/g;
|
var reBasicWord = /[a-zA-Z0-9]+/g;
|
||||||
@@ -6166,29 +6167,36 @@
|
|||||||
* @returns {Function} Returns `wrapper`.
|
* @returns {Function} Returns `wrapper`.
|
||||||
*/
|
*/
|
||||||
var setWrapToString = !defineProperty ? identity : function(wrapper, ref, bitmask) {
|
var setWrapToString = !defineProperty ? identity : function(wrapper, ref, bitmask) {
|
||||||
var string = (ref + ''),
|
var source = (ref + '');
|
||||||
match = string.match(reWrapDetails),
|
return defineProperty(wrapper, 'toString', {
|
||||||
details = match ? match[1].split(/, (?:& )| & /) : [];
|
'configurable': true,
|
||||||
|
'enumerable': false,
|
||||||
arrayEach(wrapFlags, function(pair) {
|
'value': constant(insertWrapDetails(source, updateWrapDetails(getWrapDetails(source), bitmask)))
|
||||||
if ((bitmask & pair[1]) && !arrayIncludes(details, '_.'+ pair[0])) {
|
|
||||||
details.push('_.' + pair[0]);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
function getWrapDetails(source) {
|
||||||
|
var match = source.match(reWrapDetails);
|
||||||
|
return match ? match[1].split(reSplitDetails) : [];
|
||||||
|
}
|
||||||
|
|
||||||
|
function insertWrapDetails(source, details) {
|
||||||
var length = details.length,
|
var length = details.length,
|
||||||
lastIndex = length - 1;
|
lastIndex = length - 1;
|
||||||
|
|
||||||
details[lastIndex] = (length > 1 ? '& ' : '') + details[lastIndex];
|
details[lastIndex] = (length > 1 ? '& ' : '') + details[lastIndex];
|
||||||
details = details.join(length > 2 ? ', ' : ' ');
|
details = details.join(length > 2 ? ', ' : ' ');
|
||||||
string = string.replace(reWrapComment, '{\n/* [wrapped with ' + details + '] */\n');
|
return source.replace(reWrapComment, '{\n/* [wrapped with ' + details + '] */\n');
|
||||||
|
}
|
||||||
|
|
||||||
return defineProperty(wrapper, 'toString', {
|
function updateWrapDetails(details, bitmask) {
|
||||||
'configurable': true,
|
arrayEach(wrapFlags, function(pair) {
|
||||||
'enumerable': false,
|
if ((bitmask & pair[1]) && !arrayIncludes(details, '_.'+ pair[0])) {
|
||||||
'value': constant(string)
|
details.push('_.' + pair[0]);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
return details.sort();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts `string` to a property path array.
|
* Converts `string` to a property path array.
|
||||||
|
|||||||
Reference in New Issue
Block a user