CodeSampleX

Exemplo

balanced-match 1.0.2

Amostra verificada para npm balanced-match 1.0.2. O contrato rodou em node 22 · linux alpine/x64 · docker e passou: balanced matches balanced delimiters and…

sha256:6bac510a5d55404e7b6c840be79fb2fd1ce04c4f993a7fb4822cbe644fb42530

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@1
2026-08-21

Caso

HOW
Objetivo
verify pkg:npm/balanced-match@1.0.2
Pacotes
Ambiente
node 22.23.2
Criado
2026-08-21T16:12:24Z

Contrato

  1. balanced matches balanced delimiters and returns pre, body, post, start, and end
  2. balanced correctly parses nested delimiters returning the outermost balanced span
  3. balanced returns undefined when delimiters do not match
  4. balanced.range returns [start, end] indices for balanced matches or undefined if unbalanced

Arquivos

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

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/balanced-match@1.0.2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/balanced-match@1.0.2
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:6bb49f69b03a0f59eb7b857fb9328b808879a6cc58199f5af373275253c6e16e","constraints":{"executionContext":"node"},"contract":["balanced matches balanced delimiters and returns pre, body, post, start, and end","balanced correctly parses nested delimiters returning the outermost balanced span","balanced returns undefined when delimiters do not match","balanced.range returns [start, end] indices for balanced matches or undefined if unbalanced"],"goal":"verify pkg:npm/balanced-match@1.0.2","kind":"HOW","packages":["pkg:npm/balanced-match@1.0.2"],"schemaVersion":1},"contractCommand":["node","test/contract.js"],"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/balanced-match@1.0.2"],"schemaVersion":1,"subject":"pkg:npm/balanced-match@1.0.2","verifierAdapter":"node-typescript@1"}
index.js
const balanced = require("balanced-match");

function extractBalanced(opening, closing, text) {
  const match = balanced(opening, closing, text);
  if (!match) {
    return null;
  }
  return {
    start: match.start,
    end: match.end,
    pre: match.pre,
    body: match.body,
    post: match.post
  };
}

function extractRange(opening, closing, text) {
  return balanced.range(opening, closing, text);
}

module.exports = {
  extractBalanced,
  extractRange
};
package-lock.json
{
  "name": "sample-balanced-match",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-balanced-match",
      "version": "1.0.0",
      "dependencies": {
        "balanced-match": "1.0.2"
      }
    },
    "node_modules/balanced-match": {
      "version": "1.0.2",
      "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
      "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-balanced-match",
  "version": "1.0.0",
  "private": true,
  "description": "Sample verifying balanced-match delimiters matching and range extraction",
  "main": "index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "balanced-match": "1.0.2"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/balanced-match@1.0.2",
  "kind": "HOW",
  "packages": [
    "pkg:npm/balanced-match@1.0.2"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.js
const assert = require("assert");
const { extractBalanced, extractRange } = require("../index.js");
const balanced = require("balanced-match");

// Test 1: Basic balanced delimiter match
const res1 = extractBalanced("{", "}", "prefix{inside}suffix");
assert.deepStrictEqual(res1, {
  start: 6,
  end: 13,
  pre: "prefix",
  body: "inside",
  post: "suffix"
});

// Test 2: Nested delimiter match returns the outermost balanced range
const res2 = extractBalanced("{", "}", "a{b{c}d}e");
assert.deepStrictEqual(res2, {
  start: 1,
  end: 7,
  pre: "a",
  body: "b{c}d",
  post: "e"
});

// Test 3: No match returns null
const res3 = extractBalanced("{", "}", "no delimiters here");
assert.strictEqual(res3, null);

// Test 4: Custom string delimiter match
const res4 = extractBalanced("<b>", "</b>", "hello <b>world</b>!");
assert.deepStrictEqual(res4, {
  start: 6,
  end: 14,
  pre: "hello ",
  body: "world",
  post: "!"
});

// Test 5: Range extraction returns [start, end] indices
const range1 = extractRange("{", "}", "abc{def}ghi");
assert.deepStrictEqual(range1, [3, 7]);

// Test 6: Unbalanced string returns undefined
const rangeUnbalanced = extractRange("{", "}", "unbalanced { open");
assert.strictEqual(rangeUnbalanced, undefined);

// Direct package call verification
const direct = balanced("(", ")", "pre(match)post");
assert.strictEqual(direct.body, "match");

console.log("All contract tests passed successfully.");

Seeder de origem

anônimo