mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 03:17:49 +00:00
Adjust how words are deburred.
This commit is contained in:
29
lodash.js
29
lodash.js
@@ -242,22 +242,22 @@
|
|||||||
* for more details.
|
* for more details.
|
||||||
*/
|
*/
|
||||||
var deburredLetters = {
|
var deburredLetters = {
|
||||||
'\xC0': 'a', '\xC1': 'a', '\xC2': 'a', '\xC3': 'a', '\xC4': 'a', '\xC5': 'a',
|
'\xC0': 'A', '\xC1': 'A', '\xC2': 'A', '\xC3': 'A', '\xC4': 'A', '\xC5': 'A',
|
||||||
'\xE0': 'a', '\xE1': 'a', '\xE2': 'a', '\xE3': 'a', '\xE4': 'a', '\xE5': 'a',
|
'\xE0': 'a', '\xE1': 'a', '\xE2': 'a', '\xE3': 'a', '\xE4': 'a', '\xE5': 'a',
|
||||||
'\xC7': 'c', '\xE7': 'c',
|
'\xC7': 'C', '\xE7': 'c',
|
||||||
'\xD0': 'd', '\xF0': 'd',
|
'\xD0': 'D', '\xF0': 'd',
|
||||||
'\xC8': 'e', '\xC9': 'e', '\xCA': 'e', '\xCB': 'e',
|
'\xC8': 'E', '\xC9': 'E', '\xCA': 'E', '\xCB': 'E',
|
||||||
'\xE8': 'e', '\xE9': 'e', '\xEA': 'e', '\xEB': 'e',
|
'\xE8': 'e', '\xE9': 'e', '\xEA': 'e', '\xEB': 'e',
|
||||||
'\xCC': 'i', '\xCD': 'i', '\xCE': 'i', '\xCF': 'i',
|
'\xCC': 'I', '\xCD': 'I', '\xCE': 'I', '\xCF': 'I',
|
||||||
'\xEC': 'i', '\xED': 'i', '\xEE': 'i', '\xEF': 'i',
|
'\xEC': 'i', '\xED': 'i', '\xEE': 'i', '\xEF': 'i',
|
||||||
'\xD1': 'n', '\xF1': 'n',
|
'\xD1': 'N', '\xF1': 'n',
|
||||||
'\xD2': 'o', '\xD3': 'o', '\xD4': 'o', '\xD5': 'o', '\xD6': 'o', '\xD8': 'o',
|
'\xD2': 'O', '\xD3': 'O', '\xD4': 'O', '\xD5': 'O', '\xD6': 'O', '\xD8': 'O',
|
||||||
'\xF2': 'o', '\xF3': 'o', '\xF4': 'o', '\xF5': 'o', '\xF6': 'o', '\xF8': 'o',
|
'\xF2': 'o', '\xF3': 'o', '\xF4': 'o', '\xF5': 'o', '\xF6': 'o', '\xF8': 'o',
|
||||||
'\xD9': 'u', '\xDA': 'u', '\xDB': 'u', '\xDC': 'u',
|
'\xD9': 'U', '\xDA': 'U', '\xDB': 'U', '\xDC': 'U',
|
||||||
'\xF9': 'u', '\xFA': 'u', '\xFB': 'u', '\xFC': 'u',
|
'\xF9': 'u', '\xFA': 'u', '\xFB': 'u', '\xFC': 'u',
|
||||||
'\xDD': 'y', '\xFD': 'y', '\xFF': 'y',
|
'\xDD': 'Y', '\xFD': 'y', '\xFF': 'y',
|
||||||
'\xC6': 'ae', '\xE6': 'ae',
|
'\xC6': 'Ae', '\xE6': 'ae',
|
||||||
'\xDE': 'th', '\xFE': 'th',
|
'\xDE': 'Th', '\xFE': 'th',
|
||||||
'\xDF': 'ss', '\xD7': ' ', '\xF7': ' '
|
'\xDF': 'ss', '\xD7': ' ', '\xF7': ' '
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -500,7 +500,7 @@
|
|||||||
result = '';
|
result = '';
|
||||||
|
|
||||||
while (++index < length) {
|
while (++index < length) {
|
||||||
result = callback(result, words[index].toLowerCase(), index, words);
|
result = callback(result, words[index], index, words);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
@@ -8012,6 +8012,7 @@
|
|||||||
* // => 'helloWorld'
|
* // => 'helloWorld'
|
||||||
*/
|
*/
|
||||||
var camelCase = createCompounder(function(result, word, index) {
|
var camelCase = createCompounder(function(result, word, index) {
|
||||||
|
word = word.toLowerCase();
|
||||||
return index ? (result + word.charAt(0).toUpperCase() + word.slice(1)) : word;
|
return index ? (result + word.charAt(0).toUpperCase() + word.slice(1)) : word;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -8139,7 +8140,7 @@
|
|||||||
* // => 'hello-world'
|
* // => 'hello-world'
|
||||||
*/
|
*/
|
||||||
var kebabCase = createCompounder(function(result, word, index) {
|
var kebabCase = createCompounder(function(result, word, index) {
|
||||||
return result + (index ? '-' : '') + word;
|
return result + (index ? '-' : '') + word.toLowerCase();
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -8300,7 +8301,7 @@
|
|||||||
* // => 'hello_world'
|
* // => 'hello_world'
|
||||||
*/
|
*/
|
||||||
var snakeCase = createCompounder(function(result, word, index) {
|
var snakeCase = createCompounder(function(result, word, index) {
|
||||||
return result + (index ? '_' : '') + word;
|
return result + (index ? '_' : '') + word.toLowerCase();
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
27
test/test.js
27
test/test.js
@@ -1288,6 +1288,11 @@
|
|||||||
var methodName = caseName + 'Case',
|
var methodName = caseName + 'Case',
|
||||||
func = _[methodName];
|
func = _[methodName];
|
||||||
|
|
||||||
|
var strings = [
|
||||||
|
'hello world', 'Hello world', 'HELLO WORLD',
|
||||||
|
'helloWorld', '--hello-world', '__hello_world__'
|
||||||
|
];
|
||||||
|
|
||||||
var expected = (function() {
|
var expected = (function() {
|
||||||
switch (caseName) {
|
switch (caseName) {
|
||||||
case 'camel': return 'helloWorld';
|
case 'camel': return 'helloWorld';
|
||||||
@@ -1304,26 +1309,26 @@
|
|||||||
];
|
];
|
||||||
|
|
||||||
var deburredLetters = [
|
var deburredLetters = [
|
||||||
'A', 'A', 'A', 'A', 'A', 'A', 'AE', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I', 'I',
|
'A', 'A', 'A', 'A', 'A', 'A', 'Ae', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I', 'I',
|
||||||
'D', 'N', 'O', 'O', 'O', 'O', 'O', '', 'O', 'U', 'U', 'U', 'U', 'Y', 'Th', 'ss',
|
'D', 'N', 'O', 'O', 'O', 'O', 'O', '', 'O', 'U', 'U', 'U', 'U', 'Y', 'Th', 'ss',
|
||||||
'a', 'a', 'a', 'a', 'a', 'a', 'ae', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i',
|
'a', 'a', 'a', 'a', 'a', 'a', 'ae', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i',
|
||||||
'd', 'n', 'o', 'o', 'o', 'o', 'o', '', 'o', 'u', 'u', 'u', 'u', 'y', 'th', 'y'
|
'd', 'n', 'o', 'o', 'o', 'o', 'o', '', 'o', 'u', 'u', 'u', 'u', 'y', 'th', 'y'
|
||||||
];
|
];
|
||||||
|
|
||||||
test('`_.' + methodName + '` should convert `string` to ' + caseName + ' case', 4, function() {
|
test('`_.' + methodName + '` should convert `string` to ' + caseName + ' case', 1, function() {
|
||||||
_.each(['Hello world', 'helloWorld', '--hello-world', '__hello_world__'], function(string) {
|
var actual = _.map(strings, function(string) {
|
||||||
strictEqual(func(string), expected);
|
return func(string) === expected;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ok(_.every(actual));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('`_.' + methodName + '` should handle double-converting strings', 4, function() {
|
test('`_.' + methodName + '` should handle double-converting strings', 1, function() {
|
||||||
_.each(['Hello world', 'helloWorld', '--hello-world', '__hello_world__'], function(string) {
|
var actual = _.map(strings, function(string) {
|
||||||
strictEqual(func(func(string)), expected);
|
return func(func(string)) === expected;
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
test('`_.' + methodName + '` should work with words in all caps', 1, function() {
|
ok(_.every(actual));
|
||||||
strictEqual(func('HELLO WORLD'), expected);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('`_.' + methodName + '` should deburr letters', 1, function() {
|
test('`_.' + methodName + '` should deburr letters', 1, function() {
|
||||||
@@ -1331,7 +1336,7 @@
|
|||||||
return func(burred) == deburredLetters[index].toLowerCase();
|
return func(burred) == deburredLetters[index].toLowerCase();
|
||||||
});
|
});
|
||||||
|
|
||||||
ok(_.every(actual, _.identity));
|
ok(_.every(actual));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('`_.' + methodName + '` should coerce `string` to a string', 2, function() {
|
test('`_.' + methodName + '` should coerce `string` to a string', 2, function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user