Add an utility to fix author name capitalization (#1550)
This commit is contained in:
parent
1ffc34a8ac
commit
7a3dc61892
1 changed files with 22 additions and 0 deletions
|
@ -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
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue