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

@jadl/builders

v0.1.3

Published

Builders for JaDL

Downloads

26

Readme

@jadl/builders

Builders library for JaDL

Base Builders

Embed

Embed allows the creation of a normal Discord embed object through a builder

Create an embed

import { Embed } from '@jadl/builders'

const embed = new Embed()
  .title('Hello world!')
  .description('I am here')
  .footer('Woah')

You can then render the embed to a Discord API embed object

embed.render() // APIEmbed

FileBuilder

FileBuilder allows the appension of files to a MessageBuilder or through the parser

import { FileBuilder } from '@jadl/builders'

const attachments = new FileBuilder()
  .add('hello.txt', Buffer.from('Hi'))
  .add('image.png', imageBuffer)

You can then render the FIleBuilder as a form-data object ready to be sent to Discord or through parser

attachments.toFormData()

MessageBuilder

MessageBuilder allows the appension of the builders and other useful objects to be sent through the parser

import { MessageBuilder } from '@jadl/builders'

const message = new MessageBuilder({ content: 'Hello world' })
  .addEmbed(embed)
  .addFiles(attachments)
  .addComponentRow({
    type: ComponentType.Button,
    custom_id: 'Hello',
    style: ButtonStyle.Primary,
    label: 'Hello World'
  })

You can then render these MessageBuilder's into form-data or a JSON body filled with the data added

message.render() // form-data or JSON body

Parser

parse(input)

parse() turns any readable type & the builders in this package into a valid @discordjs/rest RequestData object to be passed directly to the request. It uses the parseMessage() method (below) to create the type, but then adds all of the extra properties and headers necesarry for the request.

worker // instantiated worker with @discordjs/rest REST on .api

import { parse, MessageTypes } from '@jadl/builders'

function sendMessage (channelId: string, input: MessageTypes) {
  worker.api.post(`/channels/${channelId}/messages`, parse(input))
}
// example list of what you can pass into parse below

parseMessage()

parseMessage() turns any readable type & the builders in this package into a valid message JSON or form-data. It can take many types like strings, our builders like Embeds and FileBuilders, and of course MessageBuilders, and tries it's best to configure it into a message ready to be sent

:warning: It is recommended to use parse() as not doing so might lack the necesarry headers and configuration to send it as an actual message

import { parseMessage } from '@jadl/builders'

// works on stringified types such as strings, bigints, numbers & symbols
parseMessage('hello world') => { content: 'hello world' }

// works on our builders
parseMessage(
  new Embed()
    .title('hello world')
) => { embeds: [ { title: 'hello world' } ] }
// anything with files involved will return a form-data
parseMessage(
  new FileBuilder()
    .add('hello.txt', Buffer.from('hi'))
) => FormData<[ ['hello.txt', Buffer<68 69>] ]>

// and of course, on MessageBuilders
parseMessage(
  new MessageBuilder({ content: 'hello' })
    .addEmbeds(
      new Embed()
        .title('goodbye')
    )
    .addComponentRow({
      ...
    })
) => { content: 'hello', embeds: [ { title: 'goobye' }], components: [ ... ] }

// as afforementied, when a file is involed MessageBuilders will also turn into form-data
parseMessage(
  new MessageBuilder({ content: 'hi' })
    .addFiles(
      new FileBuilder()
        .add('hi.txt', Buffer.from('hi'))
    )
) => FormData<[ ['hi.txt', Buffer<68 69>], [ 'payload_json', '{"content": "hi"}' ] ]>
                                           // json payloads are attached correctly for Discord uploading