@mercury-fw/formatter
v0.44.1
Published
Turns the lists a [Mercury](https://github.com/lucabro81/mercury-fw) plugin hands the user into text, applying rules the app writes in its own config. It holds no format of its own: without a rule, a kind of list isn't shown (the model still gets the data
Downloads
4,860
Readme
@mercury-fw/formatter
Turns the lists a Mercury plugin hands the user into text, applying rules the app writes in its own config. It holds no format of its own: without a rule, a kind of list isn't shown (the model still gets the data, and the log says which rule is missing).
import { formatterPlugin, formatter } from "@mercury-fw/formatter";
import { jiraPlugin, type JiraDisplays } from "@mercury-fw/plugin-jira";
const jiraIssueLine = (issue: JiraDisplays["issue-list"]) =>
`${issue.key} ${issue.status ? `[${issue.status}] ` : ""}${issue.summary}\n${issue.url}`;
export default defineMercuryConfig({
plugins: [
formatterPlugin(
jiraPlugin,
formatter<JiraDisplays>({
"issue-list": { item: jiraIssueLine, empty: "No matching issues." },
}),
),
],
});formatter<D>(rules)takes one rule per kind of list, keyed by the kinds the plugin declares (D, e.g.JiraDisplays), so a kind it doesn't emit or a rule for the wrong item shape fails the typecheck. A rule is the line for each item, or{ item, empty }when an empty list needs a text of its own. Items are joined with a blank line.formatterPlugin(plugin, handler)wraps a plugin so every list it hands over goes through the rules; everything else the plugin contributes passes through untouched.
MIT
