Skip to content

feat: added BigInt encoding support and updated the build toolchain - #39

Open
mdhthahmd wants to merge 9 commits into
sqids:mainfrom
mdhthahmd:feat-bigint
Open

feat: added BigInt encoding support and updated the build toolchain#39
mdhthahmd wants to merge 9 commits into
sqids:mainfrom
mdhthahmd:feat-bigint

Conversation

@mdhthahmd

@mdhthahmd mdhthahmd commented Aug 22, 2026

Copy link
Copy Markdown

Description:

This PR adds an opt-in BigInt mode to Sqids, supporting unsigned 64-bit integers from 0n to 2^64 - 1n.

Example

 import Sqids from 'sqids'

  // Number mode (default)
  const numberSqids = new Sqids()

  const numberId = numberSqids.encode([1, 2, 3])
  const numbers = numberSqids.decode(numberId)

  console.log(numberId) // '86Rf07'
  console.log(numbers) // [1, 2, 3]

  // TypeScript error: Type 'bigint' is not assignable to type 'number'
  // numberSqids.encode([1n, 2n, 3n])


  // BigInt mode
  const bigintSqids = new Sqids({ bigint: true })

  const bigintId = bigintSqids.encode([
    1n,
    42n,
    18_446_744_073_709_551_615n, // Maximum unsigned 64-bit integer
  ])

  const bigints = bigintSqids.decode(bigintId)

  console.log(bigintId) // 'NuzBXdKvyGQqDEOc'
  console.log(bigints) // [1n, 42n, 18_446_744_073_709_551_615n]

  // TypeScript error: Type 'number' is not assignable to type 'bigint'
  // bigintSqids.encode([1, 2, 3])

Changes

  • Add BigInt encoding and decoding with { bigint: true }.
  • Preserve the existing encoding output for safe integers.
  • Add mode-specific TypeScript types and input validation.
  • Add tests for BigInt round trips, limits, compatibility, and return types.
  • Migrate from Yarn/Beemo to pnpm, tsdown, Biome, and Vitest.
  • Update the CI, build, and release workflows.

@mdhthahmd mdhthahmd mentioned this pull request Aug 22, 2026
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant