0.0.5 • Published 2 years ago

@jadl/embed v0.0.5

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

JaDL Embed

Simple and easy to use embed renderer

const embed = new Embed()
  .title('Hello world!')

To get the raw API embed object you do embed.render()

Custom sendback

Which this embed, you can create sendbacks that allow you to use nested .send() methods

For example

const embed = new Embed((embed) => {
  // embed being the created embed object

  console.log(embed.render())
})

embed
  .title('Hello!')
  .send() // this will run back the sendback passed in the constructor
  // => logs { title: 'Hello!' }

This is super useful for creating nested library functions e.g, how we do it in JADL is a .embed method that returns a new embed, and handles the .send() seamlessly to it's context

In TS

You can also create custom return types and paramater names like so:

const embed = new Embed<
  Promise<APIMessage>, // sets the return type of .send
  [ // options
    reply?: boolean,
    mention?: boolean
    // etc
  ]
>((embed, options) => {
  // options will now be typed as [boolean?, boolean?]

  return API.sendMessage(embed.render()) // return your Promise<APIMessage>
})

embed
  .title('Hello!')
  .send(true, true) // this will be typed as your options
  // the return type of this is Promise<APIMessage>
0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago