CodeSampleX

Exemplo

regexpu-core 6.4.0

Amostra verificada para npm regexpu-core 6.4.0. O contrato rodou em node 22 · linux alpine/x64 · docker e passou: rewritePattern and helper functions are…

sha256:bdccce7c900003847790b9b6e2e2681586d4ae57d4ec57720d817d6acf2f1582

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

Caso

HOW
Objetivo
verify pkg:npm/regexpu-core@6.4.0
Pacotes
Ambiente
node 22.23.2
Criado
2026-08-27T20:49:26Z

Contrato

  1. rewritePattern and helper functions are exported as callable functions
  2. transformUnicodeProperties transforms unicode property escapes into character classes
  3. transformDotAll transforms dotAll flag s into pattern matching all characters including newlines
  4. transformNamedGroups transforms named capture groups and invokes onNamedGroup callback
  5. transformUnicodeSets transforms unicode sets v flag set operations into canonical character classes
  6. transformModifiers transforms inline modifier flags into standard regular expressions
  7. rewrite transforms regular expressions using custom transformation options

Arquivos

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • 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/regexpu-core@6.4.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/regexpu-core@6.4.0

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:e88c59d6cfb11b7a17d525559909586f939f07cf5fdd116d9b0f2f79ac5e8695","contract":["rewritePattern and helper functions are exported as callable functions","transformUnicodeProperties transforms unicode property escapes into character classes","transformDotAll transforms dotAll flag s into pattern matching all characters including newlines","transformNamedGroups transforms named capture groups and invokes onNamedGroup callback","transformUnicodeSets transforms unicode sets v flag set operations into canonical character classes","transformModifiers transforms inline modifier flags into standard regular expressions","rewrite transforms regular expressions using custom transformation options"],"goal":"verify pkg:npm/regexpu-core@6.4.0","kind":"HOW","packages":["pkg:npm/regexpu-core@6.4.0"],"schemaVersion":1},"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/regexpu-core@6.4.0"],"schemaVersion":1,"subject":"pkg:npm/regexpu-core@6.4.0","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-regexpu-core",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-regexpu-core",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "regexpu-core": "6.4.0"
      }
    },
    "node_modules/jsesc": {
      "version": "3.1.0",
      "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-3.1.0.tgz",
      "integrity": "sha512-/sM3dO2FOzXjKQhJuo0Q173wf2KOo8t4I8vHy6lF9poUp7bKT0/NHE8fPX23PwfhnykfqnC2xRxOnVw5XuGIaA==",
      "license": "MIT",
      "bin": {
        "jsesc": "bin/jsesc"
      },
      "engines": {
        "node": ">=6"
      }
    },
    "node_modules/regenerate": {
      "version": "1.4.2",
      "resolved": "https://registry.npmjs.org/regenerate/-/regenerate-1.4.2.tgz",
      "integrity": "sha512-zrceR/XhGYU/d/opr2EKO7aRHUeiBI8qjtfHqADTwZd6Szfy16la6kqD0MIUs5z5hx6AaKa+PixpPrR289+I0A==",
      "license": "MIT"
    },
    "node_modules/regenerate-unicode-properties": {
      "version": "10.2.2",
      "resolved": "https://registry.npmjs.org/regenerate-unicode-properties/-/regenerate-unicode-properties-10.2.2.tgz",
      "integrity": "sha512-m03P+zhBeQd1RGnYxrGyDAPpWX/epKirLrp8e3qevZdVkKtnCrjjWczIbYc8+xd6vcTStVlqfycTx1KR4LOr0g==",
      "license": "MIT",
      "dependencies": {
        "regenerate": "^1.4.2"
      },
      "engines": {
        "node": ">=4"
      }
    },
    "node_modules/regexpu-core": {
      "version": "6.4.0",
      "resolved": "https://registry.npmjs.org/regexpu-core/-/regexpu-core-6.4.0.tgz",
      "integrity": "sha512-0ghuzq67LI9bLXpOX/ISfve/Mq33a4aFRzoQYhnnok1JOFpmE/A2TBGkNVenOGEeSBCjIiWcc6MVOG5HEQv0sA==",
      "license": "MIT",
      "dependencies": {
        "regenerate": "^1.4.2",
        "regenerate-unicode-properties": "^10.2.2",
        "regjsgen": "^0.8.0",
        "regjsparser": "^0.13.0",
        "unicode-match-property-ecmascript": "^2.0.0",
        "unicode-match-property-value-ecmascript": "^2.2.1"
      },
      "engines": {
        "node": ">=4"
      }
    },
    "node_modules/regjsgen": {
      "version": "0.8.0",
      "resolved": "https://registry.npmjs.org/regjsgen/-/regjsgen-0.8.0.tgz",
      "integrity": "sha512-RvwtGe3d7LvWiDQXeQw8p5asZUmfU1G/l6WbUXeHta7Y2PEIvBTwH6E2EfmYUK8pxcxEdEmaomqyp0vZZ7C+3Q==",
      "license": "MIT"
    },
    "node_modules/regjsparser": {
      "version": "0.13.2",
      "resolved": "https://registry.npmjs.org/regjsparser/-/regjsparser-0.13.2.tgz",
      "integrity": "sha512-NgRBy2Nx/bE+9F27nVHnqcN5HjyLmecqsqx2PJHu3/IEtADD4WuxuXIVExD5PoSDFVrl78dOonfcOe5O+5nbzQ==",
      "license": "BSD-2-Clause",
      "dependencies": {
        "jsesc": "~3.1.0"
      },
      "bin": {
        "regjsparser": "bin/parser"
      }
    },
    "node_modules/unicode-canonical-property-names-ecmascript": {
      "version": "2.0.1",
      "resolved": "https://registry.npmjs.org/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-2.0.1.tgz",
      "integrity": "sha512-dA8WbNeb2a6oQzAQ55YlT5vQAWGV9WXOsi3SskE3bcCdM0P4SDd+24zS/OCacdRq5BkdsRj9q3Pg6YyQoxIGqg==",
      "license": "MIT",
      "engines": {
        "node": ">=4"
      }
    },
    "node_modules/unicode-match-property-ecmascript": {
      "version": "2.0.0",
      "resolved": "https://registry.npmjs.org/unicode-match-property-ecmascript/-/unicode-match-property-ecmascript-2.0.0.tgz",
      "integrity": "sha512-5kaZCrbp5mmbz5ulBkDkbY0SsPOjKqVS35VpL9ulMPfSl0J0Xsm+9Evphv9CoIZFwre7aJoa94AY6seMKGVN5Q==",
      "license": "MIT",
      "dependencies": {
        "unicode-canonical-property-names-ecmascript": "^2.0.0",
        "unicode-property-aliases-ecmascript": "^2.0.0"
      },
      "engines": {
        "node": ">=4"
      }
    },
    "node_modules/unicode-match-property-value-ecmascript": {
      "version": "2.2.1",
      "resolved": "https://registry.npmjs.org/unicode-match-property-value-ecmascript/-/unicode-match-property-value-ecmascript-2.2.1.tgz",
      "integrity": "sha512-JQ84qTuMg4nVkx8ga4A16a1epI9H6uTXAknqxkGF/aFfRLw1xC/Bp24HNLaZhHSkWd3+84t8iXnp1J0kYcZHhg==",
      "license": "MIT",
      "engines": {
        "node": ">=4"
      }
    },
    "node_modules/unicode-property-aliases-ecmascript": {
      "version": "2.2.0",
      "resolved": "https://registry.npmjs.org/unicode-property-aliases-ecmascript/-/unicode-property-aliases-ecmascript-2.2.0.tgz",
      "integrity": "sha512-hpbDzxUY9BFwX+UeBnxv3Sh1q7HFxj48DTmXchNgRa46lO8uj3/1iEn3MiNUYTg1g9ctIqXCCERn8gYZhHC5lQ==",
      "license": "MIT",
      "engines": {
        "node": ">=4"
      }
    }
  }
}
package.json
{
  "name": "sample-regexpu-core",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of regexpu-core",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "regexpu-core": "6.4.0"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/regexpu-core@6.4.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/regexpu-core@6.4.0"
  ]
}
src/index.js
const rewritePatternModule = require('regexpu-core');
const rewritePattern = typeof rewritePatternModule === 'function' ? rewritePatternModule : rewritePatternModule.default;

