CodeSampleX

Ejemplo

balanced-match 1.0.2

Muestra verificada para npm balanced-match 1.0.2. El contrato se ejecutó en node 22 · linux alpine/x64 · docker y pasó: balanced matches balanced delimiters…

sha256:6bac510a5d55404e7b6c840be79fb2fd1ce04c4f993a7fb4822cbe644fb42530

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

Caso

HOW
Objetivo
verify pkg:npm/balanced-match@1.0.2
Paquetes
Entorno
node 22.23.2
Creado
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

Archivos

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

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 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 origen

anónimo