CodeSampleX

Ejemplo

nanoid 3.3.17: urlAlphabet

Muestra verificada para npm nanoid 3.3.17: urlAlphabet. El contrato se ejecutó en node 22 · linux alpine/x64 · docker y pasó: urlAlphabet is an exported…

sha256:dce0f4d84d96142e78102bd8fb97fb5d2cb240fd468ad8bbb338b179f7313d70

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
1
Claves de firma que lo compilaron
1
Entorno declarado node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
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

Caso

HOW
Objetivo
verify nanoid.urlAlphabet in pkg:npm/nanoid@3.3.17
Paquetes
Símbolos
  • nanoid.urlAlphabet
Entorno
node 22.23.2
Creado
2026-08-27T16:29:21Z

Contrato

  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

Archivos

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

Descargar el artefacto de código fuente (tar.gz)

Código fuente

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);
}

Seeder de origen

anónimo