/**
 * Rewrites a regular expression pattern using regexpu-core.
 * @param {string} pattern - The regular expression pattern string.
 * @param {string} [flags=''] - Regular expression flags (e.g., 'u', 's', 'v').
 * @param {object} [options={}] - Transformation options.
 * @returns {string} The transformed pattern string.
 */
function rewrite(pattern, flags = '', options = {}) {
  return rewritePattern(pattern, flags, options);
}

/**
 * Transforms Unicode property escapes (\p{...} / \P{...}) into character classes.
 * @param {string} pattern - Pattern containing unicode property escapes.
 * @param {string} [flags='u'] - Regular expression flags.
 * @returns {string} The transformed pattern.
 */
function transformUnicodeProperties(pattern, flags = 'u') {
  return rewritePattern(pattern, flags, {
    unicodePropertyEscapes: 'transform'
  });
}

/**
 * Transforms dotAll flag (s) into character classes that match any character including newlines.
 * @param {string} pattern - Pattern containing dot.
 * @returns {string} The transformed pattern.
 */
function transformDotAll(pattern) {
  return rewritePattern(pattern, 's', {
    dotAllFlag: 'transform'
  });
}

/**
 * Transforms named capture groups into numbered groups, tracking captured names and indices.
 * @param {string} pattern - Pattern with named capture groups.
 * @param {function} [onNamedGroup] - Callback invoked with (name, index).
 * @returns {string} The transformed pattern.
 */
function transformNamedGroups(pattern, onNamedGroup) {
  return rewritePattern(pattern, '', {
    namedGroups: 'transform',
    onNamedGroup
  });
}

