Add _.upperCase and _.lowerCase.

This commit is contained in:
Droogans
2015-10-05 15:28:08 -05:00
committed by John-David Dalton
parent 7da4ea5ecb
commit 6725e7dc49
2 changed files with 53 additions and 27 deletions

View File

@@ -11115,6 +11115,23 @@
return result + (index ? '-' : '') + word.toLowerCase();
});
/**
* Converts `string` to lower case.
*
* @static
* @memberOf _
* @category String
* @param {string} [string=''] The string to convert.
* @returns {string} Returns the lower cased string.
* @example
*
* _.lowerCase('FRED');
* // => 'fred'
*/
var lowerCase = createCompounder(function(result, word, index) {
return result + (index ? ' ' : '') + word.toLowerCase();
});
/**
* Pads `string` on the left and right sides if it's shorter than `length`.
* Padding characters are truncated if they can't be evenly divided by `length`.
@@ -11781,6 +11798,23 @@
: string;
}
/**
* Converts `string` to upper case.
*
* @static
* @memberOf _
* @category String
* @param {string} [string=''] The string to convert.
* @returns {string} Returns the upper cased string.
* @example
*
* _.upperCase('fred');
* // => 'FRED'
*/
var upperCase = createCompounder(function(result, word, index) {
return result + (index ? ' ' : '') + word.toUpperCase();
});
/**
* Splits `string` into an array of its words.
*
@@ -12811,6 +12845,7 @@
lodash.kebabCase = kebabCase;
lodash.last = last;
lodash.lastIndexOf = lastIndexOf;
lodash.lowerCase = lowerCase;
lodash.lt = lt;
lodash.lte = lte;
lodash.max = max;
@@ -12854,6 +12889,7 @@
lodash.trunc = trunc;
lodash.unescape = unescape;
lodash.uniqueId = uniqueId;
lodash.upperCase = upperCase;
mixin(lodash, (function() {
var source = {};

View File

@@ -1694,7 +1694,7 @@
QUnit.module('case methods');
_.each(['camel', 'kebab', 'snake', 'start'], function(caseName) {
_.each(['camel', 'kebab', 'lower', 'snake', 'start', 'upper'], function(caseName) {
var methodName = caseName + 'Case',
func = _[methodName];
@@ -1707,8 +1707,10 @@
switch (caseName) {
case 'camel': return 'fooBar';
case 'kebab': return 'foo-bar';
case 'lower': return 'foo bar';
case 'snake': return 'foo_bar';
case 'start': return 'Foo Bar';
case 'upper': return 'FOO BAR';
}
}());
@@ -1739,7 +1741,13 @@
var actual = _.map(burredLetters, function(burred, index) {
var letter = deburredLetters[index];
letter = caseName == 'start' ? _.capitalize(letter) : letter.toLowerCase();
if (caseName == 'start') {
letter = _.capitalize(letter);
} else if (caseName == 'upper') {
letter = letter.toUpperCase();
} else {
letter = letter.toLowerCase();
}
return func(burred) === letter;
});
@@ -1841,28 +1849,6 @@
assert.strictEqual(_.capitalize('Fred'), 'Fred');
assert.strictEqual(_.capitalize(' fred'), ' fred');
});
QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
assert.expect(1);
if (!isNpm) {
assert.strictEqual(_('fred').capitalize(), 'Fred');
}
else {
skipTest(assert);
}
});
QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
assert.expect(1);
if (!isNpm) {
assert.ok(_('fred').chain().capitalize() instanceof _);
}
else {
skipTest(assert);
}
});
}());
/*--------------------------------------------------------------------------*/
@@ -20840,6 +20826,7 @@
'join',
'kebabCase',
'last',
'lowerCase',
'max',
'maxBy',
'min',
@@ -20868,7 +20855,8 @@
'trimLeft',
'trimRight',
'trunc',
'unescape'
'unescape',
'upperCase'
];
_.each(funcs, function(methodName) {
@@ -20988,6 +20976,7 @@
'capitalize',
'escape',
'kebabCase',
'lowerCase',
'pad',
'padLeft',
'padRight',
@@ -20997,7 +20986,8 @@
'trimLeft',
'trimRight',
'trunc',
'unescape'
'unescape',
'upperCase'
];
_.each(stringMethods, function(methodName) {
@@ -21105,7 +21095,7 @@
var acceptFalsey = _.difference(allMethods, rejectFalsey);
QUnit.test('should accept falsey arguments', function(assert) {
assert.expect(251);
assert.expect(253);
var emptyArrays = _.map(falsey, _.constant([]));