CodeSampleX

サンプル

sqids 0.3.0: default

検証済みサンプル — npm sqids 0.3.0: default. node 22 · linux debian/x64 · docker で contract を実行し、成功しました: sqids.default exposes the default export constructor…

sha256:4bbf8fa5ffd062fbe17cc322f8b9011de68a354bc09c8a13ab8992066c88c367

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 MIT-0

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
1
ビルドした署名鍵
1
宣言された環境 linux 24 · ubuntu · glibc 2.39 x64 npm

検証実行環境

環境 コントラクト ステージ 実行日
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-19

ケース

HOW
ゴール
verify sqids.default in pkg:npm/sqids@0.3.0
パッケージ
シンボル
  • sqids.default
作成日
2026-09-17T18:46:17Z

コントラクト

  1. sqids.default exposes the default export constructor function from sqids module
  2. sqids.default instantiates with default options and creates functional instance
  3. sqids.default encodes an array of integers into an ID string and decodes back
  4. sqids.default instantiates with custom alphabet, minLength, and blocklist options
  5. sqids.default encodes empty array to empty string and decodes empty string to empty array
  6. sqids.default enforces minimum length by padding the generated ID
  7. sqids.default throws when encoding negative numbers or numbers exceeding MAX_SAFE_INTEGER
  8. sqids.default rejects invalid alphabet with multibyte, short length, or duplicates

ファイル

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

ソースアーティファクトをダウンロード (tar.gz)

ソース

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 sqids.default 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:
  - sqids.default

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:17d2dcf4d952d9ac7210ec7a17d0a86807ecfc04308f3d40fbc252dc63889540","contract":["sqids.default exposes the default export constructor function from sqids module","sqids.default instantiates with default options and creates functional instance","sqids.default encodes an array of integers into an ID string and decodes back","sqids.default instantiates with custom alphabet, minLength, and blocklist options","sqids.default encodes empty array to empty string and decodes empty string to empty array","sqids.default enforces minimum length by padding the generated ID","sqids.default throws when encoding negative numbers or numbers exceeding MAX_SAFE_INTEGER","sqids.default rejects invalid alphabet with multibyte, short length, or duplicates"],"goal":"verify sqids.default in pkg:npm/sqids@0.3.0","kind":"HOW","packages":["pkg:npm/sqids@0.3.0"],"schemaVersion":1,"symbols":["sqids.default"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/sqids@0.3.0"],"schemaVersion":1,"subject":"pkg:npm/sqids@0.3.0","symbols":["sqids.default"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-sqids",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-sqids",
      "version": "1.0.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",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "dependencies": {
    "sqids": "0.3.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify sqids.default in pkg:npm/sqids@0.3.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/sqids@0.3.0"
  ],
  "symbols": [
    "sqids.default"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import * as sqids from 'sqids';
import defaultImport from 'sqids';

// 1. sqids.default exposes the default export constructor function from sqids module
{
  assert.ok(typeof sqids.default === 'function', 'sqids.default should be a function/constructor');
  assert.strictEqual(sqids.default, defaultImport, 'sqids.default should match default import');
  const dynamic = await import('sqids');
  assert.strictEqual(dynamic.default, sqids.default, 'dynamic import default should match sqids.default');
}

// 2. sqids.default instantiates with default options and creates functional instance
{
  const instance = new sqids.default();
  assert.ok(instance instanceof sqids.default, 'instance should be an instance of sqids.default');
  assert.strictEqual(typeof instance.encode, 'function', 'instance should have encode method');
  assert.strictEqual(typeof instance.decode, 'function', 'instance should have decode method');
}

// 3. sqids.default encodes an array of integers into an ID string and decodes back
{
  const instance = new sqids.default();
  const numbers = [1, 2, 3];
  const id = instance.encode(numbers);
  assert.strictEqual(typeof id, 'string', 'encode should return a string');
  assert.ok(id.length > 0, 'encoded ID string should not be empty');

  const decoded = instance.decode(id);
  assert.deepStrictEqual(decoded, numbers, 'decode should reproduce original numbers');

  const zeroTest = [0, 42, 9999];
  assert.deepStrictEqual(instance.decode(instance.encode(zeroTest)), zeroTest, 'roundtrip with zero and large numbers');
}

// 4. sqids.default instantiates with custom alphabet, minLength, and blocklist options
{
  const customAlphabet = 'abcdefghijklmnopqrstuvwxyz0123456789';
  const customInstance = new sqids.default({
    alphabet: customAlphabet,
    minLength: 8,
    blocklist: new Set(['blockedword']),
  });
  assert.ok(customInstance instanceof sqids.default, 'custom instance should be an instance of sqids.default');
  const id = customInstance.encode([10, 20]);
  assert.ok(id.length >= 8, 'custom minLength should be honored');
  assert.deepStrictEqual(customInstance.decode(id), [10, 20], 'custom instance should decode correctly');
}

// 5. sqids.default encodes empty array to empty string and decodes empty string to empty array
{
  const instance = new sqids.default();
  assert.strictEqual(instance.encode([]), '', 'encode empty array should return empty string');
  assert.deepStrictEqual(instance.decode(''), [], 'decode empty string should return empty array');
}

// 6. sqids.default enforces minimum length by padding the generated ID
{
  const minLength = 10;
  const instance = new sqids.default({ minLength });
  const id = instance.encode([1]);
  assert.ok(id.length >= minLength, `encoded ID length (${id.length}) should be at least minLength (${minLength})`);
  assert.deepStrictEqual(instance.decode(id), [1], 'padded ID should decode correctly');
}

// 7. sqids.default throws when encoding negative numbers or numbers exceeding MAX_SAFE_INTEGER
{
  const instance = new sqids.default();
  assert.throws(
    () => instance.encode([-1]),
    /Encoding supports numbers between 0 and/,
    'encoding negative number should throw RangeError'
  );
  assert.throws(
    () => instance.encode([Number.MAX_SAFE_INTEGER + 1]),
    /Encoding supports numbers between 0 and/,
    'encoding number > MAX_SAFE_INTEGER should throw RangeError'
  );
}

// 8. sqids.default rejects invalid alphabet with multibyte, short length, or duplicates
{
  assert.throws(
    () => new sqids.default({ alphabet: 'ab' }),
    /Alphabet length must be at least 3/,
    'alphabet length < 3 should throw'
  );
  assert.throws(
    () => new sqids.default({ alphabet: 'aabcdef' }),
    /Alphabet must contain unique characters/,
    'duplicate characters in alphabet should throw'
  );
  assert.throws(
    () => new sqids.default({ alphabet: 'abc\u{1F680}def' }),
    /Alphabet cannot contain multibyte characters/,
    'multibyte characters in alphabet should throw'
  );
}

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

オリジンシーダー

匿名