Skip to content

@bight-ts/toolkit

import { ... } from "@bight-ts/toolkit";
ExportDescription
createMemoryCache(options?)Creates a TTL-based in-memory cache
MemoryCacheClass constructor for the same
MemoryCacheOptions{ ttl?: number, maxSize?: number }
ExportDescription
createConfirmationRow()Builds a Discord ActionRow with Confirm/Cancel buttons
createPagerRow()Builds previous/next pagination buttons
paginateItems(items, page, pageSize)Returns a page slice from an array
clampPageIndex(page, totalPages)Clamps a page index within valid range
ExportDescription
createKeyedLock()Creates a per-key async mutex (prevents concurrent operations on the same ID)
KeyedLockThe lock interface: acquire(key) => Promise<() => void>
ExportDescription
DISCORD_LIMITSObject with Discord character limits (embed, message, fieldValue, etc)
formatJsonCodeBlock(value, options?)Formats a value as a JSON code block, auto-truncated
splitText(text, options)Splits long text at safe boundaries (newlines, spaces)
truncateText(text, options)Truncates with an optional suffix
truncateCodeBlock(text, options)Truncates while preserving code block formatting
ExportDescription
discordTimestamp(input, style)Formats a date as a Discord timestamp string (<t:...>)
longDateTime(input)discordTimestamp(input, "F") — full date + time
relativeTime(input)discordTimestamp(input, "R") — relative (“2 hours ago”)
shortTime(input)discordTimestamp(input, "t") — short time

DiscordTimestampInput accepts Date, number (ms), or string (ISO).

ExportDescription
parseOption(interaction, name, schema)Parses a command option through a Zod schema, throwing on failure
safeParseOption(interaction, name, schema)Same, but returns SafeParseResult
parseWithSchema(value, schema)Parse any value through a Zod schema
safeParseWithSchema(value, schema)Same, safe variant
formatZodIssues(issues, options?)Formats Zod validation errors into readable strings
formatSafeParseIssues(result)Extracts and formats issues from a SafeParseResult