Add _.thru doc example and add pattern param to _.words. [ci skip]

This commit is contained in:
John-David Dalton
2014-09-09 23:32:06 -07:00
parent 336e5e0ff7
commit 967ce824f7

View File

@@ -4485,11 +4485,11 @@
* @returns {*} Returns `value`. * @returns {*} Returns `value`.
* @example * @example
* *
* _([1, 2, 3, 4]) * _([1, 2, 3])
* .tap(function(array) { array.pop(); }) * .tap(function(array) { array.pop(); })
* .reverse() * .reverse()
* .value(); * .value();
* // => [3, 2, 1] * // => [2, 1]
*/ */
function tap(value, interceptor, thisArg) { function tap(value, interceptor, thisArg) {
interceptor.call(thisArg, value); interceptor.call(thisArg, value);
@@ -4507,6 +4507,12 @@
* @param {*} [thisArg] The `this` binding of `interceptor`. * @param {*} [thisArg] The `this` binding of `interceptor`.
* @returns {*} Returns the result of `interceptor`. * @returns {*} Returns the result of `interceptor`.
* @example * @example
*
* _([1, 2, 3])
* .last()
* .thru(function(value) { return [value]; })
* .value();
* // => [3]
*/ */
function thru(value, interceptor, thisArg) { function thru(value, interceptor, thisArg) {
return interceptor.call(thisArg, value); return interceptor.call(thisArg, value);
@@ -8756,15 +8762,19 @@
* @memberOf _ * @memberOf _
* @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.
* @returns {Array} Returns the words of `string`. * @returns {Array} Returns the words of `string`.
* @example * @example
* *
* _.words('hello world'); * _.words('fred, barney, & pebbles');
* // => ['hello', 'world'] * // => ['fred', 'barney', 'pebbles']
*
* _.words('fred, barney, & pebbles', /[^, ]+/g);
* // => ['fred', 'barney', '&', 'pebbles']
*/ */
function words(string) { function words(string, pattern) {
string = string == null ? '' : String(string); string = string == null ? '' : String(string);
return (string && string.match(reWords)) || []; return (string && string.match(pattern || reWords)) || [];
} }
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/