From 150bd32f97b07ab4424f9caa54979dead4fb1ff1 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 8 Oct 2015 21:50:30 -0700 Subject: [PATCH] Add `_.toLower` and `_.toUpper`. --- lodash.js | 58 +++++++++++++++++++++++++++++++++++++++++++++++----- test/test.js | 4 +++- 2 files changed, 56 insertions(+), 6 deletions(-) diff --git a/lodash.js b/lodash.js index c6949a2b7..b693a1525 100644 --- a/lodash.js +++ b/lodash.js @@ -11120,7 +11120,7 @@ }); /** - * Converts `string` to lower case. + * Converts `string`, as space separated words, to lower case. * * @static * @memberOf _ @@ -11129,13 +11129,13 @@ * @returns {string} Returns the lower cased string. * @example * - * _.lowerCase('Foo Bar'); + * _.lowerCase('--Foo-Bar'); * // => 'foo bar' * * _.lowerCase('fooBar'); * // => 'foo bar' * - * _.lowerCase('__foo_bar__'); + * _.lowerCase('__FOO_BAR__'); * // => 'foo bar' */ var lowerCase = createCompounder(function(result, word, index) { @@ -11584,6 +11584,52 @@ return result; } + /** + * Converts `string`, as a whole, to lower case. + * + * @static + * @memberOf _ + * @category String + * @param {string} [string=''] The string to convert. + * @returns {string} Returns the lower cased string. + * @example + * + * _.toLower('--Foo-Bar'); + * // => '--foo-bar' + * + * _.toLower('fooBar'); + * // => 'foobar' + * + * _.toLower('__FOO_BAR__'); + * // => '__foo_bar__' + */ + function toLower(value) { + return toString(value).toLowerCase(); + } + + /** + * Converts `string`, as a whole, to upper case. + * + * @static + * @memberOf _ + * @category String + * @param {string} [string=''] The string to convert. + * @returns {string} Returns the upper cased string. + * @example + * + * _.toUpper('--foo-bar'); + * // => '--FOO-BAR' + * + * _.toUpper('fooBar'); + * // => 'FOOBAR' + * + * _.toUpper('__foo_bar__'); + * // => '__FOO_BAR__' + */ + function toUpper(value) { + return toString(value).toUpperCase(); + } + /** * Removes leading and trailing whitespace or specified characters from `string`. * @@ -11809,7 +11855,7 @@ } /** - * Converts `string` to upper case. + * Converts `string`, as space separated words, to upper case. * * @static * @memberOf _ @@ -11818,7 +11864,7 @@ * @returns {string} Returns the upper cased string. * @example * - * _.upperCase('Foo Bar'); + * _.upperCase('--foo-bar'); * // => 'FOO BAR' * * _.upperCase('fooBar'); @@ -12904,7 +12950,9 @@ lodash.sumBy = sumBy; lodash.template = template; lodash.toInteger = toInteger; + lodash.toLower = toLower; lodash.toString = toString; + lodash.toUpper = toUpper; lodash.trim = trim; lodash.trimLeft = trimLeft; lodash.trimRight = trimRight; diff --git a/test/test.js b/test/test.js index 2a81b3806..c35e8802e 100644 --- a/test/test.js +++ b/test/test.js @@ -20991,7 +20991,9 @@ 'some', 'startsWith', 'toInteger', + 'toLower', 'toString', + 'toUpper', 'trim', 'trimLeft', 'trimRight', @@ -21236,7 +21238,7 @@ var acceptFalsey = _.difference(allMethods, rejectFalsey); QUnit.test('should accept falsey arguments', function(assert) { - assert.expect(253); + assert.expect(255); var emptyArrays = _.map(falsey, _.constant([]));