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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@teever/ez-hook

v0.3.6

Published

A simple way to send webhooks to discord with zero dependencies

Readme

Zero dependency, TypeScript/JavaScript library for sending Discord webhooks. Useful for edge runtimes, Cloudflare Workers, Vercel, Deno, etc. Create embeds using builder methods with flexible parameter options - pass objects or individual values for customization.

Built-in Input Validation Errors

The hook throws validation errors in the following cases:

  • Size Constraints:

    • Content exceeds maximum allowed length
    • Content is shorter than minimum required length
    • Field size is larger than permitted limit
    • Field size is smaller than required minimum
  • Invalid Content:

    • Content format doesn't match required pattern
    • Content contains invalid characters
    • Content structure violates specified rules

These validations comply with Discord's limits.

Discord Webhook Limits

  • Content Limits:

    • Message content: 2000 characters
    • Embed title: 256 characters
    • Embed description: 4096 characters
    • Embed fields: Up to 25 fields
    • Embed field name: 256 characters
    • Embed field value: 1024 characters
    • Embed footer text: 2048 characters
    • Embed author name: 256 characters
    • Total embeds per message: 10
    • Total character limit across all embeds: 6000 characters
  • Media Limits:

    • Image URLs: 2048 characters
    • Thumbnail URLs: 2048 characters
    • Author icon URLs: 2048 characters
    • Footer icon URLs: 2048 characters
  • Rate Limits:

    • Default rate limit: 30 requests per minute per webhook
    • Responses include retry-after header when rate limited

These limits are enforced by Discord's API and this library validates inputs against these limits to prevent API errors.

Install

Install from npm:

  • npm install @teever/ez-hook
  • pnpm add @teever/ez-hook
  • yarn add @teever/ez-hook
  • bun add @teever/ez-hook

Install from JSR:

  • deno add @teever/ez-hook
  • npx jsr add @teever/ez-hook
  • yarn dlx jsr add @teever/ez-hook
  • pnpm dlx jsr add @teever/ez-hook
  • bunx jsr add @teever/ez-hook

Features

  • Zero dependencies
  • TypeScript support
  • Automatic retry on rate limits and server errors
  • Configurable retry behavior
  • Fluent builder API
  • Overloaded methods for simpler usage
  • Structured responses with status/retry metadata

Response shape

send, modify, and get return a RequestResult object:

  • ok: boolean success indicator
  • status: HTTP status code (0 on network failure)
  • retryAfter: milliseconds until retry if provided by Discord
  • bodyText: raw response text, when present
  • error: message for non-OK responses

Input validation errors throw ValidationError with the field path and limit details.

Request options

You can pass a second parameter with signal, custom headers, and timeoutMs:

const controller = new AbortController()
const res = await hook.send({
  headers: { 'X-Custom-Header': 'value' },
  signal: controller.signal,
  timeoutMs: 5000
})

Example

Basic Use

import { Webhook } from '@teever/ez-hook'

// Optional retry configuration 
const retryConfig = {
  maxRetries: 3,      // Maximum number of retries
  baseDelay: 1000,    // Base delay in ms (1 second)
  maxDelay: 60000     // Maximum delay in ms (60 seconds)
} // Also the default configuration

const hook = new Webhook('https://discord.com/api/webhooks/1234567890/abcdefghijklmnopqrstuvwxyz', retryConfig)

hook
  .setUsername('Username')
  .setContent('Lorem ipsum dolor sit amet, consectetur adipiscing elit.')

const result = await hook.send()

if (!result.ok) {
  console.error('Webhook failed', result)
}

Custom Embeds (Rich Message)

import { Embed, Webhook } from '@teever/ez-hook'

const hook = new Webhook('https://discord.com/api/webhooks/1234567890/abcdefghijklmnopqrstuvwxyz')

const embed = new Embed()
embed
  .setTitle('Embed Title')
  .setDescription('Embed Description')
  // Use hex string or number for color
  .setColor('#ffffff')  // (Note: must be prefixed with #)
  // Example number for color
  .setColor(12345)
  // Simple method overload
  .setThumbnail('https://example.com/image.png')  
  // Or use full object
  .setThumbnail({
    url: 'https://example.com/image.png',
    height: 100,
    width: 100
  })
  // Simple author setting
  .setAuthor('Author Name', 'https://discord.com', 'https://example.com/icon.png')
  // Or use full object
  .setAuthor({
    name: 'Author Name',
    icon_url: 'https://example.com/icon.png',
    url: 'https://discord.com'
  })
  // Simple footer setting
  .setFooter('Footer Text', 'https://example.com/icon.png')
  // Or use full object
  .setFooter({
    text: 'Footer Text',
    icon_url: 'https://example.com/icon.png'
  })
  .setTimestamp()
  // Simple field adding
  .addField('Field 1', 'Value 1', true)
  // Or use full object
  .addField({
    name: 'Field 2',
    value: 'Value 2',
    inline: true
  })

const res = await hook.addEmbed(embed).send()

if (!res.ok) {
  console.error('Webhook failed', res)
}

Error Handling

EZ-Hook provides typed error classes for precise error handling:

import {
  Webhook,
  ValidationError,
  RateLimitError,
  WebhookError,
  WebhookNotFoundError
} from '@teever/ez-hook'

const hook = new Webhook('https://discord.com/api/webhooks/...')

try {
  hook.setContent('Hello!')
  await hook.send()
} catch (error) {
  if (error instanceof ValidationError) {
    console.error(`Validation failed: ${error.field}`)
    console.error(`Max: ${error.maxLength}, Actual: ${error.actualLength}`)
  } else if (error instanceof RateLimitError) {
    console.error(`Rate limited! Retry after ${error.retryAfter}ms`)
  } else if (error instanceof WebhookNotFoundError) {
    console.error('Webhook URL is invalid or deleted')
  } else if (error instanceof WebhookError) {
    console.error(`HTTP error ${error.statusCode}: ${error.message}`)
  }
}

Examples

See the examples directory for more usage patterns: