npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dekita-md-embed

v1.1.11

Published

Converts MD files into discord js embeds!

Downloads

7

Readme

What is EmbedMD?

EmbedMD, or dekita-md-embed is a simple module written by DekitaRPG that allows you to load a markdown file, or directory of, and then convert the file(s) into discord.js embed objects! You can then send those embeds in discord.js like you normally would!!

Please note: discord.js is REQUIRED for this module to function.

License TLDR

Copyright (c) 2021 Dekita ([email protected]) [view license]

Documentation

https://dekita.github.io/md-embed/

System Requirements

node.js | discord.js

Author Information

email | website | twitter | github

How To Use This Module In Your Own Projects:

Assuming you already have a node.js project that uses discord.js, getting setup with this module is incredibly straighforward! Just follow the examples below to get you started.

Install EmbedMD

npm i dekita-md-embed

Require EmbedMD

const EmbedMD = require('dekita-md-embed');

Create Markdown Files

Once you have installed EmbedMD, create a file and save it as filename.md. Use the format detailed below for the file contents, and then it can be used as a template for creating discord.js embeds.

# URL #
{creator.url}

# TITLE #
title text... 

# COLOR #
RANDOM

# AUTHOR #
{user.name} :: {user.avatar} :: {creator.url}

# THUMBNAIL #
{bot.avatar}

# DESCRIPTION #
description text...

# FOOTER #
{user.name} :: {user.avatar}

# FIELD #
label :: string :: true

# FIELDS #
label :: string :: true

# TIMESTAMP #
false

NOTE1: If using a hex color code within the COLOR field, remove the # or you will get errors! NOTE2: FIELD, FIELDS, AUTHOR, and FOOTER elements exprect multiple properties. These should be delimited using a double : character (::)! If you dont want to delimit with :: then you can set a custom delimiter by setting the EmbedMD.delimiter. For example, to use -;

EmbedMD.delimiter = '-';

Load A File Then Create Embed

const embed_md = EmbedMD.prepareMD('/directory/path.md'); // cache embed files from path
const embed = EmbedMD.getEmbed(embed_md); // get embed using embed_md

Load All Files From Directory Then Create Embed

const embed_mds = EmbedMD.parseDir('/directory/path'); // cache embed files from path
const embed_ids = Object.keys(embed_mds); // array of filenames without.md and route
const embed = EmbedMD.getEmbed(embed_mds.embed_id); // get embed using embed_id

Send Embed With discord.js

// in some discord js command interaction:
await interaction.reply({embeds: [embed]});

Formatting Embed Templates

Its entirely possible to have the embed parse information based on additional properties. For example, you might want to display user information or some data from a variable within your embed. Simply pass an object as the second argument to getEmbed with the properties that you want to replace within your .md file. For example, lets assume the following files:

file.md:

# FOOTER #
{user.name} :: {user.avatar}

file.js:

const embed_md = EmbedMD.prepareMD('./file.md');
const embed = EmbedMD.getEmbed(embed_md, {
    '{user.avatar}': interaction.user.displayAvatarURL(),
    '{user.name}': interaction.user.username,
    '{creator.url}': "https://dekitarpg.com",
}); 

With these files in place, an embed with only footer information will be created, and will use the interaction user information for the footer content when being initialized.

Global Replacers

You can define replacer key:value's globally by using the setGlobalReplacer function. All future embedds created will use then these replacers. NOTE: If you define a global replacer, and then supply a duplicate replacer for any embed template, the global replacer will be ignored. Use unsetGlobalReplacer if you need to later remove global replacer key:values.

EmbedMD.setGlobalReplacer('{bot.name}', client.user.username);
EmbedMD.setGlobalReplacer('{bot.color}', CONFIG.embed_color.replace('#',''));
EmbedMD.setGlobalReplacer('{bot.avatar}', client.user.displayAvatarURL());

Additional

You can also utilize the included helper functions for anything you might find useful. They are pretty handy!

EmbedMD.format("Hi name!", {name: 'DekiaRPG'});
// => "Hi DekitaRPG!"

EmbedMD.parseArray(['1', '5', 'false', 'some description']);
// => [1, 5, false, 'some description']

Actual Real Life Reviews

Tbh this is the most useful/creative/good-idea lib i've seen around here in a long time - Tim