Skip to content

Commit

Permalink
fix: pluralization of words ending in y, where y follows a vowel
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Dec 23, 2024
1 parent 592ca15 commit c01d24d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
19 changes: 18 additions & 1 deletion packages/core/types/src/common/__tests__/pluralize.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ describe("Pluralize", () => {
expectTypeOf<Pluralize<"knife">>().toEqualTypeOf<"knives">()
})

test("pluralize words ending with ch", () => {
expectTypeOf<Pluralize<"church">>().toEqualTypeOf<"churches">()
expectTypeOf<Pluralize<"arch">>().toEqualTypeOf<"arches">()
})

test("pluralize words ending with o", () => {
expectTypeOf<Pluralize<"hero">>().toEqualTypeOf<"heroes">()
})
Expand All @@ -30,8 +35,20 @@ describe("Pluralize", () => {
expectTypeOf<Pluralize<"fiz">>().toEqualTypeOf<"fizes">()
})

test("pluralize words ending with y", () => {
test("pluralize words ending with y, in which y follows a constant", () => {
expectTypeOf<Pluralize<"puppy">>().toEqualTypeOf<"puppies">()
expectTypeOf<Pluralize<"twenty">>().toEqualTypeOf<"twenties">()
expectTypeOf<Pluralize<"copy">>().toEqualTypeOf<"copies">()
})

test("pluralize words ending with y, in which y follow a vowel", () => {
expectTypeOf<Pluralize<"play">>().toEqualTypeOf<"plays">()
expectTypeOf<Pluralize<"relay">>().toEqualTypeOf<"relays">()
expectTypeOf<Pluralize<"alley">>().toEqualTypeOf<"alleys">()
expectTypeOf<Pluralize<"alley">>().toEqualTypeOf<"alleys">()
expectTypeOf<Pluralize<"boy">>().toEqualTypeOf<"boys">()
expectTypeOf<Pluralize<"enjoy">>().toEqualTypeOf<"enjoys">()
expectTypeOf<Pluralize<"buy">>().toEqualTypeOf<"buys">()
})

test("pluralize words with special rules", () => {
Expand Down
24 changes: 16 additions & 8 deletions packages/core/types/src/common/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,26 +365,34 @@ export type Pluralize<Singular extends string> =
? PluralizationSpecialRules[Lowercase<Singular>]
: Lowercase<Singular> extends UncountableRules
? Singular
: Singular extends `${infer R}ss`
: Singular extends `${string}ss`
? `${Singular}es`
: Singular extends `${infer R}sis`
? `${R}ses`
: Singular extends `${infer R}is`
? `${R}ises`
: Singular extends `${infer R}s`
: Singular extends `${string}s`
? `${Singular}`
: Singular extends `${infer R}ay`
? `${R}ays`
: Singular extends `${infer R}ey`
? `${R}eys`
: Singular extends `${infer R}iy`
? `${R}iys`
: Singular extends `${infer R}oy`
? `${R}oys`
: Singular extends `${infer R}uy`
? `${R}uys`
: Singular extends `${infer R}y`
? `${R}ies`
: Singular extends `${infer R}es`
: Singular extends `${string}es`
? `${Singular}`
: Singular extends
| `${infer R}sh`
| `${infer R}ch`
| `${infer R}x`
| `${infer R}z`
| `${infer R}o`
| `${string}sh`
| `${string}ch`
| `${string}x`
| `${string}z`
| `${string}o`
? `${Singular}es`
: Singular extends `${infer R}fe`
? `${R}ves`
Expand Down

0 comments on commit c01d24d

Please sign in to comment.