CodeSampleX

샘플

nanoid 3.3.17: urlAlphabet

검증된 샘플 — npm nanoid 3.3.17: urlAlphabet. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: urlAlphabet is an exported 64-character string…

sha256:dce0f4d84d96142e78102bd8fb97fb5d2cb240fd468ad8bbb338b179f7313d70

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

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

검증 실행 환경

환경 컨트랙트 단계 실행일
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5…
2026-08-27

케이스

HOW
목표
verify nanoid.urlAlphabet in pkg:npm/nanoid@3.3.17
패키지
심벌
  • nanoid.urlAlphabet
환경
node 22.23.2
생성일
2026-08-27T16:29:21Z

컨트랙트

  1. urlAlphabet is an exported 64-character string containing URL-safe characters
  2. urlAlphabet contains 64 unique characters with numbers, lowercase letters, uppercase letters, hyphen, and underscore
  3. urlAlphabet characters all conform to URL-safe ASCII character set
  4. urlAlphabet is exported both from the root nanoid package and from the url-alphabet subpath
  5. urlAlphabet can be used with customAlphabet to generate URL-safe identifiers

파일

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

소스 아티팩트 내려받기 (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 nanoid.urlAlphabet in pkg:npm/nanoid@3.3.17
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/nanoid@3.3.17
Demonstrate these symbols/APIs:
  - nanoid.urlAlphabet

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:26b4a85d96249f2576d330b626be6bd8f2d726c7eb797acc0f56069ea5e0d3ac","contract":["urlAlphabet is an exported 64-character string containing URL-safe characters","urlAlphabet contains 64 unique characters with numbers, lowercase letters, uppercase letters, hyphen, and underscore","urlAlphabet characters all conform to URL-safe ASCII character set","urlAlphabet is exported both from the root nanoid package and from the url-alphabet subpath","urlAlphabet can be used with customAlphabet to generate URL-safe identifiers"],"goal":"verify nanoid.urlAlphabet in pkg:npm/nanoid@3.3.17","kind":"HOW","packages":["pkg:npm/nanoid@3.3.17"],"schemaVersion":1,"symbols":["nanoid.urlAlphabet"]},"contractCommand":["node","test/contract.cjs"],"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/nanoid@3.3.17"],"schemaVersion":1,"subject":"pkg:npm/nanoid@3.3.17","symbols":["nanoid.urlAlphabet"],"verifierAdapter":"node-typescript@1"}
index.js
'use strict';

const { urlAlphabet } = require('nanoid');

/**
 * Returns the default URL-safe alphabet string used by Nano ID.
 * @returns {string} The 64-character URL-safe alphabet.
 */
function getUrlAlphabet() {
  return urlAlphabet;
}

/**
 * Validates whether all characters in a given string belong to nanoid.urlAlphabet.
 * @param {string} str - String to validate.
 * @returns {boolean} True if all characters are in urlAlphabet, false otherwise.
 */
function isUrlSafeString(str) {
  if (typeof str !== 'string') {
    return false;
  }
  for (let i = 0; i < str.length; i++) {
    if (!urlAlphabet.includes(str[i])) {
      return false;
    }
  }
  return true;
}

module.exports = {
  urlAlphabet,
  getUrlAlphabet,
  isUrlSafeString
};
package-lock.json
{
  "name": "sample-nanoid-urlalphabet",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-nanoid-urlalphabet",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "nanoid": "3.3.17"
      }
    },
    "node_modules/nanoid": {
      "version": "3.3.17",
      "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.17.tgz",
      "integrity": "sha512-xQLf0A3HOMlgHq0n247/LRuAOYmB7dXJ/DvAxGvsSBij45XtBSmQycu+F8ODbHwns/XyFZagyL1+J0Offw1E0g==",
      "funding": [
        {
          "type": "github",
          "url": "https://github.com/sponsors/ai"
        }
      ],
      "license": "MIT",
      "bin": {
        "nanoid": "bin/nanoid.cjs"
      },
      "engines": {
        "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1"
      }
    }
  }
}
package.json
{
  "name": "sample-nanoid-urlalphabet",
  "version": "1.0.0",
  "private": true,
  "description": "verify nanoid.urlAlphabet in pkg:npm/nanoid@3.3.17",
  "main": "index.js",
  "scripts": {
    "test": "node test/contract.cjs"
  },
  "dependencies": {
    "nanoid": "3.3.17"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify nanoid.urlAlphabet in pkg:npm/nanoid@3.3.17",
  "kind": "HOW",
  "packages": [
    "pkg:npm/nanoid@3.3.17"
  ],
  "symbols": [
    "nanoid.urlAlphabet"
  ]
}
test/contract.cjs
'use strict';

const assert = require('node:assert');
const { urlAlphabet: rootAlphabet, customAlphabet } = require('nanoid');
const { urlAlphabet: subAlphabet } = require('nanoid/url-alphabet');
const { urlAlphabet, getUrlAlphabet, isUrlSafeString } = require('../index.js');

function testAlphabetStructure() {
  // 1. urlAlphabet is an exported 64-character string containing URL-safe characters
  assert.strictEqual(typeof urlAlphabet, 'string', 'urlAlphabet must be a string');
  assert.strictEqual(urlAlphabet.length, 64, 'urlAlphabet must have length 64');
  assert.strictEqual(getUrlAlphabet(), urlAlphabet, 'getUrlAlphabet helper must return urlAlphabet');

  // 2. urlAlphabet contains 64 unique characters with numbers, lowercase letters, uppercase letters, hyphen, and underscore
  const charSet = new Set(urlAlphabet);
  assert.strictEqual(charSet.size, 64, 'urlAlphabet must contain 64 unique characters');

  for (let c = 65; c <= 90; c++) {
    assert.ok(charSet.has(String.fromCharCode(c)), `Must contain uppercase letter ${String.fromCharCode(c)}`);
  }
  for (let c = 97; c <= 122; c++) {
    assert.ok(charSet.has(String.fromCharCode(c)), `Must contain lowercase letter ${String.fromCharCode(c)}`);
  }
  for (let c = 48; c <= 57; c++) {
    assert.ok(charSet.has(String.fromCharCode(c)), `Must contain digit ${String.fromCharCode(c)}`);
  }
  assert.ok(charSet.has('-'), 'Must contain hyphen (-) character');
  assert.ok(charSet.has('_'), 'Must contain underscore (_) character');

  // 3. urlAlphabet characters all conform to URL-safe ASCII character set
  assert.match(urlAlphabet, /^[A-Za-z0-9_-]{64}$/, 'urlAlphabet characters must all be URL-safe ASCII');
  assert.strictEqual(isUrlSafeString(urlAlphabet), true, 'urlAlphabet must pass isUrlSafeString check');
  assert.strictEqual(isUrlSafeString('hello-world_123'), true);
  assert.strictEqual(isUrlSafeString('hello world!'), false);
  assert.strictEqual(isUrlSafeString(null), false);

  // 4. urlAlphabet is exported both from the root nanoid package and from the url-alphabet subpath
  assert.strictEqual(rootAlphabet, urlAlphabet, 'root export must match urlAlphabet');
  assert.strictEqual(subAlphabet, urlAlphabet, 'subpath export must match urlAlphabet');

  // 5. urlAlphabet can be used with customAlphabet to generate URL-safe identifiers
  const generate = customAlphabet(urlAlphabet, 21);
  assert.strictEqual(typeof generate, 'function', 'customAlphabet should return a generator');
  const id = generate();
  assert.strictEqual(typeof id, 'string', 'Generated ID must be a string');
  assert.strictEqual(id.length, 21, 'Generated ID length must match configured size');
  assert.strictEqual(isUrlSafeString(id), true, 'Generated ID characters must all belong to urlAlphabet');
}

function runAll() {
  testAlphabetStructure();
  console.log('Contract verification finished successfully.');
}

try {
  runAll();
  process.exit(0);
} catch (err) {
  console.error('Contract verification failed:', err);
  process.exit(1);
}

오리진 시더

익명