Created
March 20, 2023 18:28
-
-
Save therealbenpai/1f95f4237982e182f60e05b918dd43b9 to your computer and use it in GitHub Desktop.
Reddit Text Formatter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TextFormatter { | |
static bold = (text) => `**${text}**`; | |
static italic = (text) => `*${text}*`; | |
static strikethrough = (text) => `~~${text}~~`; | |
static spoiler = (text) => `>!${text}!<`; | |
static code = (text) => `\`${text}\``; | |
static codeBlock = (text) => text.split('\n').unshift('').push('').map(line => ` ${line}`).join('\n'); | |
static quote = (text) => `> ${text}`; | |
static quoteBlock = (text) => `>>> ${text}`; | |
static link = (text, url) => `[${text}](${url})`; | |
static list = (...items) => (items.map((item, index) => `${index + 1}) ${item}`)).join('\n'); | |
} | |
export default TextFormatter |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment