@jckj/pluralizeword 0.0.0-stage → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +127 -3
- package/dist/pluralizeWord.js +439 -0
- package/index.d.ts +36 -0
- package/package.json +40 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 hzqhxy
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,127 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
|
|
2
|
+
# Pluralize Word API 文档
|
|
3
|
+
|
|
4
|
+
该模块提供了根据英语语法规则将单数名词转换为复数形式的功能。它支持不规则变化、规则变化,并能够智能保持原词的大小写格式。
|
|
5
|
+
|
|
6
|
+
## 目录
|
|
7
|
+
- [Pluralize Word API 文档](#pluralize-word-api-文档)
|
|
8
|
+
- [目录](#目录)
|
|
9
|
+
- [函数 API](#函数-api)
|
|
10
|
+
- [`pluralizeWord`](#pluralizeword)
|
|
11
|
+
- [签名 1:仅通过数量判断](#签名-1仅通过数量判断)
|
|
12
|
+
- [签名 2:自定义复数形式](#签名-2自定义复数形式)
|
|
13
|
+
- [实现细节](#实现细节)
|
|
14
|
+
- [内部辅助函数](#内部辅助函数)
|
|
15
|
+
- [`getRegularPlural`](#getregularplural)
|
|
16
|
+
- [`applyCase`](#applycase)
|
|
17
|
+
- [使用示例](#使用示例)
|
|
18
|
+
- [配置要求](#配置要求)
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## 函数 API
|
|
23
|
+
|
|
24
|
+
### `pluralizeWord`
|
|
25
|
+
|
|
26
|
+
根据数量将英语单数名词转换为复数形式。支持不规则变化、规则变化,并保持原词的大小写格式。
|
|
27
|
+
|
|
28
|
+
该函数提供了多个重载签名,以支持不同的调用方式。
|
|
29
|
+
|
|
30
|
+
#### 签名 1:仅通过数量判断
|
|
31
|
+
```typescript
|
|
32
|
+
export function pluralizeWord(word: string, count: number): string;
|
|
33
|
+
```
|
|
34
|
+
- **参数**:
|
|
35
|
+
- `word` (`string`): 需要处理的单词。
|
|
36
|
+
- `count` (`number`): 单词的数量,用于决定返回单数还是复数。
|
|
37
|
+
- **返回值**: (`string`) 根据数量返回的单数或复数形式的字符串。
|
|
38
|
+
|
|
39
|
+
#### 签名 2:自定义复数形式
|
|
40
|
+
```typescript
|
|
41
|
+
export function pluralizeWord(word: string, plural: string, count: number): string;
|
|
42
|
+
```
|
|
43
|
+
- **参数**:
|
|
44
|
+
- `word` (`string`): 需要处理的单词。
|
|
45
|
+
- `plural` (`string`): 自定义的复数形式。
|
|
46
|
+
- `count` (`number`): 单词的数量,用于决定返回单数还是复数。
|
|
47
|
+
- **返回值**: (`string`) 根据数量返回的单数或复数形式的字符串。
|
|
48
|
+
|
|
49
|
+
#### 实现细节
|
|
50
|
+
- **参数预处理**:如果第二个参数被识别为数字,则会将其作为 `count` 处理。
|
|
51
|
+
- **自动推导**:如果没有提供有效的自定义复数形式(如 `undefined` 或空字符串),函数会自动从内置的不规则名词表(`irregularPlurals.json`)中查找;若未找到,则调用 `getRegularPlural` 按语法规则生成。
|
|
52
|
+
- **大小写保持**:自动推导出的复数形式会通过 `applyCase` 函数处理,以匹配原词的首字母大写或全大写状态。
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## 内部辅助函数
|
|
57
|
+
|
|
58
|
+
以下函数为模块内部使用,不对外导出,但了解它们有助于理解内部逻辑。
|
|
59
|
+
|
|
60
|
+
### `getRegularPlural`
|
|
61
|
+
|
|
62
|
+
根据英语语法规则生成单词的复数形式。主要处理以下规则:
|
|
63
|
+
- 以 `s`, `x`, `z`, `ch`, `sh` 结尾的词,加 `es` (如 `box` -> `boxes`)。
|
|
64
|
+
- 以辅音字母加 `y` 结尾的词,将 `y` 改为 `ies` (如 `party` -> `parties`)。
|
|
65
|
+
- 其他情况直接加 `s`。
|
|
66
|
+
- 保持原词尾部的大小写状态(如 `BOX` -> `BOXES`)。
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
function getRegularPlural(word: string): string;
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### `applyCase`
|
|
73
|
+
|
|
74
|
+
将推导出的复数形式应用到原词的大小写格式上。
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
function applyCase(singular: string, plural: string): string;
|
|
78
|
+
```
|
|
79
|
+
- **逻辑**:
|
|
80
|
+
1. 判断原词首字母是否大写,若是,则将复数词首字母大写(如 `Mouse` -> `Mice`)。
|
|
81
|
+
2. 判断原词是否全大写,若是,则将复数词全部大写(如 `MOUSE` -> `MICE`)。
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## 使用示例
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
import { pluralizeWord } from './pluralize';
|
|
89
|
+
|
|
90
|
+
// 1. 使用规则变化
|
|
91
|
+
console.log(pluralizeWord("apple", 2)); // 输出: "apples"
|
|
92
|
+
console.log(pluralizeWord("box", 2)); // 输出: "boxes"
|
|
93
|
+
console.log(pluralizeWord("party", 2)); // 输出: "parties"
|
|
94
|
+
|
|
95
|
+
// 2. 使用不规则变化 (依赖 irregularPlurals.json)
|
|
96
|
+
console.log(pluralizeWord("mouse", 2)); // 输出: "mice"
|
|
97
|
+
console.log(pluralizeWord("goose", 2)); // 输出: "geese"
|
|
98
|
+
|
|
99
|
+
// 3. 数量为 1 时返回原词
|
|
100
|
+
console.log(pluralizeWord("apple", 1)); // 输出: "apple"
|
|
101
|
+
console.log(pluralizeWord("mouse", 1)); // 输出: "mouse"
|
|
102
|
+
|
|
103
|
+
// 4. 保持大小写格式
|
|
104
|
+
console.log(pluralizeWord("Apple", 2)); // 输出: "Apples"
|
|
105
|
+
console.log(pluralizeWord("Mouse", 2)); // 输出: "Mice"
|
|
106
|
+
console.log(pluralizeWord("BOX", 2)); // 输出: "BOXES"
|
|
107
|
+
console.log(pluralizeWord("MOUSE", 2)); // 输出: "MICE"
|
|
108
|
+
|
|
109
|
+
// 5. 使用自定义复数形式
|
|
110
|
+
console.log(pluralizeWord("person", "people", 2)); // 输出: "people"
|
|
111
|
+
console.log(pluralizeWord("person", "people", 1)); // 输出: "person"
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## 配置要求
|
|
117
|
+
|
|
118
|
+
由于本模块使用了 `import irregularPluralsJson from "./irregularPlurals.json";` 来导入 JSON 文件,请确保您的 `tsconfig.json` 中已启用以下配置项:
|
|
119
|
+
|
|
120
|
+
```json
|
|
121
|
+
{
|
|
122
|
+
"compilerOptions": {
|
|
123
|
+
"resolveJsonModule": true,
|
|
124
|
+
"esModuleInterop": true
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
```
|
|
@@ -0,0 +1,439 @@
|
|
|
1
|
+
// lib/pluralizeWord.ts
|
|
2
|
+
var e = new Map(Object.entries({
|
|
3
|
+
abscissa: "abscissae",
|
|
4
|
+
addendum: "addenda",
|
|
5
|
+
adulthood: "adulthood",
|
|
6
|
+
advice: "advice",
|
|
7
|
+
afreet: "afreets",
|
|
8
|
+
afrit: "afrits",
|
|
9
|
+
agendum: "agenda",
|
|
10
|
+
aid: "aid",
|
|
11
|
+
aircraft: "aircraft",
|
|
12
|
+
albino: "albinos",
|
|
13
|
+
alcohol: "alcohol",
|
|
14
|
+
alga: "algae",
|
|
15
|
+
alto: "altos",
|
|
16
|
+
alumna: "alumnae",
|
|
17
|
+
alumnus: "alumni",
|
|
18
|
+
alveolus: "alveoli",
|
|
19
|
+
amoeba: "amoebas",
|
|
20
|
+
ammo: "ammo",
|
|
21
|
+
analysis: "analyses",
|
|
22
|
+
analytics: "analytics",
|
|
23
|
+
anathema: "anathemas",
|
|
24
|
+
anime: "anime",
|
|
25
|
+
antenna: "antennas",
|
|
26
|
+
antithesis: "antitheses",
|
|
27
|
+
aphelion: "aphelia",
|
|
28
|
+
apparatus: "apparatuses",
|
|
29
|
+
appendix: "appendixes",
|
|
30
|
+
aquarium: "aquariums",
|
|
31
|
+
archipelago: "archipelagos",
|
|
32
|
+
armadillo: "armadillos",
|
|
33
|
+
asyndeton: "asyndetons",
|
|
34
|
+
athletics: "athletics",
|
|
35
|
+
audio: "audio",
|
|
36
|
+
aurora: "auroras",
|
|
37
|
+
automaton: "automatons",
|
|
38
|
+
axis: "axes",
|
|
39
|
+
bacillus: "bacilli",
|
|
40
|
+
bacterium: "bacteria",
|
|
41
|
+
baculum: "bacula",
|
|
42
|
+
barracks: "barracks",
|
|
43
|
+
basis: "bases",
|
|
44
|
+
basso: "bassos",
|
|
45
|
+
beau: "beaus",
|
|
46
|
+
beef: "beefs",
|
|
47
|
+
blood: "blood",
|
|
48
|
+
bema: "bemas",
|
|
49
|
+
biceps: "biceps",
|
|
50
|
+
bison: "bison",
|
|
51
|
+
bream: "bream",
|
|
52
|
+
breeches: "breeches",
|
|
53
|
+
britches: "britches",
|
|
54
|
+
brother: "brothers",
|
|
55
|
+
buffalo: "buffalo",
|
|
56
|
+
bureau: "bureaus",
|
|
57
|
+
businessman: "businessmen",
|
|
58
|
+
butter: "butter",
|
|
59
|
+
cactus: "cactuses",
|
|
60
|
+
calf: "calves",
|
|
61
|
+
cash: "cash",
|
|
62
|
+
candelabrum: "candelabra",
|
|
63
|
+
canto: "cantos",
|
|
64
|
+
cantus: "cantus",
|
|
65
|
+
carcinoma: "carcinomas",
|
|
66
|
+
carp: "carp",
|
|
67
|
+
census: "censuses",
|
|
68
|
+
chapeau: "chapeaus",
|
|
69
|
+
charisma: "charismas",
|
|
70
|
+
chairman: "chairmen",
|
|
71
|
+
chassis: "chassis",
|
|
72
|
+
cherub: "cherubs",
|
|
73
|
+
chess: "chess",
|
|
74
|
+
child: "children",
|
|
75
|
+
château: "châteaus",
|
|
76
|
+
clippers: "clippers",
|
|
77
|
+
clitoris: "clitorises",
|
|
78
|
+
clothes: "clothes",
|
|
79
|
+
clothing: "clothing",
|
|
80
|
+
cloaca: "cloacae",
|
|
81
|
+
cod: "cod",
|
|
82
|
+
codex: "codices",
|
|
83
|
+
commerce: "commerce",
|
|
84
|
+
coitus: "coitus",
|
|
85
|
+
commando: "commandos",
|
|
86
|
+
compendium: "compendiums",
|
|
87
|
+
concerto: "concertos",
|
|
88
|
+
consortium: "consortia",
|
|
89
|
+
contralto: "contraltos",
|
|
90
|
+
contretemps: "contretemps",
|
|
91
|
+
cooperation: "cooperation",
|
|
92
|
+
corps: "corps",
|
|
93
|
+
corpus: "corpora",
|
|
94
|
+
cortex: "cortices",
|
|
95
|
+
cranium: "crania",
|
|
96
|
+
crescendo: "crescendos",
|
|
97
|
+
crisis: "crises",
|
|
98
|
+
criterion: "criteria",
|
|
99
|
+
curriculum: "curricula",
|
|
100
|
+
cyclops: "cyclopses",
|
|
101
|
+
cystoma: "cystomata",
|
|
102
|
+
data: "data",
|
|
103
|
+
datum: "data",
|
|
104
|
+
debris: "debris",
|
|
105
|
+
deer: "deer",
|
|
106
|
+
desideratum: "desiderata",
|
|
107
|
+
diabetes: "diabetes",
|
|
108
|
+
diagnosis: "diagnoses",
|
|
109
|
+
dictum: "dicta",
|
|
110
|
+
die: "dice",
|
|
111
|
+
digestion: "digestion",
|
|
112
|
+
dingo: "dingoes",
|
|
113
|
+
diploma: "diplomas",
|
|
114
|
+
ditto: "dittos",
|
|
115
|
+
djinni: "djinn",
|
|
116
|
+
dogma: "dogmata",
|
|
117
|
+
drama: "dramas",
|
|
118
|
+
dwarf: "dwarfs",
|
|
119
|
+
dynamo: "dynamos",
|
|
120
|
+
economics: "economics",
|
|
121
|
+
echo: "echoes",
|
|
122
|
+
edema: "edemas",
|
|
123
|
+
efreet: "efreets",
|
|
124
|
+
eland: "eland",
|
|
125
|
+
elf: "elves",
|
|
126
|
+
elk: "elk",
|
|
127
|
+
ellipsis: "ellipses",
|
|
128
|
+
embargo: "embargoes",
|
|
129
|
+
embryo: "embryos",
|
|
130
|
+
emphasis: "emphases",
|
|
131
|
+
emporium: "emporia",
|
|
132
|
+
encomium: "encomia",
|
|
133
|
+
enigma: "enigmas",
|
|
134
|
+
equipment: "equipment",
|
|
135
|
+
ephemeris: "ephemerides",
|
|
136
|
+
erratum: "errata",
|
|
137
|
+
excretion: "excretion",
|
|
138
|
+
expertise: "expertise",
|
|
139
|
+
extremum: "extrema",
|
|
140
|
+
"faux pas": "faux pas",
|
|
141
|
+
fez: "fezzes",
|
|
142
|
+
fiasco: "fiascos",
|
|
143
|
+
fibula: "fibulae",
|
|
144
|
+
firmware: "firmware",
|
|
145
|
+
fish: "fish",
|
|
146
|
+
flounder: "flounder",
|
|
147
|
+
focus: "focuses",
|
|
148
|
+
foot: "feet",
|
|
149
|
+
fun: "fun",
|
|
150
|
+
foramen: "foramina",
|
|
151
|
+
formula: "formulas",
|
|
152
|
+
forum: "forums",
|
|
153
|
+
fungus: "fungi",
|
|
154
|
+
gallows: "gallows",
|
|
155
|
+
garbage: "garbage",
|
|
156
|
+
ganglion: "ganglia",
|
|
157
|
+
generalissimo: "generalissimos",
|
|
158
|
+
genie: "genies",
|
|
159
|
+
gentleman: "gentlemen",
|
|
160
|
+
genus: "genera",
|
|
161
|
+
ghetto: "ghettos",
|
|
162
|
+
glomerulus: "glomeruli",
|
|
163
|
+
goose: "geese",
|
|
164
|
+
goy: "goyim",
|
|
165
|
+
graffiti: "graffiti",
|
|
166
|
+
graffito: "graffiti",
|
|
167
|
+
grouse: "grouse",
|
|
168
|
+
guano: "guano",
|
|
169
|
+
gumma: "gummata",
|
|
170
|
+
gymnasium: "gymnasiums",
|
|
171
|
+
half: "halves",
|
|
172
|
+
hamulus: "hamuli",
|
|
173
|
+
hardware: "hardware",
|
|
174
|
+
health: "health",
|
|
175
|
+
headquarters: "headquarters",
|
|
176
|
+
hero: "heroes",
|
|
177
|
+
herpes: "herpes",
|
|
178
|
+
highjinks: "highjinks",
|
|
179
|
+
hijinks: "hijinks",
|
|
180
|
+
hiatus: "hiatuses",
|
|
181
|
+
hippopotamus: "hippopotamuses",
|
|
182
|
+
homework: "homework",
|
|
183
|
+
honorarium: "honoraria",
|
|
184
|
+
hoof: "hooves",
|
|
185
|
+
housework: "housework",
|
|
186
|
+
hovercraft: "hovercraft",
|
|
187
|
+
humerus: "humeri",
|
|
188
|
+
hyperbaton: "hyperbata",
|
|
189
|
+
hyperbola: "hyperbolae",
|
|
190
|
+
hypothesis: "hypotheses",
|
|
191
|
+
ilium: "ilia",
|
|
192
|
+
impetus: "impetuses",
|
|
193
|
+
incubus: "incubi",
|
|
194
|
+
index: "indexes",
|
|
195
|
+
information: "information",
|
|
196
|
+
inferno: "infernos",
|
|
197
|
+
innings: "innings",
|
|
198
|
+
interregnum: "interregna",
|
|
199
|
+
interstitium: "interstitia",
|
|
200
|
+
jackanapes: "jackanapes",
|
|
201
|
+
jeans: "jeans",
|
|
202
|
+
jumbo: "jumbos",
|
|
203
|
+
kakapo: "kakapo",
|
|
204
|
+
knife: "knives",
|
|
205
|
+
kudos: "kudos",
|
|
206
|
+
labour: "labour",
|
|
207
|
+
lacuna: "lacunas",
|
|
208
|
+
larva: "larvae",
|
|
209
|
+
leaf: "leaves",
|
|
210
|
+
lemma: "lemmas",
|
|
211
|
+
libretto: "librettos",
|
|
212
|
+
life: "lives",
|
|
213
|
+
lingo: "lingos",
|
|
214
|
+
literature: "literature",
|
|
215
|
+
loaf: "loaves",
|
|
216
|
+
loculus: "loculi",
|
|
217
|
+
locus: "loci",
|
|
218
|
+
looey: "looies",
|
|
219
|
+
louse: "lice",
|
|
220
|
+
lumbago: "lumbagos",
|
|
221
|
+
lumen: "lumina",
|
|
222
|
+
lustrum: "lustra",
|
|
223
|
+
lymphoma: "lymphomata",
|
|
224
|
+
machinery: "machinery",
|
|
225
|
+
mackerel: "mackerel",
|
|
226
|
+
magma: "magmas",
|
|
227
|
+
mail: "mail",
|
|
228
|
+
magneto: "magnetos",
|
|
229
|
+
man: "men",
|
|
230
|
+
manga: "manga",
|
|
231
|
+
manifesto: "manifestos",
|
|
232
|
+
matrix: "matrices",
|
|
233
|
+
maximum: "maxima",
|
|
234
|
+
means: "means",
|
|
235
|
+
measles: "measles",
|
|
236
|
+
medico: "medicos",
|
|
237
|
+
medium: "media",
|
|
238
|
+
melisma: "melismas",
|
|
239
|
+
memorandum: "memoranda",
|
|
240
|
+
meniscus: "menisci",
|
|
241
|
+
mews: "mews",
|
|
242
|
+
miasma: "miasmas",
|
|
243
|
+
millennium: "millennia",
|
|
244
|
+
minimum: "minima",
|
|
245
|
+
minutia: "minutiae",
|
|
246
|
+
momentum: "momenta",
|
|
247
|
+
mongoose: "mongooses",
|
|
248
|
+
moose: "moose",
|
|
249
|
+
mud: "mud",
|
|
250
|
+
mouse: "mice",
|
|
251
|
+
mumps: "mumps",
|
|
252
|
+
music: "music",
|
|
253
|
+
murex: "murices",
|
|
254
|
+
mythos: "mythoi",
|
|
255
|
+
nebula: "nebulas",
|
|
256
|
+
nemesis: "nemeses",
|
|
257
|
+
neurosis: "neuroses",
|
|
258
|
+
news: "news",
|
|
259
|
+
nexus: "nexuses",
|
|
260
|
+
nimbus: "nimbuses",
|
|
261
|
+
noumenon: "noumena",
|
|
262
|
+
nova: "novas",
|
|
263
|
+
nucleolus: "nucleoli",
|
|
264
|
+
nucleus: "nuclei",
|
|
265
|
+
oasis: "oases",
|
|
266
|
+
occiput: "occipita",
|
|
267
|
+
octavo: "octavos",
|
|
268
|
+
octopus: "octopuses",
|
|
269
|
+
oedema: "oedemas",
|
|
270
|
+
offspring: "offspring",
|
|
271
|
+
omphalos: "omphaloi",
|
|
272
|
+
optimum: "optima",
|
|
273
|
+
opus: "opuses",
|
|
274
|
+
organon: "organons",
|
|
275
|
+
ovum: "ova",
|
|
276
|
+
ox: "oxen",
|
|
277
|
+
parabola: "parabolas",
|
|
278
|
+
paralysis: "paralyses",
|
|
279
|
+
parenthesis: "parentheses",
|
|
280
|
+
passerby: "passersby",
|
|
281
|
+
penny: "pennies",
|
|
282
|
+
personnel: "personnel",
|
|
283
|
+
perihelion: "perihelia",
|
|
284
|
+
person: "people",
|
|
285
|
+
phalanx: "phalanges",
|
|
286
|
+
phenomenon: "phenomena",
|
|
287
|
+
photo: "photos",
|
|
288
|
+
physics: "physics",
|
|
289
|
+
phylum: "phyla",
|
|
290
|
+
pike: "pike",
|
|
291
|
+
pincers: "pincers",
|
|
292
|
+
plankton: "plankton",
|
|
293
|
+
plateau: "plateaus",
|
|
294
|
+
platypus: "platypuses",
|
|
295
|
+
plexus: "plexuses",
|
|
296
|
+
pliers: "pliers",
|
|
297
|
+
police: "police",
|
|
298
|
+
policeman: "policemen",
|
|
299
|
+
politics: "politics",
|
|
300
|
+
pollution: "pollution",
|
|
301
|
+
polyhedron: "polyhedra",
|
|
302
|
+
pontifex: "pontifices",
|
|
303
|
+
potato: "potatoes",
|
|
304
|
+
premises: "premises",
|
|
305
|
+
pro: "pros",
|
|
306
|
+
proceedings: "proceedings",
|
|
307
|
+
prognosis: "prognoses",
|
|
308
|
+
prolegomenon: "prolegomena",
|
|
309
|
+
prospectus: "prospectuses",
|
|
310
|
+
quantum: "quanta",
|
|
311
|
+
quarto: "quartos",
|
|
312
|
+
quiz: "quizzes",
|
|
313
|
+
rabies: "rabies",
|
|
314
|
+
rain: "rain",
|
|
315
|
+
radius: "radii",
|
|
316
|
+
referendum: "referendums",
|
|
317
|
+
reindeer: "reindeer",
|
|
318
|
+
research: "research",
|
|
319
|
+
rhino: "rhinos",
|
|
320
|
+
rice: "rice",
|
|
321
|
+
roof: "roofs",
|
|
322
|
+
rostrum: "rostrums",
|
|
323
|
+
salmon: "salmon",
|
|
324
|
+
sarcoma: "sarcomas",
|
|
325
|
+
sarcophagus: "sarcophagi",
|
|
326
|
+
savings: "savings",
|
|
327
|
+
scarf: "scarves",
|
|
328
|
+
schema: "schemas",
|
|
329
|
+
scissors: "scissors",
|
|
330
|
+
scrotum: "scrota",
|
|
331
|
+
"sea bass": "sea bass",
|
|
332
|
+
sewage: "sewage",
|
|
333
|
+
self: "selves",
|
|
334
|
+
seminoma: "seminomas",
|
|
335
|
+
shambles: "shambles",
|
|
336
|
+
seraph: "seraphs",
|
|
337
|
+
series: "series",
|
|
338
|
+
shears: "shears",
|
|
339
|
+
sheep: "sheep",
|
|
340
|
+
shelf: "shelves",
|
|
341
|
+
shrimp: "shrimp",
|
|
342
|
+
silex: "silices",
|
|
343
|
+
simplex: "simplexes",
|
|
344
|
+
simulacrum: "simulacra",
|
|
345
|
+
software: "software",
|
|
346
|
+
sinus: "sinuses",
|
|
347
|
+
soliloquy: "soliloquies",
|
|
348
|
+
solo: "solos",
|
|
349
|
+
soma: "somas",
|
|
350
|
+
soprano: "sopranos",
|
|
351
|
+
spacecraft: "spacecraft",
|
|
352
|
+
spokesman: "spokesmen",
|
|
353
|
+
species: "species",
|
|
354
|
+
spectrum: "spectra",
|
|
355
|
+
speculum: "specula",
|
|
356
|
+
sphinx: "sphinxes",
|
|
357
|
+
squid: "squid",
|
|
358
|
+
stadium: "stadiums",
|
|
359
|
+
staff: "staffs",
|
|
360
|
+
stairs: "stairs",
|
|
361
|
+
stamen: "stamens",
|
|
362
|
+
status: "statuses",
|
|
363
|
+
stigma: "stigmas",
|
|
364
|
+
stimulus: "stimuli",
|
|
365
|
+
stoma: "stomas",
|
|
366
|
+
stratum: "strata",
|
|
367
|
+
stylus: "styluses",
|
|
368
|
+
succubus: "succubi",
|
|
369
|
+
swine: "swine",
|
|
370
|
+
syconium: "syconia",
|
|
371
|
+
syllabus: "syllabuses",
|
|
372
|
+
symposium: "symposiums",
|
|
373
|
+
synopsis: "synopses",
|
|
374
|
+
synthesis: "syntheses",
|
|
375
|
+
tennis: "tennis",
|
|
376
|
+
tableau: "tableaus",
|
|
377
|
+
tempo: "tempos",
|
|
378
|
+
thanks: "thanks",
|
|
379
|
+
testis: "testes",
|
|
380
|
+
that: "those",
|
|
381
|
+
thesis: "theses",
|
|
382
|
+
thief: "thieves",
|
|
383
|
+
this: "these",
|
|
384
|
+
thrombus: "thrombi",
|
|
385
|
+
tibia: "tibias",
|
|
386
|
+
tomato: "tomatoes",
|
|
387
|
+
tooth: "teeth",
|
|
388
|
+
torpedo: "torpedoes",
|
|
389
|
+
tornado: "tornadoes",
|
|
390
|
+
torus: "tori",
|
|
391
|
+
traffic: "traffic",
|
|
392
|
+
transportation: "transportation",
|
|
393
|
+
trapezium: "trapezia",
|
|
394
|
+
trauma: "traumas",
|
|
395
|
+
triceps: "triceps",
|
|
396
|
+
trilby: "trilbies",
|
|
397
|
+
trout: "trout",
|
|
398
|
+
tuna: "tuna",
|
|
399
|
+
ultimatum: "ultimatums",
|
|
400
|
+
umbilicus: "umbilici",
|
|
401
|
+
upstairs: "upstairs",
|
|
402
|
+
uterus: "uteruses",
|
|
403
|
+
vacuum: "vacuums",
|
|
404
|
+
velum: "vela",
|
|
405
|
+
vertebra: "vertebrae",
|
|
406
|
+
vertex: "vertices",
|
|
407
|
+
veto: "vetoes",
|
|
408
|
+
viscus: "viscera",
|
|
409
|
+
wealth: "wealth",
|
|
410
|
+
welfare: "welfare",
|
|
411
|
+
vita: "vitae",
|
|
412
|
+
volcano: "volcanoes",
|
|
413
|
+
vortex: "vortices",
|
|
414
|
+
watercraft: "watercraft",
|
|
415
|
+
wharf: "wharves",
|
|
416
|
+
whiting: "whiting",
|
|
417
|
+
wife: "wives",
|
|
418
|
+
wildebeest: "wildebeest",
|
|
419
|
+
wildlife: "wildlife",
|
|
420
|
+
wolf: "wolves",
|
|
421
|
+
woman: "women"
|
|
422
|
+
}));
|
|
423
|
+
function t(e) {
|
|
424
|
+
return (e.replace(RegExp("(?:[sxz]|ch|sh)$", "iv"), "$&e").replace(RegExp("(?<consonant>[^aeiou])y$", "iv"), "$<consonant>ie") + "s").replace(RegExp("i?e?s$", "iv"), (t) => e.slice(-1) === e.slice(-1).toLowerCase() ? t.toLowerCase() : t.toUpperCase());
|
|
425
|
+
}
|
|
426
|
+
function n(e, t) {
|
|
427
|
+
let n = e.charAt(0);
|
|
428
|
+
return n !== n.toLowerCase() && n === n.toUpperCase() && (t = n + t.slice(1)), e === e.toUpperCase() && (t = t.toUpperCase()), t;
|
|
429
|
+
}
|
|
430
|
+
function r(r, i, a) {
|
|
431
|
+
typeof i == "number" && (a = i, i = void 0);
|
|
432
|
+
let o = a ?? 1;
|
|
433
|
+
if (!i) {
|
|
434
|
+
let a = r.toLocaleLowerCase(), o = e.get(a);
|
|
435
|
+
i = o ? n(r, o) : t(r);
|
|
436
|
+
}
|
|
437
|
+
return Math.abs(o) === 1 ? r : i;
|
|
438
|
+
}
|
|
439
|
+
export { r as pluralizeWord };
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 根据数量将英语单数名词转换为复数形式。
|
|
3
|
+
* 支持不规则变化、规则变化,并保持原词的大小写格式。
|
|
4
|
+
*
|
|
5
|
+
* @param word - 需要处理的单词。
|
|
6
|
+
* @param count - 单词的数量,用于决定返回单数还是复数。
|
|
7
|
+
* @returns 根据数量返回的单数或复数形式的字符串。
|
|
8
|
+
*/
|
|
9
|
+
export declare function pluralizeWord(word: string, count: number): string;
|
|
10
|
+
/**
|
|
11
|
+
* 根据数量将英语单数名词转换为复数形式。
|
|
12
|
+
* 支持不规则变化、规则变化,并保持原词的大小写格式。
|
|
13
|
+
*
|
|
14
|
+
* @param word - 需要处理的单词。
|
|
15
|
+
* @param plural - 自定义的复数形式。
|
|
16
|
+
* @param count - 单词的数量,用于决定返回单数还是复数。
|
|
17
|
+
* @returns 根据数量返回的单数或复数形式的字符串。
|
|
18
|
+
*/
|
|
19
|
+
export declare function pluralizeWord(
|
|
20
|
+
word: string,
|
|
21
|
+
plural: string,
|
|
22
|
+
count: number,
|
|
23
|
+
): string;
|
|
24
|
+
/**
|
|
25
|
+
* pluralizeWord 函数的实现签名。
|
|
26
|
+
*
|
|
27
|
+
* @param word - 需要处理的单词。
|
|
28
|
+
* @param plural - 自定义的复数形式,或作为数量传入的数字。
|
|
29
|
+
* @param count - 单词的数量,用于决定返回单数还是复数。
|
|
30
|
+
* @returns 根据数量返回的单数或复数形式的字符串。
|
|
31
|
+
*/
|
|
32
|
+
export declare function pluralizeWord(
|
|
33
|
+
word: string,
|
|
34
|
+
plural: string | number,
|
|
35
|
+
count?: number,
|
|
36
|
+
): string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jckj/pluralizeword",
|
|
3
|
-
"
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
"publishConfig": {
|
|
4
|
+
"access": "public",
|
|
5
|
+
"registry": "https://registry.npmjs.org/"
|
|
6
|
+
},
|
|
7
|
+
"version": "1.0.1",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"exports": {
|
|
10
|
+
"types": "./index.d.ts",
|
|
11
|
+
"default": "./dist/pluralizeWord.js"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist",
|
|
15
|
+
"index.d.ts",
|
|
16
|
+
"README.md",
|
|
17
|
+
"LICENSE"
|
|
18
|
+
],
|
|
19
|
+
"module": "dist/pluralizeWord.js",
|
|
20
|
+
"types": "index.d.ts",
|
|
21
|
+
"description": "A lightweight TypeScript utility library featuring pluralize a word.",
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "https://gitee.com/hzqhxy/pluralize-word"
|
|
25
|
+
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"pluralize",
|
|
28
|
+
"word"
|
|
29
|
+
],
|
|
30
|
+
"author": {
|
|
31
|
+
"name": "hzqhxy",
|
|
32
|
+
"email": "hzqhxy@163.com"
|
|
33
|
+
},
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"typescript": "~6.0.3",
|
|
37
|
+
"vite": "^8.2.2"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"dev": "vite",
|
|
41
|
+
"build": "tsc && vite build"
|
|
42
|
+
}
|
|
6
43
|
}
|