/**
 * Transforms unicode sets flag (v) expressions such as set intersections and differences.
 * @param {string} pattern - Pattern with unicode set expressions.
 * @returns {string} The transformed pattern.
 */
function transformUnicodeSets(pattern) {
  return rewritePattern(pattern, 'v', {
    unicodeSetsFlag: 'transform'
  });
}

/**
 * Transforms inline modifier flags like (?i:...) into standard regular expressions.
 * @param {string} pattern - Pattern containing inline modifiers.
 * @returns {string} The transformed pattern.
 */
function transformModifiers(pattern) {
  return rewritePattern(pattern, '', {
    modifiers: 'transform'
  });
}

module.exports = {
  rewritePattern,
  rewrite,
  transformUnicodeProperties,
  transformDotAll,
  transformNamedGroups,
  transformUnicodeSets,
  transformModifiers
};
test/contract.mjs
import assert from 'node:assert';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const {
  rewritePattern,
  rewrite,
  transformUnicodeProperties,
  transformDotAll,
  transformNamedGroups,
  transformUnicodeSets,
  transformModifiers
} = require('../src/index.js');

// 1. Function exports verification
assert.strictEqual(typeof rewritePattern, 'function', 'rewritePattern should be a function');
assert.strictEqual(typeof rewrite, 'function', 'rewrite should be a function');
assert.strictEqual(typeof transformUnicodeProperties, 'function', 'transformUnicodeProperties should be a function');
assert.strictEqual(typeof transformDotAll, 'function', 'transformDotAll should be a function');
assert.strictEqual(typeof transformNamedGroups, 'function', 'transformNamedGroups should be a function');
assert.strictEqual(typeof transformUnicodeSets, 'function', 'transformUnicodeSets should be a function');
assert.strictEqual(typeof transformModifiers, 'function', 'transformModifiers should be a function');

// 2. Unicode property escapes transformation
const asciiPattern = transformUnicodeProperties('\\p{ASCII}');
assert.strictEqual(typeof asciiPattern, 'string', 'asciiPattern should be a string');
assert.ok(asciiPattern.length > 0, 'asciiPattern should not be empty');
assert.strictEqual(new RegExp(asciiPattern).test('A'), true);
assert.strictEqual(new RegExp(asciiPattern).test('9'), true);
assert.strictEqual(new RegExp(asciiPattern).test('~'), true);
assert.strictEqual(new RegExp(asciiPattern).test('\u00e9'), false);

const greekPattern = transformUnicodeProperties('\\p{Script=Greek}');
assert.ok(greekPattern.length > 0, 'Greek unicode property should produce valid pattern');
assert.strictEqual(new RegExp(greekPattern, 'u').test('\u03b1'), true);
assert.strictEqual(new RegExp(greekPattern, 'u').test('z'), false);

// 3. DotAll flag (s) transformation
const dotAllTransformed = transformDotAll('start.*end');
assert.strictEqual(dotAllTransformed, 'start[^]*end', 'dotAll flag s should rewrite dot to [^]');
assert.strictEqual(new RegExp(dotAllTransformed).test('start\nmultiline\nend'), true);

// 4. Named capture groups transformation and onNamedGroup callback
const capturedGroups = [];
const namedTransformed = transformNamedGroups('(?<year>\\d{4})-(?<month>\\d{2})-(?<day>\\d{2})', (name, index) => {
  capturedGroups.push({ name, index });
});
assert.strictEqual(namedTransformed, '(\\d{4})-(\\d{2})-(\\d{2})', 'named capture groups should be converted to standard capture groups');
assert.deepStrictEqual(capturedGroups, [
  { name: 'year', index: 1 },
  { name: 'month', index: 2 },
  { name: 'day', index: 3 }
]);
const match = '2026-08-28'.match(new RegExp(namedTransformed));
assert.ok(match);
assert.strictEqual(match[1], '2026');
assert.strictEqual(match[2], '08');
assert.strictEqual(match[3], '28');

// 5. Unicode sets flag (v) transformation
const vTransformed = transformUnicodeSets('[\\p{ASCII}&&[a-z]]');
assert.strictEqual(vTransformed, '[a-z]', 'unicode set intersection should produce intersection class');
assert.strictEqual(new RegExp(vTransformed, 'u').test('m'), true);
assert.strictEqual(new RegExp(vTransformed, 'u').test('M'), false);
assert.strictEqual(new RegExp(vTransformed, 'u').test('9'), false);

// 6. Inline modifier flags transformation
const modTransformed = transformModifiers('(?i:foo)bar');
assert.strictEqual(new RegExp(modTransformed).test('FOObar'), true);
assert.strictEqual(new RegExp(modTransformed).test('fooBAR'), false);

// 7. General rewrite function with custom options
const customTransformed = rewrite('(?<tag>#[a-zA-Z]+)', '', { namedGroups: 'transform' });
assert.strictEqual(customTransformed, '(#[a-zA-Z]+)');

console.log('Contract tests passed successfully.');

Seeder de origem

anônimo