CodeSampleX

Exemple

balanced-match 1.0.2

Échantillon vérifié pour npm balanced-match 1.0.2. Le contrat s'est exécuté sur node 22 · linux alpine/x64 · docker et a réussi.

sha256:6bac510a5d55404e7b6c840be79fb2fd1ce04c4f993a7fb4822cbe644fb42530

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
1
Clés de signature qui l’ont compilé
1
Environnement déclaré node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
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

Cas

HOW
Objectif
verify pkg:npm/balanced-match@1.0.2
Paquets
Environnement
node 22.23.2
Créé
2026-08-21T16:12:24Z

Contrat

  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

Fichiers

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

Télécharger l’artefact source (tar.gz)

Code source

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 d'origine

anonyme