Compare commits

...

2 Commits

Author SHA1 Message Date
jdalton
9e749daefa Bump to v3.1.0. 2015-02-04 00:42:01 -08:00
jdalton
bbec03c4d5 Bump to v3.0.1. 2015-02-04 00:40:48 -08:00
31 changed files with 184 additions and 106 deletions

View File

@@ -1,4 +1,4 @@
# lodash v3.0.0 # lodash v3.1.0
The [modern build](https://github.com/lodash/lodash/wiki/Build-Differences) of [lodash](https://lodash.com/) exported as [Node.js](http://nodejs.org/)/[io.js](https://iojs.org/) modules. The [modern build](https://github.com/lodash/lodash/wiki/Build-Differences) of [lodash](https://lodash.com/) exported as [Node.js](http://nodejs.org/)/[io.js](https://iojs.org/) modules.
@@ -28,7 +28,7 @@ var array = require('lodash/array');
var chunk = require('lodash/array/chunk'); var chunk = require('lodash/array/chunk');
``` ```
See the [package source](https://github.com/lodash/lodash/tree/3.0.0-npm) for more details. See the [package source](https://github.com/lodash/lodash/tree/3.1.0-npm) for more details.
**Note:**<br> **Note:**<br>
Dont assign values to the [special variable](http://nodejs.org/api/repl.html#repl_repl_features) `_` when in the REPL.<br> Dont assign values to the [special variable](http://nodejs.org/api/repl.html#repl_repl_features) `_` when in the REPL.<br>
@@ -39,8 +39,8 @@ Install [n_](https://www.npmjs.com/package/n_) for a REPL that includes lodash b
lodash is also available in a variety of other builds & module formats. lodash is also available in a variety of other builds & module formats.
* npm packages for [modern](https://www.npmjs.com/package/lodash), [compatibility](https://www.npmjs.com/package/lodash-compat), & [per method](https://www.npmjs.com/browse/keyword/lodash-modularized) builds * npm packages for [modern](https://www.npmjs.com/package/lodash), [compatibility](https://www.npmjs.com/package/lodash-compat), & [per method](https://www.npmjs.com/browse/keyword/lodash-modularized) builds
* AMD modules for [modern](https://github.com/lodash/lodash/tree/3.0.0-amd) & [compatibility](https://github.com/lodash/lodash-compat/tree/3.0.0-amd) builds * AMD modules for [modern](https://github.com/lodash/lodash/tree/3.1.0-amd) & [compatibility](https://github.com/lodash/lodash-compat/tree/3.1.0-amd) builds
* ES modules for the [modern](https://github.com/lodash/lodash/tree/3.0.0-es) build * ES modules for the [modern](https://github.com/lodash/lodash/tree/3.1.0-es) build
## Further Reading ## Further Reading
@@ -97,7 +97,7 @@ lodash is also available in a variety of other builds & module formats.
* [_.bind](https://lodash.com/docs#bind), [_.curry](https://lodash.com/docs#curry), [_.partial](https://lodash.com/docs#partial), & * [_.bind](https://lodash.com/docs#bind), [_.curry](https://lodash.com/docs#curry), [_.partial](https://lodash.com/docs#partial), &
[more](https://lodash.com/docs "_.bindKey, _.curryRight, _.partialRight") support customizable argument placeholders [more](https://lodash.com/docs "_.bindKey, _.curryRight, _.partialRight") support customizable argument placeholders
* [_.capitalize](https://lodash.com/docs#capitalize), [_.trim](https://lodash.com/docs#trim), & * [_.capitalize](https://lodash.com/docs#capitalize), [_.trim](https://lodash.com/docs#trim), &
[more](https://lodash.com/docs "_.camelCase, _.deburr, _.endsWith, _.escapeRegExp, _.kebabCase, _.pad, _.padLeft, _.padRight, _.repeat, _.snakeCase, _.startsWith, _.trimLeft, _.trimRight, _.trunc, _.words") string methods [more](https://lodash.com/docs "_.camelCase, _.deburr, _.endsWith, _.escapeRegExp, _.kebabCase, _.pad, _.padLeft, _.padRight, _.repeat, _.snakeCase, _.startCase, _.startsWith, _.trimLeft, _.trimRight, _.trunc, _.words") string methods
* [_.clone](https://lodash.com/docs#clone), [_.isEqual](https://lodash.com/docs#isEqual), & * [_.clone](https://lodash.com/docs#clone), [_.isEqual](https://lodash.com/docs#isEqual), &
[more](https://lodash.com/docs "_.assign, _.cloneDeep, _.merge") accept callbacks [more](https://lodash.com/docs "_.assign, _.cloneDeep, _.merge") accept callbacks
* [_.dropWhile](https://lodash.com/docs#dropWhile), [_.takeWhile](https://lodash.com/docs#takeWhile), & * [_.dropWhile](https://lodash.com/docs#dropWhile), [_.takeWhile](https://lodash.com/docs#takeWhile), &
@@ -109,6 +109,6 @@ lodash is also available in a variety of other builds & module formats.
## Support ## Support
Tested in Chrome 39-40, Firefox 34-35, IE 6-11, Opera 25-26, Safari 5-8, io.js 1.0.4, Node.js 0.8.28 & 0.10.35, PhantomJS 1.9.8, RingoJS 0.11, & Rhino 1.7RC5. Tested in Chrome 39-40, Firefox 34-35, IE 6-11, Opera 26-27, Safari 5-8, io.js 1.0.4, Node.js 0.8.28 & 0.10.35, PhantomJS 1.9.8, RingoJS 0.11, & Rhino 1.7RC5.
Automated [browser](https://saucelabs.com/u/lodash) & [CI](https://travis-ci.org/lodash/lodash/) test runs are available. Special thanks to [Sauce Labs](https://saucelabs.com/) for providing automated browser testing. Automated [browser](https://saucelabs.com/u/lodash) & [CI](https://travis-ci.org/lodash/lodash/) test runs are available. Special thanks to [Sauce Labs](https://saucelabs.com/) for providing automated browser testing.

View File

@@ -57,14 +57,14 @@ var hasOwnProperty = objectProto.hasOwnProperty;
* `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`, `has`, * `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`, `has`,
* `identity`, `includes`, `indexOf`, `isArguments`, `isArray`, `isBoolean`, * `identity`, `includes`, `indexOf`, `isArguments`, `isArray`, `isBoolean`,
* `isDate`, `isElement`, `isEmpty`, `isEqual`, `isError`, `isFinite`, * `isDate`, `isElement`, `isEmpty`, `isEqual`, `isError`, `isFinite`,
* `isFunction`, `isMatch` , `isNative`, `isNaN`, `isNull`, `isNumber`, * `isFunction`, `isMatch`, `isNative`, `isNaN`, `isNull`, `isNumber`,
* `isObject`, `isPlainObject`, `isRegExp`, `isString`, `isUndefined`, * `isObject`, `isPlainObject`, `isRegExp`, `isString`, `isUndefined`,
* `isTypedArray`, `join`, `kebabCase`, `last`, `lastIndexOf`, `max`, `min`, * `isTypedArray`, `join`, `kebabCase`, `last`, `lastIndexOf`, `max`, `min`,
* `noConflict`, `now`, `pad`, `padLeft`, `padRight`, `parseInt`, `pop`, * `noConflict`, `now`, `pad`, `padLeft`, `padRight`, `parseInt`, `pop`,
* `random`, `reduce`, `reduceRight`, `repeat`, `result`, `runInContext`, * `random`, `reduce`, `reduceRight`, `repeat`, `result`, `runInContext`,
* `shift`, `size`, `snakeCase`, `some`, `sortedIndex`, `sortedLastIndex`, * `shift`, `size`, `snakeCase`, `some`, `sortedIndex`, `sortedLastIndex`,
* `startsWith`, `template`, `trim`, `trimLeft`, `trimRight`, `trunc`, * `startCase`, `startsWith`, `template`, `trim`, `trimLeft`, `trimRight`,
* `unescape`, `uniqueId`, `value`, and `words` * `trunc`, `unescape`, `uniqueId`, `value`, and `words`
* *
* The wrapper function `sample` will return a wrapped value when `n` is provided, * The wrapper function `sample` will return a wrapped value when `n` is provided,
* otherwise an unwrapped value is returned. * otherwise an unwrapped value is returned.

View File

@@ -25,6 +25,9 @@ var LazyWrapper = require('../internal/LazyWrapper'),
function wrapperReverse() { function wrapperReverse() {
var value = this.__wrapped__; var value = this.__wrapped__;
if (value instanceof LazyWrapper) { if (value instanceof LazyWrapper) {
if (this.__actions__.length) {
value = new LazyWrapper(this);
}
return new LodashWrapper(value.reverse()); return new LodashWrapper(value.reverse());
} }
return this.thru(function(value) { return this.thru(function(value) {

View File

@@ -1,5 +1,5 @@
var find = require('./find'), var baseMatches = require('../internal/baseMatches'),
matches = require('../utility/matches'); find = require('./find');
/** /**
* Performs a deep comparison between each element in `collection` and the * Performs a deep comparison between each element in `collection` and the
@@ -26,7 +26,7 @@ var find = require('./find'),
* // => 'fred' * // => 'fred'
*/ */
function findWhere(collection, source) { function findWhere(collection, source) {
return find(collection, matches(source)); return find(collection, baseMatches(source));
} }
module.exports = findWhere; module.exports = findWhere;

View File

@@ -23,7 +23,7 @@ var arrayEach = require('../internal/arrayEach'),
* @returns {Array|Object|string} Returns `collection`. * @returns {Array|Object|string} Returns `collection`.
* @example * @example
* *
* _([1, 2, 3]).forEach(function(n) { console.log(n); }); * _([1, 2, 3]).forEach(function(n) { console.log(n); }).value();
* // => logs each value from left to right and returns the array * // => logs each value from left to right and returns the array
* *
* _.forEach({ 'one': 1, 'two': 2, 'three': 3 }, function(n, key) { console.log(n, key); }); * _.forEach({ 'one': 1, 'two': 2, 'three': 3 }, function(n, key) { console.log(n, key); });

View File

@@ -1,5 +1,5 @@
var map = require('./map'), var baseProperty = require('../internal/baseProperty'),
property = require('../utility/property'); map = require('./map');
/** /**
* Gets the value of `key` from all elements in `collection`. * Gets the value of `key` from all elements in `collection`.
@@ -25,7 +25,7 @@ var map = require('./map'),
* // => [36, 40] (iteration order is not guaranteed) * // => [36, 40] (iteration order is not guaranteed)
*/ */
function pluck(collection, key) { function pluck(collection, key) {
return map(collection, property(key)); return map(collection, baseProperty(key + ''));
} }
module.exports = pluck; module.exports = pluck;

View File

@@ -1,5 +1,5 @@
var filter = require('./filter'), var baseMatches = require('../internal/baseMatches'),
matches = require('../utility/matches'); filter = require('./filter');
/** /**
* Performs a deep comparison between each element in `collection` and the * Performs a deep comparison between each element in `collection` and the
@@ -29,7 +29,7 @@ var filter = require('./filter'),
* // => ['barney', 'fred'] * // => ['barney', 'fred']
*/ */
function where(collection, source) { function where(collection, source) {
return filter(collection, matches(source)); return filter(collection, baseMatches(source));
} }
module.exports = where; module.exports = where;

View File

@@ -35,7 +35,7 @@ var FUNC_ERROR_TEXT = 'Expected a function';
* // => 'FRED' * // => 'FRED'
* *
* // modifying the result cache * // modifying the result cache
* upperCase.cache.set('fred, 'BARNEY'); * upperCase.cache.set('fred', 'BARNEY');
* upperCase('fred'); * upperCase('fred');
* // => 'BARNEY' * // => 'BARNEY'
* *

129
index.js
View File

@@ -1,6 +1,6 @@
/** /**
* @license * @license
* lodash 3.0.0 (Custom Build) <https://lodash.com/> * lodash 3.1.0 (Custom Build) <https://lodash.com/>
* Build: `lodash modern -d -o ./index.js` * Build: `lodash modern -d -o ./index.js`
* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/> * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
* Based on Underscore.js 1.7.0 <http://underscorejs.org/LICENSE> * Based on Underscore.js 1.7.0 <http://underscorejs.org/LICENSE>
@@ -13,7 +13,7 @@
var undefined; var undefined;
/** Used as the semantic version number. */ /** Used as the semantic version number. */
var VERSION = '3.0.0'; var VERSION = '3.1.0';
/** Used to compose bitmasks for wrapper metadata. */ /** Used to compose bitmasks for wrapper metadata. */
var BIND_FLAG = 1, var BIND_FLAG = 1,
@@ -769,7 +769,7 @@
/** /**
* Used as the maximum length of an array-like value. * Used as the maximum length of an array-like value.
* See the [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength) * See the [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.max_safe_integer)
* for more details. * for more details.
*/ */
var MAX_SAFE_INTEGER = Math.pow(2, 53) - 1; var MAX_SAFE_INTEGER = Math.pow(2, 53) - 1;
@@ -827,14 +827,14 @@
* `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`, `has`, * `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`, `has`,
* `identity`, `includes`, `indexOf`, `isArguments`, `isArray`, `isBoolean`, * `identity`, `includes`, `indexOf`, `isArguments`, `isArray`, `isBoolean`,
* `isDate`, `isElement`, `isEmpty`, `isEqual`, `isError`, `isFinite`, * `isDate`, `isElement`, `isEmpty`, `isEqual`, `isError`, `isFinite`,
* `isFunction`, `isMatch` , `isNative`, `isNaN`, `isNull`, `isNumber`, * `isFunction`, `isMatch`, `isNative`, `isNaN`, `isNull`, `isNumber`,
* `isObject`, `isPlainObject`, `isRegExp`, `isString`, `isUndefined`, * `isObject`, `isPlainObject`, `isRegExp`, `isString`, `isUndefined`,
* `isTypedArray`, `join`, `kebabCase`, `last`, `lastIndexOf`, `max`, `min`, * `isTypedArray`, `join`, `kebabCase`, `last`, `lastIndexOf`, `max`, `min`,
* `noConflict`, `now`, `pad`, `padLeft`, `padRight`, `parseInt`, `pop`, * `noConflict`, `now`, `pad`, `padLeft`, `padRight`, `parseInt`, `pop`,
* `random`, `reduce`, `reduceRight`, `repeat`, `result`, `runInContext`, * `random`, `reduce`, `reduceRight`, `repeat`, `result`, `runInContext`,
* `shift`, `size`, `snakeCase`, `some`, `sortedIndex`, `sortedLastIndex`, * `shift`, `size`, `snakeCase`, `some`, `sortedIndex`, `sortedLastIndex`,
* `startsWith`, `template`, `trim`, `trimLeft`, `trimRight`, `trunc`, * `startCase`, `startsWith`, `template`, `trim`, `trimLeft`, `trimRight`,
* `unescape`, `uniqueId`, `value`, and `words` * `trunc`, `unescape`, `uniqueId`, `value`, and `words`
* *
* The wrapper function `sample` will return a wrapped value when `n` is provided, * The wrapper function `sample` will return a wrapped value when `n` is provided,
* otherwise an unwrapped value is returned. * otherwise an unwrapped value is returned.
@@ -1060,11 +1060,14 @@
* @returns {Object} Returns the new reversed `LazyWrapper` object. * @returns {Object} Returns the new reversed `LazyWrapper` object.
*/ */
function lazyReverse() { function lazyReverse() {
var filtered = this.filtered, if (this.filtered) {
result = filtered ? new LazyWrapper(this) : this.clone(); var result = new LazyWrapper(this);
result.dir = -1;
result.dir = this.dir * -1; result.filtered = true;
result.filtered = filtered; } else {
result = this.clone();
result.dir *= -1;
}
return result; return result;
} }
@@ -1083,12 +1086,12 @@
} }
var dir = this.dir, var dir = this.dir,
isRight = dir < 0, isRight = dir < 0,
length = array.length, view = getView(0, array.length, this.views),
view = getView(0, length, this.views),
start = view.start, start = view.start,
end = view.end, end = view.end,
length = end - start,
dropCount = this.dropCount, dropCount = this.dropCount,
takeCount = nativeMin(end - start, this.takeCount - dropCount), takeCount = nativeMin(length, this.takeCount - dropCount),
index = isRight ? end : start - 1, index = isRight ? end : start - 1,
iteratees = this.iteratees, iteratees = this.iteratees,
iterLength = iteratees ? iteratees.length : 0, iterLength = iteratees ? iteratees.length : 0,
@@ -1124,7 +1127,7 @@
result[resIndex++] = value; result[resIndex++] = value;
} }
} }
return isRight ? result.reverse() : result; return result;
} }
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
@@ -1644,8 +1647,8 @@
} }
// Handle "_.property" and "_.matches" style callback shorthands. // Handle "_.property" and "_.matches" style callback shorthands.
return type == 'object' return type == 'object'
? baseMatches(func, !argCount) ? baseMatches(func)
: baseProperty(argCount ? baseToString(func) : func); : baseProperty(func + '');
} }
/** /**
@@ -2265,10 +2268,9 @@
* *
* @private * @private
* @param {Object} source The object of property values to match. * @param {Object} source The object of property values to match.
* @param {boolean} [isCloned] Specify cloning the source object.
* @returns {Function} Returns the new function. * @returns {Function} Returns the new function.
*/ */
function baseMatches(source, isCloned) { function baseMatches(source) {
var props = keys(source), var props = keys(source),
length = props.length; length = props.length;
@@ -2282,9 +2284,6 @@
}; };
} }
} }
if (isCloned) {
source = baseClone(source, true);
}
var values = Array(length), var values = Array(length),
strictCompareFlags = Array(length); strictCompareFlags = Array(length);
@@ -2375,6 +2374,9 @@
? toPlainObject(value) ? toPlainObject(value)
: (isPlainObject(value) ? value : {}); : (isPlainObject(value) ? value : {});
} }
else {
isCommon = false;
}
} }
// Add the source value to the stack of traversed objects and associate // Add the source value to the stack of traversed objects and associate
// it with its merged value. // it with its merged value.
@@ -2496,7 +2498,8 @@
if (end < 0) { if (end < 0) {
end += length; end += length;
} }
length = start > end ? 0 : (end - start); length = start > end ? 0 : (end - start) >>> 0;
start >>>= 0;
var result = Array(length); var result = Array(length);
while (++index < length) { while (++index < length) {
@@ -3103,7 +3106,7 @@
return ''; return '';
} }
var padLength = length - strLength; var padLength = length - strLength;
chars = chars == null ? ' ' : baseToString(chars); chars = chars == null ? ' ' : (chars + '');
return repeat(chars, ceil(padLength / chars.length)).slice(0, padLength); return repeat(chars, ceil(padLength / chars.length)).slice(0, padLength);
} }
@@ -3296,7 +3299,7 @@
case stringTag: case stringTag:
// Coerce regexes to strings and treat strings primitives and string // Coerce regexes to strings and treat strings primitives and string
// objects as equal. See https://es5.github.io/#x15.10.6.4 for more details. // objects as equal. See https://es5.github.io/#x15.10.6.4 for more details.
return object == baseToString(other); return object == (other + '');
} }
return false; return false;
} }
@@ -3591,7 +3594,7 @@
var length = object.length, var length = object.length,
prereq = isLength(length) && isIndex(index, length); prereq = isLength(length) && isIndex(index, length);
} else { } else {
prereq = type == 'string' && index in value; prereq = type == 'string' && index in object;
} }
return prereq && object[index] === value; return prereq && object[index] === value;
} }
@@ -3599,6 +3602,10 @@
/** /**
* Checks if `value` is a valid array-like length. * Checks if `value` is a valid array-like length.
* *
* **Note:** This function is based on ES `ToLength`. See the
* [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength)
* for more details.
*
* @private * @private
* @param {*} value The value to check. * @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a valid length, else `false`. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
@@ -5314,6 +5321,9 @@
function wrapperReverse() { function wrapperReverse() {
var value = this.__wrapped__; var value = this.__wrapped__;
if (value instanceof LazyWrapper) { if (value instanceof LazyWrapper) {
if (this.__actions__.length) {
value = new LazyWrapper(this);
}
return new LodashWrapper(value.reverse()); return new LodashWrapper(value.reverse());
} }
return this.thru(function(value) { return this.thru(function(value) {
@@ -5666,7 +5676,7 @@
* // => 'fred' * // => 'fred'
*/ */
function findWhere(collection, source) { function findWhere(collection, source) {
return find(collection, matches(source)); return find(collection, baseMatches(source));
} }
/** /**
@@ -5689,7 +5699,7 @@
* @returns {Array|Object|string} Returns `collection`. * @returns {Array|Object|string} Returns `collection`.
* @example * @example
* *
* _([1, 2, 3]).forEach(function(n) { console.log(n); }); * _([1, 2, 3]).forEach(function(n) { console.log(n); }).value();
* // => logs each value from left to right and returns the array * // => logs each value from left to right and returns the array
* *
* _.forEach({ 'one': 1, 'two': 2, 'three': 3 }, function(n, key) { console.log(n, key); }); * _.forEach({ 'one': 1, 'two': 2, 'three': 3 }, function(n, key) { console.log(n, key); });
@@ -6043,7 +6053,7 @@
* // => [36, 40] (iteration order is not guaranteed) * // => [36, 40] (iteration order is not guaranteed)
*/ */
function pluck(collection, key) { function pluck(collection, key) {
return map(collection, property(key)); return map(collection, baseProperty(key + ''));
} }
/** /**
@@ -6414,7 +6424,7 @@
* // => ['barney', 'fred'] * // => ['barney', 'fred']
*/ */
function where(collection, source) { function where(collection, source) {
return filter(collection, matches(source)); return filter(collection, baseMatches(source));
} }
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
@@ -7105,7 +7115,7 @@
* // => 'FRED' * // => 'FRED'
* *
* // modifying the result cache * // modifying the result cache
* upperCase.cache.set('fred, 'BARNEY'); * upperCase.cache.set('fred', 'BARNEY');
* upperCase('fred'); * upperCase('fred');
* // => 'BARNEY' * // => 'BARNEY'
* *
@@ -9059,7 +9069,7 @@
*/ */
var camelCase = createCompounder(function(result, word, index) { var camelCase = createCompounder(function(result, word, index) {
word = word.toLowerCase(); word = word.toLowerCase();
return index ? (result + word.charAt(0).toUpperCase() + word.slice(1)) : word; return result + (index ? (word.charAt(0).toUpperCase() + word.slice(1)) : word);
}); });
/** /**
@@ -9193,7 +9203,7 @@
/** /**
* Converts `string` to kebab case (a.k.a. spinal case). * Converts `string` to kebab case (a.k.a. spinal case).
* See [Wikipedia](https://en.wikipedia.org/wiki/Letter_case#Computers) for * See [Wikipedia](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles) for
* more details. * more details.
* *
* @static * @static
@@ -9410,16 +9420,41 @@
* _.snakeCase('Foo Bar'); * _.snakeCase('Foo Bar');
* // => 'foo_bar' * // => 'foo_bar'
* *
* _.snakeCase('--foo-bar'); * _.snakeCase('fooBar');
* // => 'foo_bar' * // => 'foo_bar'
* *
* _.snakeCase('fooBar'); * _.snakeCase('--foo-bar');
* // => 'foo_bar' * // => 'foo_bar'
*/ */
var snakeCase = createCompounder(function(result, word, index) { var snakeCase = createCompounder(function(result, word, index) {
return result + (index ? '_' : '') + word.toLowerCase(); return result + (index ? '_' : '') + word.toLowerCase();
}); });
/**
* Converts `string` to start case.
* See [Wikipedia](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage)
* for more details.
*
* @static
* @memberOf _
* @category String
* @param {string} [string=''] The string to convert.
* @returns {string} Returns the start cased string.
* @example
*
* _.startCase('--foo-bar');
* // => 'Foo Bar'
*
* _.startCase('fooBar');
* // => 'Foo Bar'
*
* _.startCase('__foo_bar__');
* // => 'Foo Bar'
*/
var startCase = createCompounder(function(result, word, index) {
return result + (index ? ' ' : '') + (word.charAt(0).toUpperCase() + word.slice(1));
});
/** /**
* Checks if `string` starts with the given target string. * Checks if `string` starts with the given target string.
* *
@@ -9679,7 +9714,7 @@
if (guard ? isIterateeCall(value, chars, guard) : chars == null) { if (guard ? isIterateeCall(value, chars, guard) : chars == null) {
return string.slice(trimmedLeftIndex(string), trimmedRightIndex(string) + 1); return string.slice(trimmedLeftIndex(string), trimmedRightIndex(string) + 1);
} }
chars = baseToString(chars); chars = (chars + '');
return string.slice(charsLeftIndex(string, chars), charsRightIndex(string, chars) + 1); return string.slice(charsLeftIndex(string, chars), charsRightIndex(string, chars) + 1);
} }
@@ -9710,7 +9745,7 @@
if (guard ? isIterateeCall(value, chars, guard) : chars == null) { if (guard ? isIterateeCall(value, chars, guard) : chars == null) {
return string.slice(trimmedLeftIndex(string)) return string.slice(trimmedLeftIndex(string))
} }
return string.slice(charsLeftIndex(string, baseToString(chars))); return string.slice(charsLeftIndex(string, (chars + '')));
} }
/** /**
@@ -9740,7 +9775,7 @@
if (guard ? isIterateeCall(value, chars, guard) : chars == null) { if (guard ? isIterateeCall(value, chars, guard) : chars == null) {
return string.slice(0, trimmedRightIndex(string) + 1) return string.slice(0, trimmedRightIndex(string) + 1)
} }
return string.slice(0, charsRightIndex(string, baseToString(chars)) + 1); return string.slice(0, charsRightIndex(string, (chars + '')) + 1);
} }
/** /**
@@ -9947,7 +9982,9 @@
if (guard && isIterateeCall(func, thisArg, guard)) { if (guard && isIterateeCall(func, thisArg, guard)) {
thisArg = null; thisArg = null;
} }
return baseCallback(func, thisArg); return isObjectLike(func)
? matches(func)
: baseCallback(func, thisArg);
} }
/** /**
@@ -10015,7 +10052,7 @@
* // => { 'user': 'barney', 'age': 36 } * // => { 'user': 'barney', 'age': 36 }
*/ */
function matches(source) { function matches(source) {
return baseMatches(source, true); return baseMatches(baseClone(source, true));
} }
/** /**
@@ -10512,6 +10549,7 @@
lodash.some = some; lodash.some = some;
lodash.sortedIndex = sortedIndex; lodash.sortedIndex = sortedIndex;
lodash.sortedLastIndex = sortedLastIndex; lodash.sortedLastIndex = sortedLastIndex;
lodash.startCase = startCase;
lodash.startsWith = startsWith; lodash.startsWith = startsWith;
lodash.template = template; lodash.template = template;
lodash.trim = trim; lodash.trim = trim;
@@ -10637,10 +10675,10 @@
// Add `LazyWrapper` methods for `_.pluck` and `_.where`. // Add `LazyWrapper` methods for `_.pluck` and `_.where`.
arrayEach(['pluck', 'where'], function(methodName, index) { arrayEach(['pluck', 'where'], function(methodName, index) {
var operationName = index ? 'filter' : 'map', var operationName = index ? 'filter' : 'map',
createCallback = index ? matches : property; createCallback = index ? baseMatches : baseProperty;
LazyWrapper.prototype[methodName] = function(value) { LazyWrapper.prototype[methodName] = function(value) {
return this[operationName](createCallback(value)); return this[operationName](createCallback(index ? value : (value + '')));
}; };
}); });
@@ -10677,7 +10715,8 @@
// Add `LazyWrapper` methods to `lodash.prototype`. // Add `LazyWrapper` methods to `lodash.prototype`.
baseForOwn(LazyWrapper.prototype, function(func, methodName) { baseForOwn(LazyWrapper.prototype, function(func, methodName) {
var retUnwrapped = /^(?:first|last)$/.test(methodName); var lodashFunc = lodash[methodName],
retUnwrapped = /^(?:first|last)$/.test(methodName);
lodash.prototype[methodName] = function() { lodash.prototype[methodName] = function() {
var value = this.__wrapped__, var value = this.__wrapped__,
@@ -10690,12 +10729,12 @@
if (retUnwrapped && !chainAll) { if (retUnwrapped && !chainAll) {
return onlyLazy return onlyLazy
? func.call(value) ? func.call(value)
: lodash[methodName](this.value()); : lodashFunc.call(lodash, this.value());
} }
var interceptor = function(value) { var interceptor = function(value) {
var otherArgs = [value]; var otherArgs = [value];
push.apply(otherArgs, args); push.apply(otherArgs, args);
return lodash[methodName].apply(lodash, otherArgs); return lodashFunc.apply(lodash, otherArgs);
}; };
if (isLazy || isArray(value)) { if (isLazy || isArray(value)) {
var wrapper = onlyLazy ? value : new LazyWrapper(this), var wrapper = onlyLazy ? value : new LazyWrapper(this),

View File

@@ -1,6 +1,5 @@
var baseMatches = require('./baseMatches'), var baseMatches = require('./baseMatches'),
baseProperty = require('./baseProperty'), baseProperty = require('./baseProperty'),
baseToString = require('./baseToString'),
bindCallback = require('./bindCallback'), bindCallback = require('./bindCallback'),
identity = require('../utility/identity'), identity = require('../utility/identity'),
isBindable = require('./isBindable'); isBindable = require('./isBindable');
@@ -27,8 +26,8 @@ function baseCallback(func, thisArg, argCount) {
} }
// Handle "_.property" and "_.matches" style callback shorthands. // Handle "_.property" and "_.matches" style callback shorthands.
return type == 'object' return type == 'object'
? baseMatches(func, !argCount) ? baseMatches(func)
: baseProperty(argCount ? baseToString(func) : func); : baseProperty(func + '');
} }
module.exports = baseCallback; module.exports = baseCallback;

View File

@@ -1,5 +1,4 @@
var baseClone = require('./baseClone'), var baseIsMatch = require('./baseIsMatch'),
baseIsMatch = require('./baseIsMatch'),
isStrictComparable = require('./isStrictComparable'), isStrictComparable = require('./isStrictComparable'),
keys = require('../object/keys'); keys = require('../object/keys');
@@ -15,10 +14,9 @@ var hasOwnProperty = objectProto.hasOwnProperty;
* *
* @private * @private
* @param {Object} source The object of property values to match. * @param {Object} source The object of property values to match.
* @param {boolean} [isCloned] Specify cloning the source object.
* @returns {Function} Returns the new function. * @returns {Function} Returns the new function.
*/ */
function baseMatches(source, isCloned) { function baseMatches(source) {
var props = keys(source), var props = keys(source),
length = props.length; length = props.length;
@@ -32,9 +30,6 @@ function baseMatches(source, isCloned) {
}; };
} }
} }
if (isCloned) {
source = baseClone(source, true);
}
var values = Array(length), var values = Array(length),
strictCompareFlags = Array(length); strictCompareFlags = Array(length);

