From 628ae369efa2ff3ca08c7b8029efb1f96db92567 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Tue, 23 Jun 2020 10:54:18 -0400 Subject: [PATCH] APIv4 Explorer - Update pluralize fn to match CRM_Utils_String --- ang/api4Explorer/Explorer.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) 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 -- 2.25.1