fix(utils): define link alias + pluralize (#8070)

What:
 * Fix alias of models that have "compound names": eg "related_product"
 * `deleteCascade` option
 * Package to pluralize english words correctly
This commit is contained in:
Carlos R. L. Rodrigues
2024-07-10 22:37:14 +00:00
committed by GitHub
parent 256912f392
commit f460348280
6 changed files with 129 additions and 32 deletions
+5 -22
View File
@@ -1,27 +1,10 @@
import pluralizeEN from "pluralize"
/**
* Some library provide pluralize function with language specific rules.
* This is a simple implementation of pluralize function.
* Function to pluralize English words.
* @param word
*/
export function pluralize(word: string): string {
// Add basic rules for forming plurals
if (
//word.endsWith("s") ||
word.endsWith("sh") ||
word.endsWith("ss") ||
word.endsWith("ch") ||
word.endsWith("x") ||
word.endsWith("o") ||
word.endsWith("z")
) {
return word + "es"
} else if (word.endsWith("y") && !"aeiou".includes(word[word.length - 2])) {
return word.slice(0, -1) + "ies"
} else if (word.endsWith("es")) {
return word
} else if (word.endsWith("fe")) {
return word.slice(0, -2) + "ves"
} else {
return word + "s"
}
// TODO: Implement language specific pluralize function
return pluralizeEN(word)
}