CodeSampleX

샘플

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

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. 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

컨트랙트

  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

파일

  • PROMPT.md
  • csx.json
  • index.js
  • 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 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.');

오리진 시더

익명