mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 11:27:50 +00:00
Ensure _.trunc and _.words work as a callback for methods like _.map
This commit is contained in:
22
lodash.js
22
lodash.js
@@ -23,6 +23,10 @@
|
|||||||
PARTIAL_FLAG = 32,
|
PARTIAL_FLAG = 32,
|
||||||
PARTIAL_RIGHT_FLAG = 64;
|
PARTIAL_RIGHT_FLAG = 64;
|
||||||
|
|
||||||
|
/** Used as default options for `_.trunc` */
|
||||||
|
var DEFAULT_TRUNC_LENGTH = 30,
|
||||||
|
DEFAULT_TRUNC_OMISSION = '...';
|
||||||
|
|
||||||
/** Used to detect when a function becomes hot */
|
/** Used to detect when a function becomes hot */
|
||||||
var HOT_COUNT = 150,
|
var HOT_COUNT = 150,
|
||||||
HOT_SPAN = 16;
|
HOT_SPAN = 16;
|
||||||
@@ -80,8 +84,8 @@
|
|||||||
/** Used to detect host constructors (Safari > 5) */
|
/** Used to detect host constructors (Safari > 5) */
|
||||||
var reHostCtor = /^\[object .+?Constructor\]$/;
|
var reHostCtor = /^\[object .+?Constructor\]$/;
|
||||||
|
|
||||||
/** Used to match latin-1 supplement letters */
|
/** Used to match latin-1 supplement letters (excluding mathematical operators) */
|
||||||
var reLatin1 = /[\xC0-\xFF]/g;
|
var reLatin1 = /[\xC0-\xD6\xD8-\xDE\xDF-\xF6\xF8-\xFF]/g;
|
||||||
|
|
||||||
/** Used to ensure capturing order of template delimiters */
|
/** Used to ensure capturing order of template delimiters */
|
||||||
var reNoMatch = /($^)/;
|
var reNoMatch = /($^)/;
|
||||||
@@ -253,7 +257,7 @@
|
|||||||
'\xDD': 'Y', '\xFD': 'y', '\xFF': 'y',
|
'\xDD': 'Y', '\xFD': 'y', '\xFF': 'y',
|
||||||
'\xC6': 'Ae', '\xE6': 'ae',
|
'\xC6': 'Ae', '\xE6': 'ae',
|
||||||
'\xDE': 'Th', '\xFE': 'th',
|
'\xDE': 'Th', '\xFE': 'th',
|
||||||
'\xDF': 'ss', '\xD7': ' ', '\xF7': ' '
|
'\xDF': 'ss'
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Used to determine if values are of the language type `Object` */
|
/** Used to determine if values are of the language type `Object` */
|
||||||
@@ -8683,9 +8687,11 @@
|
|||||||
* _.trunc('hi-diddly-ho there, neighborino', { 'omission': ' [...]' });
|
* _.trunc('hi-diddly-ho there, neighborino', { 'omission': ' [...]' });
|
||||||
* // => 'hi-diddly-ho there, neig [...]'
|
* // => 'hi-diddly-ho there, neig [...]'
|
||||||
*/
|
*/
|
||||||
function trunc(string, options) {
|
function trunc(string, options, guard) {
|
||||||
var length = 30,
|
options = guard ? null : options;
|
||||||
omission = '...';
|
|
||||||
|
var length = DEFAULT_TRUNC_LENGTH,
|
||||||
|
omission = DEFAULT_TRUNC_OMISSION;
|
||||||
|
|
||||||
if (isObject(options)) {
|
if (isObject(options)) {
|
||||||
var separator = 'separator' in options ? options.separator : separator;
|
var separator = 'separator' in options ? options.separator : separator;
|
||||||
@@ -8764,6 +8770,7 @@
|
|||||||
* @category String
|
* @category String
|
||||||
* @param {string} [string=''] The string to inspect.
|
* @param {string} [string=''] The string to inspect.
|
||||||
* @param {RegExp|string} [pattern] The pattern to match words.
|
* @param {RegExp|string} [pattern] The pattern to match words.
|
||||||
|
* @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
|
||||||
* @returns {Array} Returns the words of `string`.
|
* @returns {Array} Returns the words of `string`.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
@@ -8773,8 +8780,9 @@
|
|||||||
* _.words('fred, barney, & pebbles', /[^, ]+/g);
|
* _.words('fred, barney, & pebbles', /[^, ]+/g);
|
||||||
* // => ['fred', 'barney', '&', 'pebbles']
|
* // => ['fred', 'barney', '&', 'pebbles']
|
||||||
*/
|
*/
|
||||||
function words(string, pattern) {
|
function words(string, pattern, guard) {
|
||||||
string = string != null && String(string);
|
string = string != null && String(string);
|
||||||
|
pattern = guard ? null : pattern;
|
||||||
return (string && string.match(pattern || reWords)) || [];
|
return (string && string.match(pattern || reWords)) || [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user