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

@disckit/common

v1.3.0

Published

Foundation utilities for Discord bots and dashboards. String, time, array, async and random helpers.

Readme


Features

  • StringUtils — links, invites, hex colors, snowflakes, mentions, truncate, escape markdown, code blocks
  • TimeUtils — format durations, Discord timestamps, parse HH:MM:SS, remaining time, uptime
  • ArrayUtils — chunk, deduplicate, shuffle, flatten, partition
  • RandomUtils — integers, floats, probability, array picks
  • AsyncUtils — sleep, retry with backoff, timeout, batch processing
  • DISCORD — all Discord API limits (embeds, modals, select menus, Components V2, guild)
  • TIME — time constants in milliseconds
  • Full TypeScript types included · Zero dependencies · Node.js 18+

Installation

npm install @disckit/common
yarn add @disckit/common
pnpm add @disckit/common

TypeScript / ESM

Types are bundled — no extra install needed.
Supports both CommonJS and ESM:

// ESM (Vite, bundlers, Node --input-type=module)
import { StringUtils, TimeUtils, formatTime, isSnowflake } from '@disckit/common';

// CommonJS (Node.js bots)
const { StringUtils, TimeUtils, formatTime, isSnowflake } = require('@disckit/common');

Usage

String utilities

const { StringUtils } = require('@disckit/common');

StringUtils.containsLink('Visit https://example.com');   // → true
StringUtils.containsDiscordInvite('discord.gg/abc');     // → true
StringUtils.isHexColor('#5865F2');                        // → true
StringUtils.isSnowflake('123456789012345678');            // → true
StringUtils.truncate('Hello, World!', 8);                 // → "Hello..."
StringUtils.capitalize('hello world');                    // → "Hello world"
StringUtils.isBlank('   ');                               // → true
StringUtils.escapeMarkdown('**bold**');                   // → "\\*\\*bold\\*\\*"
StringUtils.codeBlock('const x = 1', 'js');              // → "```js\nconst x = 1\n```"

Mentions

const { mentionUser, mentionRole, mentionChannel } = require('@disckit/common');

mentionUser('123456789012345678');    // → "<@123456789012345678>"
mentionRole('987654321098765432');    // → "<@&987654321098765432>"
mentionChannel('111222333444555666'); // → "<#111222333444555666>"

Time utilities

const { TimeUtils, toDiscordTimestamp } = require('@disckit/common');

TimeUtils.formatTime(3661);          // → "1 hora, 1 minuto, 1 segundo"
TimeUtils.formatTimeShort(3661);     // → "1h 1m 1s"
TimeUtils.durationToMillis('1:30'); // → 90000
TimeUtils.formatUptime(3_600_000);  // → "1 hora"

// Discord timestamp tags — renders natively in Discord
toDiscordTimestamp(new Date(), 'R'); // → "<t:1711234567:R>"  (e.g. "3 minutes ago")
toDiscordTimestamp(new Date(), 'D'); // → "<t:1711234567:D>"  (e.g. "March 21, 2026")
toDiscordTimestamp(new Date(), 'F'); // → "<t:1711234567:F>"  (full date + time)
// Formats: t T d D f F R

Array utilities

const { ArrayUtils } = require('@disckit/common');

ArrayUtils.chunk([1,2,3,4,5], 2);              // → [[1,2],[3,4],[5]]
ArrayUtils.deduplicate([1,1,2,3,2]);           // → [1,2,3]
ArrayUtils.shuffle([1,2,3,4,5]);               // → shuffled array (in place)
ArrayUtils.partition([1,2,3,4], n => n%2===0); // → [[2,4],[1,3]]
ArrayUtils.last([1,2,3]);                      // → 3

Async utilities

const { AsyncUtils } = require('@disckit/common');

await AsyncUtils.sleep(1000);

const data = await AsyncUtils.retry(() => fetch(url).then(r => r.json()), 3, 500);

const result = await AsyncUtils.withTimeout(fetchSomething(), 5000);

const results = await AsyncUtils.batchProcess(items, 10, async item => processItem(item));

Random utilities

const { RandomUtils } = require('@disckit/common');

RandomUtils.randomInt(100);             // → 0–99
RandomUtils.randomIntBetween(1, 6);    // → 1–6 (dice roll)
RandomUtils.chance(0.3);               // → true ~30% of the time
RandomUtils.randomFrom(['a','b','c']); // → random element

Discord constants

const { DISCORD, TIME } = require('@disckit/common');

DISCORD.MAX_MESSAGE_LENGTH;      // → 2000
DISCORD.MAX_EMBED_FIELDS;        // → 25
DISCORD.MAX_SELECT_OPTIONS;      // → 25
DISCORD.MAX_MODAL_COMPONENTS;    // → 5
DISCORD.MAX_MEDIA_GALLERY_ITEMS; // → 10
DISCORD.EPOCH;                   // → 1420070400000n  (Discord epoch as BigInt)

TIME.MINUTE;  // → 60000
TIME.HOUR;    // → 3600000
TIME.DAY;     // → 86400000

Top-level exports

const {
  sleep, chunk, randomInt, formatTime, toDiscordTimestamp,
  isSnowflake, mentionUser, mentionRole, mentionChannel,
  truncate, capitalize, isHexColor, containsLink, isBlank
} = require('@disckit/common');

Links