View File

@@ -47,6 +47,9 @@ function baseMergeDeep(object, source, key, mergeFunc, customizer, stackA, stack
? toPlainObject(value) ? toPlainObject(value)
: (isPlainObject(value) ? value : {}); : (isPlainObject(value) ? value : {});
} }
else {
isCommon = false;
}
} }
// Add the source value to the stack of traversed objects and associate // Add the source value to the stack of traversed objects and associate
// it with its merged value. // it with its merged value.

View File

@@ -19,7 +19,8 @@ function baseSlice(array, start, end) {
if (end < 0) { if (end < 0) {
end += length; end += length;
} }
length = start > end ? 0 : (end - start); length = start > end ? 0 : (end - start) >>> 0;
start >>>= 0;
var result = Array(length); var result = Array(length);
while (++index < length) { while (++index < length) {

View File

@@ -1,5 +1,4 @@
var baseToString = require('./baseToString'), var repeat = require('../string/repeat');
repeat = require('../string/repeat');
/** Native method references. */ /** Native method references. */
var ceil = Math.ceil; var ceil = Math.ceil;
@@ -26,7 +25,7 @@ function createPad(string, length, chars) {
return ''; return '';
} }
var padLength = length - strLength; var padLength = length - strLength;
chars = chars == null ? ' ' : baseToString(chars); chars = chars == null ? ' ' : (chars + '');
return repeat(chars, ceil(padLength / chars.length)).slice(0, padLength); return repeat(chars, ceil(padLength / chars.length)).slice(0, padLength);
} }

