Formatters
@lunibee/formatters provides pure functions for generating Discord-flavoured markdown strings, mention formats, and timestamp displays.
Import
Section titled “Import”import { bold, italic, underline, strikethrough, spoiler, inlineCode, codeBlock, blockQuote, heading, subtext, link, masked, orderedList, bulletList, escapeMarkdown, userMention, channelMention, roleMention, timestamp,} from "lunibee";// or directly:import { bold } from "@lunibee/formatters";import { bold, italic, underline, strikethrough, spoiler, inlineCode, codeBlock, blockQuote, heading, subtext, link, masked, orderedList, bulletList, escapeMarkdown, userMention, channelMention, roleMention, timestamp,} from "lunibee";// or directly:import { bold } from "@lunibee/formatters";Text Formatting
Section titled “Text Formatting”bold(text)
Section titled “bold(text)”Wraps text in **...**.
bold("Hello, World!") // → "**Hello, World!**"bold("Hello, World!") // → "**Hello, World!**"italic(text)
Section titled “italic(text)”Wraps text in _..._.
italic("Important note") // → "_Important note_"italic("Important note") // → "_Important note_"underline(text)
Section titled “underline(text)”Wraps text in __...__.
underline("Underlined") // → "__Underlined__"underline("Underlined") // → "__Underlined__"strikethrough(text)
Section titled “strikethrough(text)”Wraps text in ~~...~~.
strikethrough("Deleted") // → "~~Deleted~~"strikethrough("Deleted") // → "~~Deleted~~"spoiler(text)
Section titled “spoiler(text)”Wraps text in ||...||.
spoiler("Secret content") // → "||Secret content||"spoiler("Secret content") // → "||Secret content||"inlineCode(text)
Section titled “inlineCode(text)”Wraps text in backticks.
inlineCode("process.env.TOKEN") // → "`process.env.TOKEN`"inlineCode("process.env.TOKEN") // → "`process.env.TOKEN`"codeBlock(text, language?)
Section titled “codeBlock(text, language?)”Wraps text in a fenced code block.
codeBlock("const x = 1;", "ts") // → "```ts\nconst x = 1;\n```"codeBlock("plain text") // → "```\nplain text\n```"codeBlock("const x = 1;", "ts") // → "```ts\nconst x = 1;\n```"codeBlock("plain text") // → "```\nplain text\n```"blockQuote(text)
Section titled “blockQuote(text)”Prefixes each line with > .
blockQuote("This is quoted.") // → "> This is quoted."blockQuote("This is quoted.") // → "> This is quoted."heading(text, level?)
Section titled “heading(text, level?)”Creates a markdown heading (level 1–3, default 1).
heading("Server Status", 2) // → "## Server Status"heading("Server Status", 2) // → "## Server Status"subtext(text)
Section titled “subtext(text)”Creates Discord-style subtext (wraps in -# ...).
subtext("Last updated 3 hours ago") // → "-# Last updated 3 hours ago"subtext("Last updated 3 hours ago") // → "-# Last updated 3 hours ago"masked(text)
Section titled “masked(text)”Masks text using the backtick escape for display without markdown parsing.
escapeMarkdown(value)
Section titled “escapeMarkdown(value)”Escapes all Discord markdown special characters in a string. Useful for displaying user-supplied content.
escapeMarkdown("**Bold** and ~~strikethrough~~")// → "\\*\\*Bold\\*\\* and \\~\\~strikethrough\\~\\~"escapeMarkdown("**Bold** and ~~strikethrough~~")// → "\\*\\*Bold\\*\\* and \\~\\~strikethrough\\~\\~"orderedList(...items)
Section titled “orderedList(...items)”Creates a numbered list.
orderedList("First item", "Second item", "Third item")// → "1. First item\n2. Second item\n3. Third item"orderedList("First item", "Second item", "Third item")// → "1. First item\n2. Second item\n3. Third item"bulletList(...items)
Section titled “bulletList(...items)”Creates a bulleted list.
bulletList("Apples", "Oranges", "Bananas")// → "- Apples\n- Oranges\n- Bananas"bulletList("Apples", "Oranges", "Bananas")// → "- Apples\n- Oranges\n- Bananas"link(label, url, title?)
Section titled “link(label, url, title?)”Creates a Markdown hyperlink.
link("Lunibee Docs", "https://lunibee.js.org")// → "[Lunibee Docs](https://lunibee.js.org)"
link("Hover me", "https://lunibee.js.org", "Official documentation")// → "[Hover me](https://lunibee.js.org 'Official documentation')"link("Lunibee Docs", "https://lunibee.js.org")// → "[Lunibee Docs](https://lunibee.js.org)"
link("Hover me", "https://lunibee.js.org", "Official documentation")// → "[Hover me](https://lunibee.js.org 'Official documentation')"Mentions
Section titled “Mentions”userMention(id)
Section titled “userMention(id)”Creates a <@userId> mention string.
userMention("123456789") // → "<@123456789>"userMention("123456789") // → "<@123456789>"channelMention(id)
Section titled “channelMention(id)”Creates a <#channelId> mention string.
channelMention("987654321") // → "<#987654321>"channelMention("987654321") // → "<#987654321>"roleMention(id)
Section titled “roleMention(id)”Creates a <@&roleId> mention string.
roleMention("111222333") // → "<@&111222333>"roleMention("111222333") // → "<@&111222333>"Timestamps
Section titled “Timestamps”timestamp(dateOrMs, style?)
Section titled “timestamp(dateOrMs, style?)”Creates a Discord timestamp that renders dynamically in each user’s local timezone.
timestamp(Date.now()) // → "<t:1700000000>"timestamp(new Date(), "R") // → "<t:1700000000:R>"timestamp(1700000000, "F") // → "<t:1700000000:F>"timestamp(Date.now()) // → "<t:1700000000>"timestamp(new Date(), "R") // → "<t:1700000000:R>"timestamp(1700000000, "F") // → "<t:1700000000:F>"| Style | Example output |
|---|---|
"t" |
9:30 PM |
"T" |
9:30:00 PM |
"d" |
11/14/2023 |
"D" |
November 14, 2023 |
"f" |
November 14, 2023 9:30 PM |
"F" |
Tuesday, November 14, 2023 9:30 PM |
"R" |
2 hours ago (relative) |
Example
Section titled “Example”import { bold, italic, codeBlock, timestamp, userMention, bulletList } from "lunibee";
await channel.send({ content: [ `${bold("Welcome")} to the server, ${userMention(userId)}!`, italic("Please read the rules before chatting."), "", `You joined: ${timestamp(joinedAt, "R")}`, "", bold("Quick links:"), bulletList("#rules", "#announcements", "#general"), ].join("\n"),});import { bold, italic, codeBlock, timestamp, userMention, bulletList } from "lunibee";
await channel.send({ content: [ `${bold("Welcome")} to the server, ${userMention(userId)}!`, italic("Please read the rules before chatting."), "", `You joined: ${timestamp(joinedAt, "R")}`, "", bold("Quick links:"), bulletList("#rules", "#announcements", "#general"), ].join("\n"),});