From c9ca9c5a676804a4868d7fdcfe2b67eea2253469 Mon Sep 17 00:00:00 2001 From: Mradul Singh Date: Fri, 20 Nov 2026 00:49:39 +0530 Subject: [PATCH] fix: pluralize and singularize compounds of man and woman policeman -> policemen and policemen -> policeman. The man/men rules were anchored to the whole word, so compounds fell through to the generic -s rule (policemans, and policemen -> policemens). Keep -man words that are not compounds of man (human, German, shaman, talisman) and singular nouns that end in -men (specimen, omen) working. Refs #129 --- src/inflection.ts | 18 ++++++++++++++++-- test/inflection.test.ts | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/src/inflection.ts b/src/inflection.ts index 0cd03c9..f65eefb 100644 --- a/src/inflection.ts +++ b/src/inflection.ts @@ -339,7 +339,12 @@ const uncountableWords = [ const regex = { plural: { - men: new RegExp('^(m|wom)en$', 'gi'), + men: new RegExp('(m|wom)en$', 'gi'), + // singular nouns that end in -men, not plurals of -man (specimen, omen) + menSingular: new RegExp( + '^(a|abdo|acu|agno|albu|bitu|catechu|ceru|cogno|cul|cycla|dol|dura|exa|fla|fora|grava|hy|legu|li|lu|no|nu|o|praeno|puta|regi|ru|se|speci|sta|teg|tegu|vela)men$', + 'gi' + ), people: new RegExp('(pe)ople$', 'gi'), children: new RegExp('(child)ren$', 'gi'), tia: new RegExp('([ti])a$', 'gi'), @@ -383,7 +388,12 @@ const regex = { }, singular: { - man: new RegExp('^(m|wom)an$', 'gi'), + man: new RegExp('(m|wom)an$', 'gi'), + // nouns that end in -man but are not compounds of man (human, German) + manNonCompound: new RegExp( + '(?:^(?:ata|brah|cai|cay|des|dol|ger|het|mussul|nor|otto|ro|sha|talis|turko)|hu)man$', + 'gi' + ), person: new RegExp('(pe)rson$', 'gi'), child: new RegExp('(child)$', 'gi'), drive: new RegExp('(drive)$', 'gi'), @@ -418,6 +428,9 @@ const regex = { }; const pluralRules: [RegExp, string?][] = [ + [regex.plural.menSingular, '$&s'], + [regex.singular.manNonCompound, '$&s'], + // do not replace if its already a plural word [regex.plural.men], [regex.plural.people], @@ -494,6 +507,7 @@ const pluralRules: [RegExp, string?][] = [ */ const singularRules: [RegExp, string?][] = [ // do not replace if its already a singular word + [regex.plural.menSingular], [regex.singular.man], [regex.singular.person], [regex.singular.child], diff --git a/test/inflection.test.ts b/test/inflection.test.ts index 2e0a16c..11c3c12 100644 --- a/test/inflection.test.ts +++ b/test/inflection.test.ts @@ -55,6 +55,24 @@ describe('test .pluralize', function () { expect(inflection.pluralize('nuclei')).toEqual('nuclei'); expect(inflection.pluralize('nucleuses')).toEqual('nucleuses'); }); + + it('should pluralize compounds of man and woman', function () { + expect(inflection.pluralize('policeman')).toEqual('policemen'); + expect(inflection.pluralize('Fireman')).toEqual('Firemen'); + expect(inflection.pluralize('gentleman')).toEqual('gentlemen'); + expect(inflection.pluralize('policewoman')).toEqual('policewomen'); + expect(inflection.pluralize('policemen')).toEqual('policemen'); + expect(inflection.pluralize('policewomen')).toEqual('policewomen'); + // -man words that are not compounds of man + expect(inflection.pluralize('superhuman')).toEqual('superhumans'); + expect(inflection.pluralize('German')).toEqual('Germans'); + expect(inflection.pluralize('shaman')).toEqual('shamans'); + expect(inflection.pluralize('talisman')).toEqual('talismans'); + // singular nouns that end in -men + expect(inflection.pluralize('specimen')).toEqual('specimens'); + expect(inflection.pluralize('omen')).toEqual('omens'); + expect(inflection.pluralize('abdomen')).toEqual('abdomens'); + }); }); describe('test .singularize', function () { @@ -115,6 +133,21 @@ describe('test .singularize', function () { expect(inflection.singularize('bases')).toEqual('basis'); expect(inflection.singularize('diagnoses')).toEqual('diagnosis'); }); + + it('should singularize compounds of man and woman', function () { + expect(inflection.singularize('policemen')).toEqual('policeman'); + expect(inflection.singularize('Firemen')).toEqual('Fireman'); + expect(inflection.singularize('gentlemen')).toEqual('gentleman'); + expect(inflection.singularize('policewomen')).toEqual('policewoman'); + expect(inflection.singularize('policeman')).toEqual('policeman'); + expect(inflection.singularize('superhumans')).toEqual('superhuman'); + expect(inflection.singularize('shamans')).toEqual('shaman'); + // singular nouns that end in -men + expect(inflection.singularize('specimen')).toEqual('specimen'); + expect(inflection.singularize('specimens')).toEqual('specimen'); + expect(inflection.singularize('omen')).toEqual('omen'); + expect(inflection.singularize('regimen')).toEqual('regimen'); + }); }); describe('test .inflect', function () {