Skip to content

Commit

Permalink
feat(Formatters): Add a spoiler function (discordjs#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
austr1an authored Jul 28, 2021
1 parent f83fe99 commit c213a6a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/messages/formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,15 @@ export function hyperlink(content: string, url: string | URL, title?: string) {
return title ? `[${content}](${url} "${title}")` : `[${content}](${url})`;
}

/**
* Wraps the content inside spoiler (hidden text).
* @param content The content to wrap.
* @returns The formatted content.
*/
export function spoiler<C extends string>(content: C): `||${C}||` {
return `||${content}||`;
}

/**
* Formats the user ID into a user mention.
* @param userId The user ID to format.
Expand Down
7 changes: 7 additions & 0 deletions tests/messages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
Faces,
hideLinkEmbed,
hyperlink,
spoiler,
inlineCode,
italic,
memberNicknameMention,
Expand Down Expand Up @@ -106,6 +107,12 @@ describe('Messages', () => {
).toBe('[discord.js](https://discord.js.org/ "Official Documentation")');
});
});

describe('spoiler', () => {
test('GIVEN "discord.js" THEN returns "||discord.js||"', () => {
expect<'||discord.js||'>(spoiler('discord.js')).toBe('||discord.js||');
});
});

describe('Mentions', () => {
describe('userMention', () => {
Expand Down

0 comments on commit c213a6a

Please sign in to comment.