mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-06 09:47:48 +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.
|
* @returns {string} Returns the start cased string.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* _.startCase('--foo-bar');
|
* _.startCase('--foo-bar--');
|
||||||
* // => 'Foo Bar'
|
* // => 'Foo Bar'
|
||||||
*
|
*
|
||||||
* _.startCase('fooBar');
|
* _.startCase('fooBar');
|
||||||
* // => 'Foo Bar'
|
* // => 'Foo Bar'
|
||||||
*
|
*
|
||||||
* _.startCase('__foo_bar__');
|
* _.startCase('__FOO_BAR__');
|
||||||
* // => 'Foo Bar'
|
* // => 'FOO BAR'
|
||||||
*/
|
*/
|
||||||
var startCase = createCompounder(function(result, word, index) {
|
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 = [
|
var strings = [
|
||||||
'foo bar', 'Foo bar', 'foo Bar', 'Foo Bar',
|
'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() {
|
var converted = (function() {
|
||||||
@@ -2108,7 +2108,8 @@
|
|||||||
assert.expect(1);
|
assert.expect(1);
|
||||||
|
|
||||||
var actual = lodashStable.map(strings, function(string) {
|
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));
|
assert.deepEqual(actual, lodashStable.map(strings, alwaysTrue));
|
||||||
@@ -2118,7 +2119,8 @@
|
|||||||
assert.expect(1);
|
assert.expect(1);
|
||||||
|
|
||||||
var actual = lodashStable.map(strings, function(string) {
|
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));
|
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');
|
QUnit.module('lodash.startsWith');
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user