Add an utility to fix author name capitalization (#1550)

This commit is contained in:
Martynas Bagdonas 2018-08-16 17:22:39 +08:00 committed by Dan Stillman
parent 1ffc34a8ac
commit 7a3dc61892

View file

@ -144,6 +144,28 @@ var CSL_TYPE_MAPPINGS = {
* @class Functions for text manipulation and other miscellaneous purposes
*/
Zotero.Utilities = {
/**
* Fixes author name capitalization.
* Currently for all uppercase names only
*
* JOHN -> John
* GUTIÉRREZ-ALBILLA -> Gutiérrez-Albilla
* O'NEAL -> O'Neal
*
* @param {String} string Uppercase author name
* @return {String} Title-cased author name
*/
"capitalizeName": function (string) {
if (typeof string === "string" && string.toUpperCase() === string) {
string = Zotero.Utilities.XRegExp.replace(
string.toLowerCase(),
Zotero.Utilities.XRegExp('(^|[^\\pL])\\pL', 'g'),
m => m.toUpperCase()
);
}
return string;
},
/**
* Cleans extraneous punctuation off a creator name and parse into first and last name
*