Created
September 4, 2020 09:23
-
-
Save kleberksms/1ccb5919ec0c78c66cb4080ab1bd0d85 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export class Inflector { | |
| static pluralize(word: string): string { | |
| if (!word) { | |
| return; | |
| } | |
| const isPluralAlready = word.endsWith('ies') || word.endsWith('es') || (!word.endsWith('us') && word.endsWith('s')); | |
| if (isPluralAlready) { | |
| return word; | |
| } | |
| if (word.endsWith('y') && !word.endsWith('ay')) { | |
| return `${word.substring(0, word.length - 1)}ies`; | |
| } | |
| return word.endsWith('us') ? `${word}es` : `${word}s`; | |
| } | |
| } |
Author
const isPluralAlready = word.endsWith('s') && !word.endsWith('us')
Thank you 😊
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
const isPluralAlready = word.endsWith('s') && !word.endsWith('us')