サンプル
sqids 0.3.0: encode
検証済みサンプル — npm sqids 0.3.0: encode. node 22 · linux debian/x64 · docker で contract を実行し、成功しました: assert sqids.encode encodes array of numbers into a unique…
sha256:9288fcf5ed7a48059a1bdf7302a7475c66f67fb74cc9b8bddd5067538644a0bf
このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。
合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。
MIT-0
実行証拠
宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。
- 証拠の基準
- 署名済みコントラクト合格
- 検証レシート
- 1
- ビルドした署名鍵
- 1
宣言された環境
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
検証実行環境
| 環境 | コントラクト | ステージ | 実行日 |
|---|---|---|---|
| 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 |
ケース
HOW- ゴール
- verify encode in pkg:npm/sqids@0.3.0
- パッケージ
- シンボル
-
- encode
- 環境
- node 22.23.2
- 作成日
- 2026-09-11T23:07:04Z
コントラクト
- 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
ファイル
- PROMPT.md
- csx.json
- index.js
- package-lock.json
- package.json
- spec.json
- test/contract.mjs
ソース
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.
{"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"}
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,
};
{
"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"
}
}
}
{
"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"
}
}
{
"schemaVersion": 1,
"goal": "verify encode in pkg:npm/sqids@0.3.0",
"kind": "HOW",
"packages": [
"pkg:npm/sqids@0.3.0"
],
"symbols": [
"encode"
]
}
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.');
オリジンシーダー
匿名