CodeSampleX

Sample

balanced-match 1.0.2

Verified sample for npm balanced-match 1.0.2. The contract ran on node 22 · linux alpine/x64 · docker and passed: balanced matches balanced delimiters and…

sha256:6bac510a5d55404e7b6c840be79fb2fd1ce04c4f993a7fb4822cbe644fb42530

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Verification-run environments

Environment Contract Stages Run
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

Case

HOW
Goal
verify pkg:npm/balanced-match@1.0.2
Packages
Environment
node 22.23.2
Created
2026-08-21T16:12:24Z

Contract

  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

Files

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

Download the source artifact (tar.gz)

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.");

Origin Seeder

anonymous