1.0.0 • Published 5 years ago
discord-markup v1.0.0
Installation
npm: npm i discord-markup
Usage
Constructor:
const Text = require("discord-markup");
new Text("your text here");
Methods
- Text#bold|underline|italic|strikethrough|spoiler
Wraps a given chunk of the text in the respective method's markdown style:
- bold -
**
- underline -
__
- italic -
*
- strikethrough -
~~
- spoiler -
||
Arguments/usage: Text#bold|underline|italic|strikethrough|spoiler(nothing|startIndex|string|RegExp, nothing|endIndex);
const Text = require("discord-markup");
const myText = new Text("Hello! This is going to be in italic. And this is going to be striked through. ||Shh, I'm a spoiler!|| I'm underline.");
// make the whole text bold:
myText.bold();
// parse a part of the string out using Regular Expressions:
myText.italic(/This is going to be in italic./);
// replace a given part of the string:
myText.strikethrough("And this is going to be striked through.");
// parse out a numeric range in the a string:
myText.underline(myText.length - "I'm underline".length, myText.length);
// you can chain methods too:
myText
.bold(...)
.italic(...)
.underline(...)
// you can call toString on a Text instance to get the string:
message.channel.send(String(myText)); // discord.js example
- Text#codeblock
Arguments/usage: Text#codeblock(language: string, inline: boolean, nothing|startIndex|string|RegExp, nothing|endIndex);
const Text = require("discord-markup");
const myText = new Text("I'm an inline codeblock.\nI am not!");
// the last 2 arguments are the same as for the above methods and have the same usage.
// make an inline JavaScript codeblock using string parsing:
myText.codeblock("js", true, "I'm an inline codeblock.");
// make a block JavaScript codeblock using Regular Expressions:
myText.codeblock("js", false, /I am not!/);
// you can chain it with methods too:
myText
.codeblock(...)
.bold(...)
.italic(...)
.underline(...)
// you can call toString on a Text instance to get the string:
message.channel.send(String(myText)); // discord.js example
- Text#replaceMention
Arguments/usage: Text#replaceMention(id: string, usernameOrClient: string|Client, prop: string, includeAt: boolean);
This method returns a Promise!
const Text = require("discord-markup");
const myText = new Text("Welcome to the server, <@576083686055739394>! Be sure to check the rules.");
// discord.js client example
const { Client } = require("discord.js");
const client = new Client();
myText.replaceMention("576083686055739394", client, "tag"); // replaces <@576083686055739394> with "@1s3k3b#5794"
// given username/tag example
myText.replaceMention("576083686055739394", "1s3k3b", null, "false"); // replaces <@576083686055739394> with "1s3k3b"
// you can't chain it with methods, you must resolve the returned promise:
myText.replaceMention(...).then(text =>
text
.bold(...)
.italic(...)
.underline(...)
);
// you can call toString on a Text instance to get the string:
message.channel.send(String(myText)); // discord.js example
- Text#replaceMentions
Arguments/usage: Text#replaceMentions(client: Client, prop: string, includeAt: boolean);
const Text = require("discord-markup");
const { Client } = require("discord.js");
const client = new Client();
const myText = new Text("Welcome to the server, <@576083686055739394>! Be sure to check the rules. DM <@12345678912345678> for help!");
myText.replaceMentions(client, "tag");
// "Welcome to the server, @1s3k3b#5794! Be sure to check the rules. DM @ServerOwner#1234 for help!"
// you can chain it with methods too:
myText
.replaceMentions(...)
.bold(...)
.italic(...)
.underline(...)
// you can call toString on a Text instance to get the string:
message.channel.send(String(myText)); // discord.js example
1.0.0
5 years ago