mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 15:27:50 +00:00
Ensure _.startCase only uppercases the first character of each word.
This commit is contained in:
@@ -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);
|
||||
});
|
||||
|
||||
/**
|
||||
|
||||
22
test/test.js
22
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() {
|
||||
|
||||
Reference in New Issue
Block a user