View File

@@ -1,5 +1,3 @@
var baseToString = require('./baseToString');
/** `Object#toString` result references. */ /** `Object#toString` result references. */
var boolTag = '[object Boolean]', var boolTag = '[object Boolean]',
dateTag = '[object Date]', dateTag = '[object Date]',
@@ -43,7 +41,7 @@ function equalByTag(object, other, tag) {
case stringTag: case stringTag:
// Coerce regexes to strings and treat strings primitives and string // Coerce regexes to strings and treat strings primitives and string
// objects as equal. See https://es5.github.io/#x15.10.6.4 for more details. // objects as equal. See https://es5.github.io/#x15.10.6.4 for more details.
return object == baseToString(other); return object == (other + '');
} }
return false; return false;
} }

View File

@@ -1,6 +1,6 @@
/** /**
* Used as the maximum length of an array-like value. * Used as the maximum length of an array-like value.
* See the [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength) * See the [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.max_safe_integer)
* for more details. * for more details.
*/ */
var MAX_SAFE_INTEGER = Math.pow(2, 53) - 1; var MAX_SAFE_INTEGER = Math.pow(2, 53) - 1;

View File

@@ -20,7 +20,7 @@ function isIterateeCall(value, index, object) {
var length = object.length, var length = object.length,
prereq = isLength(length) && isIndex(index, length); prereq = isLength(length) && isIndex(index, length);
} else { } else {
prereq = type == 'string' && index in value; prereq = type == 'string' && index in object;
} }
return prereq && object[index] === value; return prereq && object[index] === value;
} }

