-
Notifications
You must be signed in to change notification settings - Fork 81
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'myst-cli-utils': patch | ||
'myst-cli': patch | ||
--- | ||
|
||
Improve plural function to add `y|ies` endings for words. |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -51,6 +51,8 @@ export function tic() { | |||||
* | ||||||
* `plural('%s book(s)', books)` | ||||||
* | ||||||
* `plural('%s dependenc(y|ies)', deps)` | ||||||
* | ||||||
* If passed an object as the second argument, the number of keys will be used. | ||||||
*/ | ||||||
export function plural(f: string, count?: number | any[] | Record<any, any>): string { | ||||||
|
@@ -60,5 +62,8 @@ export function plural(f: string, count?: number | any[] | Record<any, any>): st | |||||
: Array.isArray(count) | ||||||
? count?.length | ||||||
: Object.keys(count ?? {}).length) ?? 0; | ||||||
return f.replace('%s', String(num)).replace(/\(s\)/g, num === 1 ? '' : 's'); | ||||||
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'); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can replace line 67 and 68 with this:
Suggested change
In addition to only being one regex, it handles additional cases that were not covered before, e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Would be good to chuck some tests on this though...) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Time for some tests, yeah. :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Brought in your changes and added tests! |
||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.