Skip to content
Open
Show file tree
Hide file tree
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
37 changes: 0 additions & 37 deletions framework/core/js/src/common/helpers/punctuateSeries.js

This file was deleted.

34 changes: 34 additions & 0 deletions framework/core/js/src/common/helpers/punctuateSeries.ts
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 {
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;

// 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;
}
Loading