From fcd35ea2e72b3268729466e4cd85b2794bb3394b Mon Sep 17 00:00:00 2001 From: Danial Raza Date: Wed, 24 Jul 2024 12:23:55 +0200 Subject: [PATCH] feat: add subtext formatter (#10400) Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> --- packages/formatters/__tests__/formatters.test.ts | 7 +++++++ packages/formatters/src/formatters.ts | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/packages/formatters/__tests__/formatters.test.ts b/packages/formatters/__tests__/formatters.test.ts index 645d9b817..32cb8b398 100644 --- a/packages/formatters/__tests__/formatters.test.ts +++ b/packages/formatters/__tests__/formatters.test.ts @@ -23,6 +23,7 @@ import { roleMention, spoiler, strikethrough, + subtext, time, TimestampStyles, underline, @@ -277,6 +278,12 @@ describe('Message formatters', () => { }); }); + describe('subtext', () => { + test('GIVEN "discord.js" THEN returns "-# discord.js"', () => { + expect<'-# discord.js'>(subtext('discord.js')).toEqual('-# discord.js'); + }); + }); + describe('time', () => { test('GIVEN no arguments THEN returns ""', () => { vitest.useFakeTimers(); diff --git a/packages/formatters/src/formatters.ts b/packages/formatters/src/formatters.ts index 37bfbaf9a..5ffa2a9e2 100644 --- a/packages/formatters/src/formatters.ts +++ b/packages/formatters/src/formatters.ts @@ -569,6 +569,16 @@ export function unorderedList(list: RecursiveArray): string { return listCallback(list); } +/** + * Formats the content into a subtext. + * + * @typeParam Content - This is inferred by the supplied content + * @param content - The content to wrap + */ +export function subtext(content: Content): `-# ${Content}` { + return `-# ${content}`; +} + /** * Formats a date into a short date-time string. *