Skip to content

Commit 33bc070

Browse files
committed
Pluralize the name when used as the group title
E.g. script -> scripts fetch -> fetches
1 parent 4d7e946 commit 33bc070

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

packages/react-devtools-shared/src/devtools/views/Components/InspectedElementSuspendedBy.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {useState, useTransition} from 'react';
1313
import Button from '../Button';
1414
import ButtonIcon from '../ButtonIcon';
1515
import KeyValue from './KeyValue';
16-
import {serializeDataForCopy} from '../utils';
16+
import {serializeDataForCopy, pluralize} from '../utils';
1717
import Store from '../../store';
1818
import styles from './InspectedElementSharedStyles.css';
1919
import {withPermissionsCheck} from 'react-devtools-shared/src/frontend/utils/withPermissionsCheck';
@@ -391,19 +391,20 @@ function SuspendedByGroup({
391391
left = 95;
392392
}
393393
}
394+
const pluralizedName = pluralize(name);
394395
return (
395396
<div className={styles.CollapsableRow}>
396397
<Button
397398
className={styles.CollapsableHeader}
398399
onClick={() => {
399400
setIsOpen(prevIsOpen => !prevIsOpen);
400401
}}
401-
title={name}>
402+
title={pluralizedName}>
402403
<ButtonIcon
403404
className={styles.CollapsableHeaderIcon}
404405
type={isOpen ? 'expanded' : 'collapsed'}
405406
/>
406-
<span className={styles.CollapsableHeaderTitle}>{name}</span>
407+
<span className={styles.CollapsableHeaderTitle}>{pluralizedName}</span>
407408
<div className={styles.CollapsableHeaderFiller} />
408409
{isOpen ? null : (
409410
<div className={styles.TimeBarContainer}>

packages/react-devtools-shared/src/devtools/views/utils.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,3 +198,39 @@ export function truncateText(text: string, maxLength: number): string {
198198
return text;
199199
}
200200
}
201+
202+
export function pluralize(word: string): string {
203+
if (!/^[a-z]+$/i.test(word)) {
204+
// If it's not a single a-z word, give up.
205+
return word;
206+
}
207+
208+
switch (word) {
209+
case 'man':
210+
return 'men';
211+
case 'woman':
212+
return 'women';
213+
case 'child':
214+
return 'children';
215+
case 'foot':
216+
return 'feet';
217+
case 'tooth':
218+
return 'teeth';
219+
case 'mouse':
220+
return 'mice';
221+
case 'person':
222+
return 'people';
223+
}
224+
225+
// Words ending in s, x, z, ch, sh → add "es"
226+
if (/(s|x|z|ch|sh)$/i.test(word)) return word + 'es';
227+
228+
// Words ending in consonant + y → replace y with "ies"
229+
if (/[bcdfghjklmnpqrstvwxz]y$/i.test(word)) return word.slice(0, -1) + 'ies';
230+
231+
// Words ending in f or fe → replace with "ves"
232+
if (/(?:f|fe)$/i.test(word)) return word.replace(/(?:f|fe)$/i, 'ves');
233+
234+
// Default: just add "s"
235+
return word + 's';
236+
}

0 commit comments

Comments
 (0)