Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/singular strings #358

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions src/utils/strings.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
// eslint-disable-next-line import/prefer-default-export
export const singularise = (str: string) => {
const lastTwoChars = str.slice(-2);
return lastTwoChars === 'es' ? `${str.slice(0, -2)}y` : str.slice(0, -1);
// Non-exhaustive singulariser, only handles some common English cases so use with care / add more rules.
// Consider adding a string store if really needed.
if (str.endsWith('ies')) {
// e.g. assemblies, but will fail on species
return `${str.slice(0, -3)}y`;
}
if (str.endsWith('ses')) {
// e.g. analyses, but will fail on busses
return `${str.slice(0, -3)}sis`;
}
if (str.endsWith('s')) {
// e.g. projects, but will fail on boxes
return `${str.slice(0, -1)}`;
}
if (str.endsWith('a')) {
// e.g. data, but will fail on criteria
return `${str.slice(0, -1)}um`;
}
return str;
};
Loading