CodeSampleX

Пример

path-to-regexp 8.4.2

Проверенный пример — npm path-to-regexp 8.4.2. Контракт выполнен на node 22 · linux alpine/x64 · docker и пройден: match(path) matches named parameters and…

sha256:d1885bc270eecc923f7bb07b638a5c8f1ebe40ef4e319b50a89eac3250a32caa

Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла. Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди. MIT-0

Свидетельства выполнения

Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.

Основа свидетельства
Подписанный контракт пройден
Квитанции проверки
2
Ключи подписи, собравшие его
1
Заявленная среда linux 24 · ubuntu · glibc 2.39 x64 npm

Среды запусков проверки

Окружение Контракт Этапы Запуск
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1
2026-08-20
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-07

Кейс

HOW
Цель
verify pkg:npm/path-to-regexp@8.4.2
Пакеты
Создан
2026-08-20T13:56:46Z

Контракт

  1. match(path) matches named parameters and returns the matched path and decoded parameter object
  2. match(path) matches wildcard parameters (*splat) capturing multi-segment paths as an array of decoded strings
  3. match(path) matches optional path segments wrapped in braces ({/:id}) returning empty parameters when omitted
  4. compile(path) transforms a parameter object into a URL path string, properly encoding parameter values
  5. compile(path) transforms array parameters for wildcard segments into delimited path segments
  6. pathToRegexp(path) returns an object containing a RegExp instance and keys array matching parameter definitions
  7. parse(path) produces a TokenData structure and stringify(data) reconstructs the pattern string
  8. match and parse throw PathError for invalid path syntax such as missing parameter names or unclosed braces

Файлы

  • 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 pkg:npm/path-to-regexp@8.4.2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/path-to-regexp@8.4.2

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:96b645ab77405c5cd3b9c872e3aeb6e09a0cdba338ed96d7b661a7119af9d786","contract":["match(path) matches named parameters and returns the matched path and decoded parameter object","match(path) matches wildcard parameters (*splat) capturing multi-segment paths as an array of decoded strings","match(path) matches optional path segments wrapped in braces ({/:id}) returning empty parameters when omitted","compile(path) transforms a parameter object into a URL path string, properly encoding parameter values","compile(path) transforms array parameters for wildcard segments into delimited path segments","pathToRegexp(path) returns an object containing a RegExp instance and keys array matching parameter definitions","parse(path) produces a TokenData structure and stringify(data) reconstructs the pattern string","match and parse throw PathError for invalid path syntax such as missing parameter names or unclosed braces"],"goal":"verify pkg:npm/path-to-regexp@8.4.2","kind":"HOW","packages":["pkg:npm/path-to-regexp@8.4.2"],"schemaVersion":1},"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/path-to-regexp@8.4.2"],"schemaVersion":1,"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-path-to-regexp",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-path-to-regexp",
      "version": "1.0.0",
      "dependencies": {
        "path-to-regexp": "8.4.2"
      }
    },
    "node_modules/path-to-regexp": {
      "version": "8.4.2",
      "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-8.4.2.tgz",
      "integrity": "sha512-qRcuIdP69NPm4qbACK+aDogI5CBDMi1jKe0ry5rSQJz8JVLsC7jV8XpiJjGRLLol3N+R5ihGYcrPLTno6pAdBA==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-path-to-regexp",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "dependencies": {
    "path-to-regexp": "8.4.2"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/path-to-regexp@8.4.2",
  "kind": "HOW",
  "packages": [
    "pkg:npm/path-to-regexp@8.4.2"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import { match, compile, pathToRegexp, parse, stringify, PathError } from 'path-to-regexp';

// 1. match(path) matches named parameters and returns the matched path and decoded parameter object
const matchNamed = match('/users/:id/profile');
const matchNamedResult = matchNamed('/users/42/profile');
assert.notEqual(matchNamedResult, false);
assert.equal(matchNamedResult.path, '/users/42/profile');
assert.equal(matchNamedResult.params.id, '42');
assert.equal(matchNamed('/other/42/profile'), false);

// 2. match(path) matches wildcard parameters (*splat) capturing multi-segment paths as an array of decoded strings
const matchWild = match('/files/*splat');
const matchWildResult = matchWild('/files/docs/2026/report.pdf');
assert.notEqual(matchWildResult, false);
assert.equal(matchWildResult.path, '/files/docs/2026/report.pdf');
assert.deepEqual(matchWildResult.params.splat, ['docs', '2026', 'report.pdf']);

// 3. match(path) matches optional path segments wrapped in braces ({/:id}) returning empty parameters when omitted
const matchOpt = match('/users{/:id}');
const matchOptWith = matchOpt('/users/99');
assert.notEqual(matchOptWith, false);
assert.equal(matchOptWith.params.id, '99');

const matchOptWithout = matchOpt('/users');
assert.notEqual(matchOptWithout, false);
assert.equal(matchOptWithout.params.id, undefined);
assert.deepEqual(Object.keys(matchOptWithout.params), []);

// 4. compile(path) transforms a parameter object into a URL path string, properly encoding parameter values
const compileUser = compile('/users/:id');
assert.equal(compileUser({ id: 'alice' }), '/users/alice');
assert.equal(compileUser({ id: 'café' }), '/users/caf%C3%A9');

// 5. compile(path) transforms array parameters for wildcard segments into delimited path segments
const compileFiles = compile('/files/*splat');
assert.equal(compileFiles({ splat: ['docs', 'report.pdf'] }), '/files/docs/report.pdf');

// 6. pathToRegexp(path) returns an object containing a RegExp instance and keys array matching parameter definitions
const { regexp, keys } = pathToRegexp('/posts/:slug');
assert(regexp instanceof RegExp);
assert.equal(keys.length, 1);
assert.equal(keys[0].name, 'slug');
assert.equal(keys[0].type, 'param');
assert(regexp.test('/posts/announcement'));
assert(!regexp.test('/articles/announcement'));

// 7. parse(path) produces a TokenData structure and stringify(data) reconstructs the pattern string
const tokenData = parse('/items/:category/:id');
assert.equal(tokenData.originalPath, '/items/:category/:id');
assert.equal(tokenData.tokens.length, 4);
assert.equal(stringify(tokenData), '/items/:category/:id');

// 8. match and parse throw PathError for invalid path syntax such as missing parameter names or unclosed braces
assert.throws(() => match('/invalid/:'), (err) => {
  return err instanceof PathError && /Missing parameter name/.test(err.message);
});
assert.throws(() => parse('/unclosed/{group'), (err) => {
  return err instanceof PathError && /Unexpected end/.test(err.message);
});

console.log('Contract tests passed successfully.');

Исходный сидер

аноним