CodeSampleX

Sample

sqids 0.3.0: encode

Verified sample for npm sqids 0.3.0: encode. The contract ran on node 22 · linux debian/x64 · docker and passed: assert sqids.encode encodes array of numbers…

sha256:9288fcf5ed7a48059a1bdf7302a7475c66f67fb74cc9b8bddd5067538644a0bf

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Verification-run environments

Environment Contract Stages Run
node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2…
2026-09-11

Case

HOW
Goal
verify encode in pkg:npm/sqids@0.3.0
Packages
Symbols
  • encode
Environment
node 22.23.2
Created
2026-09-11T23:07:04Z

Contract

  1. assert sqids.encode encodes array of numbers into a unique string ID
  2. assert sqids.encode produces distinct string IDs for different number arrays
  3. assert sqids.encode encodes empty array to empty string
  4. assert sqids.encode satisfies minimum length when minLength option is configured
  5. assert sqids.encode restricts output characters to provided custom alphabet
  6. assert sqids.encode throws error when negative numbers are provided

Files

  • PROMPT.md
  • csx.json
  • index.js
  • package-lock.json
  • package.json
  • spec.json
  • test/contract.mjs

Download the source artifact (tar.gz)

Source

PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify encode in pkg:npm/sqids@0.3.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/sqids@0.3.0
Demonstrate these symbols/APIs:
  - encode

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:0488ea56fa111e66247cf05cb5d9b8a9c0a9b781b1a6236fa2ce0389d8535a4b","contract":["assert sqids.encode encodes array of numbers into a unique string ID","assert sqids.encode produces distinct string IDs for different number arrays","assert sqids.encode encodes empty array to empty string","assert sqids.encode satisfies minimum length when minLength option is configured","assert sqids.encode restricts output characters to provided custom alphabet","assert sqids.encode throws error when negative numbers are provided"],"goal":"verify encode in pkg:npm/sqids@0.3.0","kind":"HOW","packages":["pkg:npm/sqids@0.3.0"],"schemaVersion":1,"symbols":["encode"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/sqids@0.3.0"],"schemaVersion":1,"subject":"pkg:npm/sqids@0.3.0","symbols":["encode"],"verifierAdapter":"node-typescript@1"}
index.js
const sqidsModule = require('sqids');
const Sqids = sqidsModule.default || sqidsModule;

/**
 * Encodes an array of numbers into a unique string ID using Sqids.
 *
 * @param {number[]} numbers - Array of non-negative integers to encode.
 * @param {Object} [options] - Optional Sqids configuration options.
 * @returns {string} The encoded string ID.
 */
function encodeNumbers(numbers, options) {
  const instance = options ? new Sqids(options) : new Sqids();
  return instance.encode(numbers);
}

module.exports = {
  encodeNumbers,
  Sqids,
};
package-lock.json
{
  "name": "sample-sqids-encode",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-sqids-encode",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "sqids": "0.3.0"
      }
    },
    "node_modules/sqids": {
      "version": "0.3.0",
      "resolved": "https://registry.npmjs.org/sqids/-/sqids-0.3.0.tgz",
      "integrity": "sha512-lOQK1ucVg+W6n3FhRwwSeUijxe93b51Bfz5PMRMihVf1iVkl82ePQG7V5vwrhzB11v0NtsR25PSZRGiSomJaJw==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-sqids-encode",
  "version": "1.0.0",
  "description": "Clean-room sample verifying encode in pkg:npm/sqids@0.3.0",
  "main": "index.js",
  "license": "MIT-0",
  "dependencies": {
    "sqids": "0.3.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify encode in pkg:npm/sqids@0.3.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/sqids@0.3.0"
  ],
  "symbols": [
    "encode"
  ]
}
test/contract.mjs
import assert from 'node:assert';
import Sqids from 'sqids';
import { encodeNumbers } from '../index.js';

// 1. Basic encoding: encodes array of numbers to a unique string
const defaultSqids = new Sqids();
const encoded1 = defaultSqids.encode([1, 2, 3]);
assert.strictEqual(typeof encoded1, 'string');
assert.strictEqual(encoded1, '86Rf07', 'sqids.encode must encode [1, 2, 3] to 86Rf07');
assert.deepStrictEqual(
  defaultSqids.decode(encoded1),
  [1, 2, 3],
  'sqids.decode must decode back to the original array'
);

const encodedHelper = encodeNumbers([1, 2, 3]);
assert.strictEqual(encodedHelper, '86Rf07', 'encodeNumbers must produce identical result to sqids.encode');

// 2. Distinct inputs produce distinct strings
const encoded2 = defaultSqids.encode([1, 2, 4]);
assert.notStrictEqual(encoded1, encoded2, 'sqids.encode must produce different IDs for different inputs');

// 3. Empty array encoding: returns empty string
const encodedEmpty = defaultSqids.encode([]);
assert.strictEqual(encodedEmpty, '', 'sqids.encode must return empty string for empty array');

// 4. Custom minLength option: ensures minimum length of generated ID
const sqidsMin = new Sqids({ minLength: 10 });
const encodedMin = sqidsMin.encode([1, 2, 3]);
assert(encodedMin.length >= 10, 'sqids.encode must satisfy minLength requirement');
assert.strictEqual(encodedMin, '86Rf07xd4z', 'sqids.encode with minLength 10 matches expected output');
assert.deepStrictEqual(
  sqidsMin.decode(encodedMin),
  [1, 2, 3],
  'sqids.decode must decode minLength-padded IDs correctly'
);

// 5. Custom alphabet option: uses characters from the provided alphabet
const customAlphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
const sqidsCustom = new Sqids({ alphabet: customAlphabet });
const encodedCustom = sqidsCustom.encode([1, 2, 3]);
assert.strictEqual(encodedCustom, 'UOYbqf', 'sqids.encode with custom alphabet matches expected output');
for (const char of encodedCustom) {
  assert(customAlphabet.includes(char), `character ${char} must be within custom alphabet`);
}
assert.deepStrictEqual(
  sqidsCustom.decode(encodedCustom),
  [1, 2, 3],
  'sqids.decode must decode custom alphabet IDs correctly'
);

// 6. Error handling: throws error on negative numbers
assert.throws(
  () => {
    defaultSqids.encode([-1]);
  },
  {
    message: /Encoding supports numbers between 0 and/,
  },
  'sqids.encode must throw error when negative number is passed'
);

console.log('All contract assertions passed.');

Origin Seeder

anonymous