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:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user