View File

@@ -1,6 +1,6 @@
/** /**
* Used as the maximum length of an array-like value. * Used as the maximum length of an array-like value.
* See the [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength) * See the [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.max_safe_integer)
* for more details. * for more details.
*/ */
var MAX_SAFE_INTEGER = Math.pow(2, 53) - 1; var MAX_SAFE_INTEGER = Math.pow(2, 53) - 1;
@@ -8,6 +8,10 @@ var MAX_SAFE_INTEGER = Math.pow(2, 53) - 1;
/** /**
* Checks if `value` is a valid array-like length. * Checks if `value` is a valid array-like length.
* *
* **Note:** This function is based on ES `ToLength`. See the
* [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength)
* for more details.
*
* @private * @private
* @param {*} value The value to check. * @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a valid length, else `false`. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.

View File

@@ -9,11 +9,14 @@ var LazyWrapper = require('./LazyWrapper');
* @returns {Object} Returns the new reversed `LazyWrapper` object. * @returns {Object} Returns the new reversed `LazyWrapper` object.
*/ */
function lazyReverse() { function lazyReverse() {
var filtered = this.filtered, if (this.filtered) {
result = filtered ? new LazyWrapper(this) : this.clone(); var result = new LazyWrapper(this);
result.dir = -1;
result.dir = this.dir * -1; result.filtered = true;
result.filtered = filtered; } else {
result = this.clone();
result.dir *= -1;
}
return result; return result;
} }

