From 9735961090f6f4d1c404246c1fce55efe02fa2cb Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 17 Mar 2016 21:07:55 -0700 Subject: [PATCH] Ensure `_.startCase` only uppercases the first character of each word. --- lodash.js | 8 ++++---- test/test.js | 22 +++++++++++++++++++--- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/lodash.js b/lodash.js index 2e37beffd..02269e96f 100644 --- a/lodash.js +++ b/lodash.js @@ -13208,17 +13208,17 @@ * @returns {string} Returns the start cased string. * @example * - * _.startCase('--foo-bar'); + * _.startCase('--foo-bar--'); * // => 'Foo Bar' * * _.startCase('fooBar'); * // => 'Foo Bar' * - * _.startCase('__foo_bar__'); - * // => 'Foo Bar' + * _.startCase('__FOO_BAR__'); + * // => 'FOO BAR' */ var startCase = createCompounder(function(result, word, index) { - return result + (index ? ' ' : '') + capitalize(word); + return result + (index ? ' ' : '') + upperFirst(word); }); /** diff --git a/test/test.js b/test/test.js index 6106afffa..2a861d72e 100644 --- a/test/test.js +++ b/test/test.js @@ -2090,7 +2090,7 @@ var strings = [ 'foo bar', 'Foo bar', 'foo Bar', 'Foo Bar', - 'FOO BAR', 'fooBar', '--foo-bar', '__foo_bar__' + 'FOO BAR', 'fooBar', '--foo-bar--', '__foo_bar__' ]; var converted = (function() { @@ -2108,7 +2108,8 @@ assert.expect(1); var actual = lodashStable.map(strings, function(string) { - return func(string) === converted; + var expected = (caseName == 'start' && string == 'FOO BAR') ? string : converted; + return func(string) === expected; }); assert.deepEqual(actual, lodashStable.map(strings, alwaysTrue)); @@ -2118,7 +2119,8 @@ assert.expect(1); var actual = lodashStable.map(strings, function(string) { - return func(func(string)) === converted; + var expected = (caseName == 'start' && string == 'FOO BAR') ? string : converted; + return func(func(string)) === expected; }); assert.deepEqual(actual, lodashStable.map(strings, alwaysTrue)); @@ -19821,6 +19823,20 @@ /*--------------------------------------------------------------------------*/ + QUnit.module('lodash.startCase'); + + (function() { + QUnit.test('should uppercase only the first character of each word', function(assert) { + assert.expect(3); + + assert.strictEqual(_.startCase('--foo-bar--'), 'Foo Bar'); + assert.strictEqual(_.startCase('fooBar'), 'Foo Bar'); + assert.strictEqual(_.startCase('__FOO_BAR__'), 'FOO BAR'); + }); + }()); + + /*--------------------------------------------------------------------------*/ + QUnit.module('lodash.startsWith'); (function() {