From: Coleman Watts Date: Tue, 23 Jun 2020 14:54:18 +0000 (-0400) Subject: APIv4 Explorer - Update pluralize fn to match CRM_Utils_String X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=628ae369efa2ff3ca08c7b8029efb1f96db92567;p=civicrm-core.git APIv4 Explorer - Update pluralize fn to match CRM_Utils_String --- diff --git a/ang/api4Explorer/Explorer.js b/ang/api4Explorer/Explorer.js index d9d8d425e9..953bdba0ab 100644 --- a/ang/api4Explorer/Explorer.js +++ b/ang/api4Explorer/Explorer.js @@ -94,14 +94,15 @@ } function pluralize(str) { - switch (str[str.length-1]) { - case 's': - return str + 'es'; - case 'y': - return str.slice(0, -1) + 'ies'; - default: - return str + 's'; + var lastLetter = str[str.length - 1], + lastTwo = str[str.length - 2] + lastLetter; + if (lastLetter === 's' || lastTwo === 'ch') { + return str + 'es'; } + if (lastLetter === 'y' && lastTwo !== 'ey') { + return str.slice(0, -1) + 'ies'; + } + return str + 's'; } // Reformat an existing array of objects for compatibility with select2