View File

@@ -24,12 +24,12 @@ function lazyValue() {
} }
var dir = this.dir, var dir = this.dir,
isRight = dir < 0, isRight = dir < 0,
length = array.length, view = getView(0, array.length, this.views),
view = getView(0, length, this.views),
start = view.start, start = view.start,
end = view.end, end = view.end,
length = end - start,
dropCount = this.dropCount, dropCount = this.dropCount,
takeCount = nativeMin(end - start, this.takeCount - dropCount), takeCount = nativeMin(length, this.takeCount - dropCount),
index = isRight ? end : start - 1, index = isRight ? end : start - 1,
iteratees = this.iteratees, iteratees = this.iteratees,
iterLength = iteratees ? iteratees.length : 0, iterLength = iteratees ? iteratees.length : 0,
@@ -65,7 +65,7 @@ function lazyValue() {
result[resIndex++] = value; result[resIndex++] = value;
} }
} }
return isRight ? result.reverse() : result; return result;
} }
module.exports = lazyValue; module.exports = lazyValue;

View File

@@ -1,6 +1,6 @@
{ {
"name": "lodash", "name": "lodash",
"version": "3.0.0", "version": "3.1.0",
"description": "The modern build of lodash modular utilities.", "description": "The modern build of lodash modular utilities.",
"homepage": "https://lodash.com/", "homepage": "https://lodash.com/",
"icon": "https://lodash.com/icon.svg", "icon": "https://lodash.com/icon.svg",

View File

@@ -12,6 +12,7 @@ module.exports = {
'parseInt': require('./string/parseInt'), 'parseInt': require('./string/parseInt'),
'repeat': require('./string/repeat'), 'repeat': require('./string/repeat'),
'snakeCase': require('./string/snakeCase'), 'snakeCase': require('./string/snakeCase'),
'startCase': require('./string/startCase'),
'startsWith': require('./string/startsWith'), 'startsWith': require('./string/startsWith'),
'template': require('./string/template'), 'template': require('./string/template'),
'templateSettings': require('./string/templateSettings'), 'templateSettings': require('./string/templateSettings'),

View File

@@ -22,7 +22,7 @@ var createCompounder = require('../internal/createCompounder');
*/ */
var camelCase = createCompounder(function(result, word, index) { var camelCase = createCompounder(function(result, word, index) {
word = word.toLowerCase(); word = word.toLowerCase();
return index ? (result + word.charAt(0).toUpperCase() + word.slice(1)) : word; return result + (index ? (word.charAt(0).toUpperCase() + word.slice(1)) : word);
}); });
module.exports = camelCase; module.exports = camelCase;

View File

@@ -2,7 +2,7 @@ var createCompounder = require('../internal/createCompounder');
/** /**
* Converts `string` to kebab case (a.k.a. spinal case). * Converts `string` to kebab case (a.k.a. spinal case).
* See [Wikipedia](https://en.wikipedia.org/wiki/Letter_case#Computers) for * See [Wikipedia](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles) for
* more details. * more details.
* *
* @static * @static

View File

@@ -14,10 +14,10 @@ var createCompounder = require('../internal/createCompounder');
* _.snakeCase('Foo Bar'); * _.snakeCase('Foo Bar');
* // => 'foo_bar' * // => 'foo_bar'
* *
* _.snakeCase('--foo-bar'); * _.snakeCase('fooBar');
* // => 'foo_bar' * // => 'foo_bar'
* *
* _.snakeCase('fooBar'); * _.snakeCase('--foo-bar');
* // => 'foo_bar' * // => 'foo_bar'
*/ */
var snakeCase = createCompounder(function(result, word, index) { var snakeCase = createCompounder(function(result, word, index) {

28
string/startCase.js Normal file
View File

@@ -0,0 +1,28 @@
var createCompounder = require('../internal/createCompounder');
/**
* Converts `string` to start case.
* See [Wikipedia](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage)
* for more details.
*
* @static
* @memberOf _
* @category String
* @param {string} [string=''] The string to convert.
* @returns {string} Returns the start cased string.
* @example
*
* _.startCase('--foo-bar');
* // => 'Foo Bar'
*
* _.startCase('fooBar');
* // => 'Foo Bar'
*
* _.startCase('__foo_bar__');
* // => 'Foo Bar'
*/
var startCase = createCompounder(function(result, word, index) {
return result + (index ? ' ' : '') + (word.charAt(0).toUpperCase() + word.slice(1));
});
module.exports = startCase;

View File

@@ -35,7 +35,7 @@ function trim(string, chars, guard) {
if (guard ? isIterateeCall(value, chars, guard) : chars == null) { if (guard ? isIterateeCall(value, chars, guard) : chars == null) {
return string.slice(trimmedLeftIndex(string), trimmedRightIndex(string) + 1); return string.slice(trimmedLeftIndex(string), trimmedRightIndex(string) + 1);
} }
chars = baseToString(chars); chars = (chars + '');
return string.slice(charsLeftIndex(string, chars), charsRightIndex(string, chars) + 1); return string.slice(charsLeftIndex(string, chars), charsRightIndex(string, chars) + 1);
} }

View File

@@ -30,7 +30,7 @@ function trimLeft(string, chars, guard) {
if (guard ? isIterateeCall(value, chars, guard) : chars == null) { if (guard ? isIterateeCall(value, chars, guard) : chars == null) {
return string.slice(trimmedLeftIndex(string)) return string.slice(trimmedLeftIndex(string))
} }
return string.slice(charsLeftIndex(string, baseToString(chars))); return string.slice(charsLeftIndex(string, (chars + '')));
} }
module.exports = trimLeft; module.exports = trimLeft;

View File

@@ -30,7 +30,7 @@ function trimRight(string, chars, guard) {
if (guard ? isIterateeCall(value, chars, guard) : chars == null) { if (guard ? isIterateeCall(value, chars, guard) : chars == null) {
return string.slice(0, trimmedRightIndex(string) + 1) return string.slice(0, trimmedRightIndex(string) + 1)
} }
return string.slice(0, charsRightIndex(string, baseToString(chars)) + 1); return string.slice(0, charsRightIndex(string, (chars + '')) + 1);
} }
module.exports = trimRight; module.exports = trimRight;

View File

@@ -1,5 +1,7 @@
var baseCallback = require('../internal/baseCallback'), var baseCallback = require('../internal/baseCallback'),
isIterateeCall = require('../internal/isIterateeCall'); isIterateeCall = require('../internal/isIterateeCall'),
isObjectLike = require('../internal/isObjectLike'),
matches = require('./matches');
/** /**
* Creates a function bound to an optional `thisArg`. If `func` is a property * Creates a function bound to an optional `thisArg`. If `func` is a property
@@ -40,7 +42,9 @@ function callback(func, thisArg, guard) {
if (guard && isIterateeCall(func, thisArg, guard)) { if (guard && isIterateeCall(func, thisArg, guard)) {
thisArg = null; thisArg = null;
} }
return baseCallback(func, thisArg); return isObjectLike(func)
? matches(func)
: baseCallback(func, thisArg);
} }
module.exports = callback; module.exports = callback;

View File

@@ -1,4 +1,5 @@
var baseMatches = require('../internal/baseMatches'); var baseClone = require('../internal/baseClone'),
baseMatches = require('../internal/baseMatches');
/** /**
* Creates a function which performs a deep comparison between a given object * Creates a function which performs a deep comparison between a given object
@@ -26,7 +27,7 @@ var baseMatches = require('../internal/baseMatches');
* // => { 'user': 'barney', 'age': 36 } * // => { 'user': 'barney', 'age': 36 }
*/ */
function matches(source) { function matches(source) {
return baseMatches(source, true); return baseMatches(baseClone(source, true));
} }
module.exports = matches; module.exports = matches;