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

👯‍♀️ Improve the plural logging function #689

Merged
merged 2 commits into from
Oct 20, 2023
Merged

Conversation

rowanc1
Copy link
Member

@rowanc1 rowanc1 commented Oct 20, 2023

No description provided.

return f
.replace('%s', String(num))
.replace(/\(s\)/g, num === 1 ? '' : 's')
.replace(/\(([a-z0-9A-Z-]*)\|([a-z0-9A-Z-]*)\)/g, num === 1 ? '$1' : '$2');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can replace line 67 and 68 with this:

Suggested change
.replace(/\(([a-z0-9A-Z-]*)\|([a-z0-9A-Z-]*)\)/g, num === 1 ? '$1' : '$2');
.replace(/\((([a-z0-9A-Z-]*)\|)?([a-z0-9A-Z-]*)\)/g, num === 1 ? '$2' : '$3');

In addition to only being one regex, it handles additional cases that were not covered before, e.g. stitch(es).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Would be good to chuck some tests on this though...)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Time for some tests, yeah. :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Brought in your changes and added tests!

return f.replace('%s', String(num)).replace(/\(s\)/g, num === 1 ? '' : 's');
return f
.replace('%s', String(num))
.replace(/\(s\)/g, num === 1 ? '' : 's')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.replace(/\(s\)/g, num === 1 ? '' : 's')

@rowanc1 rowanc1 merged commit 3c5c5a6 into main Oct 20, 2023
3 checks passed
@rowanc1 rowanc1 deleted the feat/plural branch October 20, 2023 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants