ProvenPin Install

sqids encode and decode: working versions (tested 2026-10-16)

Encode lists of non-negative numbers into short ids with sqids and decode them back, customizing the alphabet and minimum length, all offline.

passed4 passed · 0 failed2026-10-16 15:21 UTC
Status
passed
Last passed
2026-10-16 15:21 UTC
Tests
4 / 4
Language
TypeScript
Runtime
node v22.23.3
pinned versions3
sqids@0.3.0@types/node@26.6.5tsx@4.23.15
run it
npm install --no-audit --no-fund --ignore-scripts=false
npm test
test environment
node v22.23.3
linux 6.17.0-1022-azure
x64
runner: github-actions 38923127324

The code

Exactly the files that passed. Your agent can pull them with get_recipe("sqids-encode-decode") (install), or see them on GitHub.

package.json
{
  "name": "sqids-encode-decode",
  "private": true,
  "type": "module",
  "scripts": {
    "test": "node --import tsx --test test/*.test.ts"
  },
  "dependencies": {
    "sqids": "0.3.0"
  },
  "devDependencies": {
    "@types/node": "26.6.5",
    "tsx": "4.23.15"
  }
}
src/sqids.ts
import Sqids from "sqids";

export type SqidsConfig = {
  alphabet?: string;
  minLength?: number;
  blocklist?: Set<string>;
};

export function createSqids(config: SqidsConfig = {}): Sqids {
  return new Sqids(config);
}

export function encodeNumbers(sqids: Sqids, numbers: number[]): string {
  return sqids.encode(numbers);
}

export function decodeId(sqids: Sqids, id: string): number[] {
  return sqids.decode(id);
}
test/sqids.test.ts
import { test } from "node:test";
import assert from "node:assert/strict";
import { createSqids, decodeId, encodeNumbers } from "../src/sqids.ts";

test("roundtrips a list of non-negative numbers", () => {
  const sqids = createSqids();
  const numbers = [1, 2, 3, 4, 5];
  const id = encodeNumbers(sqids, numbers);
  assert.equal(typeof id, "string");
  assert.ok(id.length > 0);
  assert.deepEqual(decodeId(sqids, id), numbers);
});

test("different number lists produce different ids", () => {
  const sqids = createSqids();
  const a = encodeNumbers(sqids, [1, 2, 3]);
  const b = encodeNumbers(sqids, [3, 2, 1]);
  const c = encodeNumbers(sqids, [1, 2, 4]);
  assert.notEqual(a, b);
  assert.notEqual(a, c);
  assert.notEqual(b, c);
  assert.deepEqual(decodeId(sqids, a), [1, 2, 3]);
  assert.deepEqual(decodeId(sqids, b), [3, 2, 1]);
  assert.deepEqual(decodeId(sqids, c), [1, 2, 4]);
});

test("custom alphabet and minLength are honored", () => {
  const alphabet = "abcdefghijklmnopqrstuvwxyz";
  const sqids = createSqids({ alphabet, minLength: 10 });
  const id = encodeNumbers(sqids, [10, 20, 30]);
  assert.ok(id.length >= 10);
  for (const ch of id) {
    assert.ok(alphabet.includes(ch));
  }
  assert.deepEqual(decodeId(sqids, id), [10, 20, 30]);
});

test("configurations with different alphabets diverge", () => {
  const lower = createSqids({ alphabet: "abcdefghijklmnopqrstuvwxyz" });
  const mixed = createSqids({ alphabet: "0123456789abcdefghijklmnopqrstuvwxyz" });
  const a = encodeNumbers(lower, [1, 2, 3]);
  const b = encodeNumbers(mixed, [1, 2, 3]);
  assert.notEqual(a, b);
  assert.deepEqual(decodeId(lower, a), [1, 2, 3]);
  assert.deepEqual(decodeId(mixed, b), [1, 2, 3]);
});

Connect to ProvenPin

Add the free MCP server so your agent can pull this recipe and others like it. Same setup as the docs.

terminal
claude mcp add --transport http provenpin https://mcp.provenpin.com/mcp

Any other MCP client: Streamable HTTP at https://mcp.provenpin.com/mcp. No API key, no signup.