From d5f40436179c0c95438c3943cbb168d91802b504 Mon Sep 17 00:00:00 2001 From: jdalton Date: Sun, 1 Feb 2015 22:09:14 -0800 Subject: [PATCH] Bump to v3.1.0. --- README.md | 4 +++- chain/lodash.js | 6 +++--- collection/findWhere.js | 4 ++-- collection/pluck.js | 4 ++-- collection/where.js | 4 ++-- internal/baseCallback.js | 2 +- internal/baseMatches.js | 7 +------ internal/isIndex.js | 2 +- internal/isIterateeCall.js | 2 +- internal/isLength.js | 6 +++++- lodash.js | 17 +++++++++-------- package.json | 2 +- string.js | 2 ++ string/camelCase.js | 2 +- string/snakeCase.js | 4 ++-- string/startCase.js | 28 ++++++++++++++++++++++++++++ string/trim.js | 2 +- string/trimLeft.js | 2 +- string/trimRight.js | 2 +- utility/callback.js | 6 +++++- utility/matches.js | 3 ++- 21 files changed, 74 insertions(+), 37 deletions(-) create mode 100644 string/startCase.js diff --git a/README.md b/README.md index ff0783287..74c3bc5ef 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# lodash-es v3.0.1 +# lodash-es v3.1.0 The [modern build](https://github.com/lodash/lodash/wiki/Build-Differences) of [lodash](https://lodash.com/) exported as [ES](https://people.mozilla.org/~jorendorff/es6-draft.html) modules. @@ -6,3 +6,5 @@ Generated using [lodash-cli](https://www.npmjs.com/package/lodash-cli): ```bash $ lodash modularize modern exports=es -o ./ ``` + +See the [package source](https://github.com/lodash/lodash/tree/3.1.0-es) for more details. diff --git a/chain/lodash.js b/chain/lodash.js index 452e9284d..8c8c258c1 100644 --- a/chain/lodash.js +++ b/chain/lodash.js @@ -57,14 +57,14 @@ var hasOwnProperty = objectProto.hasOwnProperty; * `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`, `has`, * `identity`, `includes`, `indexOf`, `isArguments`, `isArray`, `isBoolean`, * `isDate`, `isElement`, `isEmpty`, `isEqual`, `isError`, `isFinite`, - * `isFunction`, `isMatch` , `isNative`, `isNaN`, `isNull`, `isNumber`, + * `isFunction`, `isMatch`, `isNative`, `isNaN`, `isNull`, `isNumber`, * `isObject`, `isPlainObject`, `isRegExp`, `isString`, `isUndefined`, * `isTypedArray`, `join`, `kebabCase`, `last`, `lastIndexOf`, `max`, `min`, * `noConflict`, `now`, `pad`, `padLeft`, `padRight`, `parseInt`, `pop`, * `random`, `reduce`, `reduceRight`, `repeat`, `result`, `runInContext`, * `shift`, `size`, `snakeCase`, `some`, `sortedIndex`, `sortedLastIndex`, - * `startsWith`, `template`, `trim`, `trimLeft`, `trimRight`, `trunc`, - * `unescape`, `uniqueId`, `value`, and `words` + * `startCase`, `startsWith`, `template`, `trim`, `trimLeft`, `trimRight`, + * `trunc`, `unescape`, `uniqueId`, `value`, and `words` * * The wrapper function `sample` will return a wrapped value when `n` is provided, * otherwise an unwrapped value is returned. diff --git a/collection/findWhere.js b/collection/findWhere.js index acf0ae049..bcc0fb0e6 100644 --- a/collection/findWhere.js +++ b/collection/findWhere.js @@ -1,5 +1,5 @@ +import baseMatches from '../internal/baseMatches'; import find from './find'; -import matches from '../utility/matches'; /** * Performs a deep comparison between each element in `collection` and the @@ -26,7 +26,7 @@ import matches from '../utility/matches'; * // => 'fred' */ function findWhere(collection, source) { - return find(collection, matches(source)); + return find(collection, baseMatches(source)); } export default findWhere; diff --git a/collection/pluck.js b/collection/pluck.js index 5d8b004a1..e59665340 100644 --- a/collection/pluck.js +++ b/collection/pluck.js @@ -1,5 +1,5 @@ +import baseProperty from '../internal/baseProperty'; import map from './map'; -import property from '../utility/property'; /** * Gets the value of `key` from all elements in `collection`. @@ -25,7 +25,7 @@ import property from '../utility/property'; * // => [36, 40] (iteration order is not guaranteed) */ function pluck(collection, key) { - return map(collection, property(key)); + return map(collection, baseProperty(key + '')); } export default pluck; diff --git a/collection/where.js b/collection/where.js index ec7c9bcb1..4f5352290 100644 --- a/collection/where.js +++ b/collection/where.js @@ -1,5 +1,5 @@ +import baseMatches from '../internal/baseMatches'; import filter from './filter'; -import matches from '../utility/matches'; /** * Performs a deep comparison between each element in `collection` and the @@ -29,7 +29,7 @@ import matches from '../utility/matches'; * // => ['barney', 'fred'] */ function where(collection, source) { - return filter(collection, matches(source)); + return filter(collection, baseMatches(source)); } export default where; diff --git a/internal/baseCallback.js b/internal/baseCallback.js index 81a670125..6c7cce7ff 100644 --- a/internal/baseCallback.js +++ b/internal/baseCallback.js @@ -26,7 +26,7 @@ function baseCallback(func, thisArg, argCount) { } // Handle "_.property" and "_.matches" style callback shorthands. return type == 'object' - ? baseMatches(func, !argCount) + ? baseMatches(func) : baseProperty(func + ''); } diff --git a/internal/baseMatches.js b/internal/baseMatches.js index b81853380..6ac3cb3dd 100644 --- a/internal/baseMatches.js +++ b/internal/baseMatches.js @@ -1,4 +1,3 @@ -import baseClone from './baseClone'; import baseIsMatch from './baseIsMatch'; import isStrictComparable from './isStrictComparable'; import keys from '../object/keys'; @@ -15,10 +14,9 @@ var hasOwnProperty = objectProto.hasOwnProperty; * * @private * @param {Object} source The object of property values to match. - * @param {boolean} [isCloned] Specify cloning the source object. * @returns {Function} Returns the new function. */ -function baseMatches(source, isCloned) { +function baseMatches(source) { var props = keys(source), length = props.length; @@ -32,9 +30,6 @@ function baseMatches(source, isCloned) { }; } } - if (isCloned) { - source = baseClone(source, true); - } var values = Array(length), strictCompareFlags = Array(length); diff --git a/internal/isIndex.js b/internal/isIndex.js index 6df32fd13..8a62990db 100644 --- a/internal/isIndex.js +++ b/internal/isIndex.js @@ -1,6 +1,6 @@ /** * 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. */ var MAX_SAFE_INTEGER = Math.pow(2, 53) - 1; diff --git a/internal/isIterateeCall.js b/internal/isIterateeCall.js index 9e0164885..4b8498fd5 100644 --- a/internal/isIterateeCall.js +++ b/internal/isIterateeCall.js @@ -20,7 +20,7 @@ function isIterateeCall(value, index, object) { var length = object.length, prereq = isLength(length) && isIndex(index, length); } else { - prereq = type == 'string' && index in value; + prereq = type == 'string' && index in object; } return prereq && object[index] === value; } diff --git a/internal/isLength.js b/internal/isLength.js index 792f027fc..137f33a77 100644 --- a/internal/isLength.js +++ b/internal/isLength.js @@ -1,6 +1,6 @@ /** * 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. */ 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. * + * **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 * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`. diff --git a/lodash.js b/lodash.js index db59c5f73..32faa2aaa 100644 --- a/lodash.js +++ b/lodash.js @@ -1,6 +1,6 @@ /** * @license - * lodash 3.0.1 (Custom Build) + * lodash 3.1.0 (Custom Build) * Build: `lodash modularize modern exports="es" -o ./` * Copyright 2012-2015 The Dojo Foundation * Based on Underscore.js 1.7.0 @@ -23,6 +23,8 @@ import arrayEach from './internal/arrayEach'; import baseCallback from './internal/baseCallback'; import baseForOwn from './internal/baseForOwn'; import baseFunctions from './internal/baseFunctions'; +import baseMatches from './internal/baseMatches'; +import baseProperty from './internal/baseProperty'; import isArray from './lang/isArray'; import isObject from './lang/isObject'; import keys from './object/keys'; @@ -30,14 +32,12 @@ import lazyClone from './internal/lazyClone'; import lazyReverse from './internal/lazyReverse'; import lazyValue from './internal/lazyValue'; import lodash from './chain/lodash'; -import matches from './utility/matches'; import _mixin from './utility/mixin'; -import property from './utility/property'; import support from './support'; import thru from './chain/thru'; /** Used as the semantic version number. */ -var VERSION = '3.0.1'; +var VERSION = '3.1.0'; /** Used to indicate the type of lazy iteratees. */ var LAZY_FILTER_FLAG = 0, @@ -121,7 +121,7 @@ lodash.keys = keys; lodash.keysIn = object.keysIn; lodash.map = collection.map; lodash.mapValues = object.mapValues; -lodash.matches = matches; +lodash.matches = utility.matches; lodash.memoize = func.memoize; lodash.merge = object.merge; lodash.mixin = mixin; @@ -134,7 +134,7 @@ lodash.partialRight = func.partialRight; lodash.partition = collection.partition; lodash.pick = object.pick; lodash.pluck = collection.pluck; -lodash.property = property; +lodash.property = utility.property; lodash.propertyOf = utility.propertyOf; lodash.pull = array.pull; lodash.pullAt = array.pullAt; @@ -252,6 +252,7 @@ lodash.snakeCase = string.snakeCase; lodash.some = collection.some; lodash.sortedIndex = array.sortedIndex; lodash.sortedLastIndex = array.sortedLastIndex; +lodash.startCase = string.startCase; lodash.startsWith = string.startsWith; lodash.template = string.template; lodash.trim = string.trim; @@ -376,10 +377,10 @@ arrayEach(['initial', 'rest'], function(methodName, index) { // Add `LazyWrapper` methods for `_.pluck` and `_.where`. arrayEach(['pluck', 'where'], function(methodName, index) { var operationName = index ? 'filter' : 'map', - createCallback = index ? matches : property; + createCallback = index ? baseMatches : baseProperty; LazyWrapper.prototype[methodName] = function(value) { - return this[operationName](createCallback(value)); + return this[operationName](createCallback(index ? value : (value + ''))); }; }); diff --git a/package.json b/package.json index 92e758c51..68bb2c915 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lodash-es", - "version": "3.0.1", + "version": "3.1.0", "description": "The modern build of lodash exported as ES modules.", "homepage": "https://lodash.com/custom-builds", "license": "MIT", diff --git a/string.js b/string.js index 0eb9d89a6..ade8e0d35 100644 --- a/string.js +++ b/string.js @@ -11,6 +11,7 @@ import padRight from './string/padRight'; import parseInt from './string/parseInt'; import repeat from './string/repeat'; import snakeCase from './string/snakeCase'; +import startCase from './string/startCase'; import startsWith from './string/startsWith'; import template from './string/template'; import templateSettings from './string/templateSettings'; @@ -35,6 +36,7 @@ export default { 'parseInt': parseInt, 'repeat': repeat, 'snakeCase': snakeCase, + 'startCase': startCase, 'startsWith': startsWith, 'template': template, 'templateSettings': templateSettings, diff --git a/string/camelCase.js b/string/camelCase.js index 529d14a93..7d4c7dbf6 100644 --- a/string/camelCase.js +++ b/string/camelCase.js @@ -22,7 +22,7 @@ import createCompounder from '../internal/createCompounder'; */ var camelCase = createCompounder(function(result, word, index) { 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); }); export default camelCase; diff --git a/string/snakeCase.js b/string/snakeCase.js index 78c712879..1a52ee846 100644 --- a/string/snakeCase.js +++ b/string/snakeCase.js @@ -14,10 +14,10 @@ import createCompounder from '../internal/createCompounder'; * _.snakeCase('Foo Bar'); * // => 'foo_bar' * - * _.snakeCase('--foo-bar'); + * _.snakeCase('fooBar'); * // => 'foo_bar' * - * _.snakeCase('fooBar'); + * _.snakeCase('--foo-bar'); * // => 'foo_bar' */ var snakeCase = createCompounder(function(result, word, index) { diff --git a/string/startCase.js b/string/startCase.js new file mode 100644 index 000000000..039606b30 --- /dev/null +++ b/string/startCase.js @@ -0,0 +1,28 @@ +import createCompounder from '../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)); +}); + +export default startCase; diff --git a/string/trim.js b/string/trim.js index 0ed20991b..f8a4987bb 100644 --- a/string/trim.js +++ b/string/trim.js @@ -35,7 +35,7 @@ function trim(string, chars, guard) { if (guard ? isIterateeCall(value, chars, guard) : chars == null) { return string.slice(trimmedLeftIndex(string), trimmedRightIndex(string) + 1); } - chars = baseToString(chars); + chars = (chars + ''); return string.slice(charsLeftIndex(string, chars), charsRightIndex(string, chars) + 1); } diff --git a/string/trimLeft.js b/string/trimLeft.js index 0190e2feb..134e35aa0 100644 --- a/string/trimLeft.js +++ b/string/trimLeft.js @@ -30,7 +30,7 @@ function trimLeft(string, chars, guard) { if (guard ? isIterateeCall(value, chars, guard) : chars == null) { return string.slice(trimmedLeftIndex(string)) } - return string.slice(charsLeftIndex(string, baseToString(chars))); + return string.slice(charsLeftIndex(string, (chars + ''))); } export default trimLeft; diff --git a/string/trimRight.js b/string/trimRight.js index 434f5b9b8..24fa43fdc 100644 --- a/string/trimRight.js +++ b/string/trimRight.js @@ -30,7 +30,7 @@ function trimRight(string, chars, guard) { if (guard ? isIterateeCall(value, chars, guard) : chars == null) { return string.slice(0, trimmedRightIndex(string) + 1) } - return string.slice(0, charsRightIndex(string, baseToString(chars)) + 1); + return string.slice(0, charsRightIndex(string, (chars + '')) + 1); } export default trimRight; diff --git a/utility/callback.js b/utility/callback.js index 58dfa58ba..8838b0d38 100644 --- a/utility/callback.js +++ b/utility/callback.js @@ -1,5 +1,7 @@ import baseCallback from '../internal/baseCallback'; import isIterateeCall from '../internal/isIterateeCall'; +import isObjectLike from '../internal/isObjectLike'; +import matches from './matches'; /** * 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)) { thisArg = null; } - return baseCallback(func, thisArg); + return isObjectLike(func) + ? matches(func) + : baseCallback(func, thisArg); } export default callback; diff --git a/utility/matches.js b/utility/matches.js index 1af6ac33e..afcefadf4 100644 --- a/utility/matches.js +++ b/utility/matches.js @@ -1,3 +1,4 @@ +import baseClone from '../internal/baseClone'; import baseMatches from '../internal/baseMatches'; /** @@ -26,7 +27,7 @@ import baseMatches from '../internal/baseMatches'; * // => { 'user': 'barney', 'age': 36 } */ function matches(source) { - return baseMatches(source, true); + return baseMatches(baseClone(source, true)); } export default matches;