-
-
Notifications
You must be signed in to change notification settings - Fork 864
Convert punctuateSeries to TypeScript #4351
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
base: 2.x
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import type { Children } from 'mithril'; | ||
| import app from '../../common/app'; | ||
|
|
||
| /** | ||
| * Formats a list of strings/nodes to read fluently in the locale. | ||
| */ | ||
| export default function punctuateSeries(items: Children[] = []): Children { | ||
|
Member
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. The export default function punctuateSeries(items: Children[]): Children {
Member
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. The function-level JSDoc describing the purpose and example has been removed. Since /**
* The `punctuateSeries` helper formats a list of strings (e.g. names) to read
* fluently in the application's locale.
*
* ```js
* punctuateSeries(['Toby', 'Franz', 'Dominion']) // Toby, Franz, and Dominion
* ```
*/ |
||
| if (items.length === 2) { | ||
| return app.translator.trans('core.lib.series.two_text', { | ||
| first: items[0], | ||
| second: items[1], | ||
| }); | ||
| } | ||
|
|
||
| if (items.length >= 3) { | ||
| const glue = app.translator.trans('core.lib.series.glue_text') as Children; | ||
|
|
||
|
Member
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.
The simplest correct approach is to type const glue = app.translator.trans('core.lib.series.glue_text') as any[];Or, since the translator returns the rendered translation here, you can just use
Member
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.
The simplest correct approach is to type const glue = app.translator.trans('core.lib.series.glue_text') as any[];Or keep |
||
| // Build middle items safely: [item, glue, item, glue, ...] | ||
| const second: Children[] = []; | ||
| for (let i = 1; i < items.length - 1; i++) { | ||
| second.push(items[i]); | ||
| if (i < items.length - 2) second.push(glue); | ||
| } | ||
|
|
||
| return app.translator.trans('core.lib.series.three_text', { | ||
| first: items[0], | ||
| second, | ||
| third: items[items.length - 1], | ||
| }); | ||
| } | ||
|
|
||
| // 0 or 1 item: return as-is (Mithril can render arrays too) | ||
| return items; | ||
| } | ||
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.
The function-level JSDoc describing the purpose and example has been removed. Since
dist-typingsis generated from this file, that documentation will be lost for extension authors browsing the.d.tsdeclarations. Restore the description and@examplefrom the original.jsfile: