CodeSampleX

Exemplo

braces 3.0.3: expand, compile

Amostra verificada para npm braces 3.0.3: expand, compile. O contrato rodou em node 22 · linux alpine/x64 · docker e passou: assert braces compiles pattern…

sha256:fc155561bbfc60003a6e4f09382bbf97232e96e4f6f914ee1a47db97e7b9c7dc

Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu. Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas. MIT-0

Evidência de execução

O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.

Base da evidência
Contrato assinado aprovado
Recibos de verificação
1
Chaves de assinatura que o compilaram
1
Ambiente declarado node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Ambientes das execuções de verificação

Ambiente Contrato Etapas Execução
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-26

Caso

HOW
Objetivo
verify pkg:npm/braces@3.0.3
Pacotes
Símbolos
  • braces
  • braces.expand
  • braces.compile
Ambiente
node 22.23.2
Criado
2026-08-26T07:51:15Z

Contrato

  1. assert braces compiles pattern sets to regex group strings by default
  2. assert braces.expand expands comma-separated alternatives and sequential sets
  3. assert braces.expand expands numeric and alphabetical ranges with steps and zero-padding
  4. assert braces.expand expands nested brace patterns and supports custom transform functions and deduplication
  5. assert braces.compile compiles brace sets and numeric ranges into regex pattern strings

Arquivos

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

Baixar o artefato de código-fonte (tar.gz)

Código-fonte

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/braces@3.0.3
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/braces@3.0.3
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - runtime: node@22.23.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:8598d5ca3bdefede8916368f5fea0bd722211bca353b35e6c6614521d9ab08d6","constraints":{"executionContext":"node"},"contract":["assert braces compiles pattern sets to regex group strings by default","assert braces.expand expands comma-separated alternatives and sequential sets","assert braces.expand expands numeric and alphabetical ranges with steps and zero-padding","assert braces.expand expands nested brace patterns and supports custom transform functions and deduplication","assert braces.compile compiles brace sets and numeric ranges into regex pattern strings"],"goal":"verify pkg:npm/braces@3.0.3","kind":"HOW","packages":["pkg:npm/braces@3.0.3"],"schemaVersion":1,"symbols":["braces","braces.expand","braces.compile"]},"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/braces@3.0.3"],"schemaVersion":1,"subject":"pkg:npm/braces@3.0.3","symbols":["braces","braces.expand","braces.compile"],"verifierAdapter":"node-typescript@1"}
index.js
const braces = require('braces');

/**
 * Expands a brace pattern into an array of resulting strings.
 *
 * @param {string} pattern - Pattern containing braces to expand.
 * @param {Object} [options] - Expansion options (e.g. { expand: true, nodupes: true }).
 * @returns {string[]} Array of expanded strings.
 */
function expandPattern(pattern, options) {
  return braces.expand(pattern, options);
}

/**
 * Compiles a brace pattern into an optimized regex string representation.
 *
 * @param {string} pattern - Pattern containing braces to compile.
 * @param {Object} [options] - Compilation options.
 * @returns {string[]} Compiled pattern array.
 */
function compilePattern(pattern, options) {
  return braces.compile(pattern, options);
}

module.exports = {
  expandPattern,
  compilePattern,
  braces,
};
package-lock.json
{
  "name": "sample-braces",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-braces",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "braces": "3.0.3"
      }
    },
    "node_modules/braces": {
      "version": "3.0.3",
      "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz",
      "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==",
      "license": "MIT",
      "dependencies": {
        "fill-range": "^7.1.1"
      },
      "engines": {
        "node": ">=8"
      }
    },
    "node_modules/fill-range": {
      "version": "7.1.1",
      "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz",
      "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==",
      "license": "MIT",
      "dependencies": {
        "to-regex-range": "^5.0.1"
      },
      "engines": {
        "node": ">=8"
      }
    },
    "node_modules/is-number": {
      "version": "7.0.0",
      "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz",
      "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==",
      "license": "MIT",
      "engines": {
        "node": ">=0.12.0"
      }
    },
    "node_modules/to-regex-range": {
      "version": "5.0.1",
      "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz",
      "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==",
      "license": "MIT",
      "dependencies": {
        "is-number": "^7.0.0"
      },
      "engines": {
        "node": ">=8.0"
      }
    }
  }
}
package.json
{
  "name": "sample-braces",
  "version": "1.0.0",
  "description": "Clean-room sample verifying pkg:npm/braces@3.0.3 functionality",
  "main": "index.js",
  "license": "MIT-0",
  "dependencies": {
    "braces": "3.0.3"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/braces@3.0.3",
  "kind": "HOW",
  "packages": [
    "pkg:npm/braces@3.0.3"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.mjs
import assert from 'node:assert';
import braces from 'braces';
import { expandPattern, compilePattern } from '../index.js';

// 1. Default compilation behavior
const defaultCompiled = braces('a/{b,c}/d');
assert.deepStrictEqual(
  defaultCompiled,
  ['a/(b|c)/d'],
  'braces compiles pattern sets to regex group strings by default'
);

// 2. Expand comma-separated alternatives and sequential sets
const setExpanded = expandPattern('path/{foo,bar}/file.txt');
assert.deepStrictEqual(
  setExpanded,
  ['path/foo/file.txt', 'path/bar/file.txt'],
  'braces.expand must expand comma-separated sets into individual string elements'
);

const simpleSet = braces.expand('{a,b,c}');
assert.deepStrictEqual(
  simpleSet,
  ['a', 'b', 'c'],
  'braces.expand must expand simple list of alternatives'
);

const seqExpanded = expandPattern('{a,b}{1,2}');
assert.deepStrictEqual(
  seqExpanded,
  ['a1', 'a2', 'b1', 'b2'],
  'braces.expand must expand sequential brace patterns'
);

// 3. Expand numeric and alphabetical ranges with steps and zero-padding
const numRange = expandPattern('{1..5}');
assert.deepStrictEqual(
  numRange,
  ['1', '2', '3', '4', '5'],
  'braces.expand must expand numeric range'
);

const alphaRange = expandPattern('{a..e}');
assert.deepStrictEqual(
  alphaRange,
  ['a', 'b', 'c', 'd', 'e'],
  'braces.expand must expand alphabetical range'
);

const stepRange = expandPattern('{1..10..2}');
assert.deepStrictEqual(
  stepRange,
  ['1', '3', '5', '7', '9'],
  'braces.expand must expand stepped numeric range'
);

const paddedRange = expandPattern('{01..03}');
assert.deepStrictEqual(
  paddedRange,
  ['01', '02', '03'],
  'braces.expand must preserve zero padding in numeric ranges'
);

// 4. Expand nested patterns, transform functions, and deduplication
const nestedExpanded = expandPattern('a/{b,c/{d,e}}/f');
assert.deepStrictEqual(
  nestedExpanded,
  ['a/b/f', 'a/c/d/f', 'a/c/e/f'],
  'braces.expand must expand nested brace patterns'
);

const transformed = expandPattern('{1..3}', { transform: val => `v${val}` });
assert.deepStrictEqual(
  transformed,
  ['v1', 'v2', 'v3'],
  'braces.expand must apply custom transform function'
);

const deduplicated = expandPattern('{a,b,a}', { nodupes: true });
assert.deepStrictEqual(
  deduplicated,
  ['a', 'b'],
  'braces.expand must deduplicate results when nodupes is true'
);

// 5. Compile to regex pattern strings
const compiledSet = compilePattern('a/{b,c}/d');
assert.strictEqual(
  compiledSet,
  'a/(b|c)/d',
  'braces.compile must compile sets into regex branch group string'
);

const compiledRange = compilePattern('{1..5}');
assert.strictEqual(
  compiledRange,
  '([1-5])',
  'braces.compile must compile numeric ranges into regex character class string'
);

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

Seeder de origem

anônimo