CodeSampleX

Exemple

lodash.escaperegexp 4.1.2: escapeRegExp

Échantillon vérifié pour npm lodash.escaperegexp 4.1.2: escapeRegExp. Le contrat s'est exécuté sur node 22 · linux alpine/x64 · docker et a réussi.

sha256:8e56c58d990bebfbf887cb7666d7e0bb8722f650ce8101a26490df3fe32f3394

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@1node:22-alpine@sha256:c610fcdfb1d5…
2026-08-28

Cas

HOW
Objectif
verify pkg:npm/lodash.escaperegexp@4.1.2
Paquets
Symboles
  • escapeRegExp
  • lodash.escaperegexp
Environnement
node 22.23.2
Créé
2026-08-28T04:59:33Z

Contrat

  1. escapeRegExp exports a function that escapes RegExp special characters
  2. escapeRegExp escapes all 14 standard RegExp syntax characters \ ^ $ . * + ? ( ) [ ] { } |
  3. escapeRegExp preserves regular strings and characters that do not require escaping
  4. escapeRegExp converts null and undefined to empty strings
  5. escapeRegExp converts numbers and other non-string primitives to strings
  6. createExactMatcher creates regular expressions matching exact literal text with special characters

Fichiers

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

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/lodash.escaperegexp@4.1.2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/lodash.escaperegexp@4.1.2
Demonstrate these symbols/APIs:
  - escapeRegExp
  - lodash.escaperegexp

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:29ad9274f6925f71663673fa3c619b9376a3a2e082f37cfbb6a8cafddc942ea1","contract":["escapeRegExp exports a function that escapes RegExp special characters","escapeRegExp escapes all 14 standard RegExp syntax characters \\ ^ $ . * + ? ( ) [ ] { } |","escapeRegExp preserves regular strings and characters that do not require escaping","escapeRegExp converts null and undefined to empty strings","escapeRegExp converts numbers and other non-string primitives to strings","createExactMatcher creates regular expressions matching exact literal text with special characters"],"goal":"verify pkg:npm/lodash.escaperegexp@4.1.2","kind":"HOW","packages":["pkg:npm/lodash.escaperegexp@4.1.2"],"schemaVersion":1,"symbols":["escapeRegExp","lodash.escaperegexp"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"esm","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/lodash.escaperegexp@4.1.2"],"schemaVersion":1,"subject":"pkg:npm/lodash.escaperegexp@4.1.2","symbols":["escapeRegExp","lodash.escaperegexp"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-lodash-escaperegexp",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-lodash-escaperegexp",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "lodash.escaperegexp": "4.1.2"
      }
    },
    "node_modules/lodash.escaperegexp": {
      "version": "4.1.2",
      "resolved": "https://registry.npmjs.org/lodash.escaperegexp/-/lodash.escaperegexp-4.1.2.tgz",
      "integrity": "sha512-TM9YBvyC84ZxE3rgfefxUWiQKLilstD6k7PTGt6wfbtXF8ixIJLOL3VYyV/z+ZiPLsVxAsKAFVwWlWeb2Y8Yyw==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-lodash-escaperegexp",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of lodash.escaperegexp special character escaping",
  "type": "module",
  "main": "src/index.js",
  "license": "MIT-0",
  "dependencies": {
    "lodash.escaperegexp": "4.1.2"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/lodash.escaperegexp@4.1.2",
  "kind": "HOW",
  "packages": [
    "pkg:npm/lodash.escaperegexp@4.1.2"
  ],
  "symbols": [
    "escapeRegExp",
    "lodash.escaperegexp"
  ]
}
src/index.js
import escapeRegExp from 'lodash.escaperegexp';

/**
 * Escapes RegExp special characters in a string so it can be safely used in a RegExp constructor.
 *
 * @param {string} string - The string to escape.
 * @returns {string} The escaped string.
 */
export function escapePattern(string) {
  return escapeRegExp(string);
}

/**
 * Creates a regular expression that matches the exact literal string.
 *
 * @param {string} literal - The exact literal string to match.
 * @param {string} [flags=''] - Optional RegExp flags.
 * @returns {RegExp} RegExp matching the exact string.
 */
export function createExactMatcher(literal, flags = '') {
  return new RegExp(escapeRegExp(literal), flags);
}

export { escapeRegExp };
export default escapeRegExp;
test/contract.mjs
import assert from 'node:assert/strict';
import { escapeRegExp, escapePattern, createExactMatcher } from '../src/index.js';

// 1. escapeRegExp exports a function that escapes RegExp special characters
assert.equal(typeof escapeRegExp, 'function', 'escapeRegExp should be a function');
assert.equal(typeof escapePattern, 'function', 'escapePattern helper should be a function');
assert.equal(typeof createExactMatcher, 'function', 'createExactMatcher helper should be a function');

// 2. escapeRegExp escapes all 14 standard RegExp syntax characters \ ^ $ . * + ? ( ) [ ] { } |
const specialChars = '\\^$.*+?()[]{}|';
const expectedEscaped = '\\\\\\^\\$\\.\\*\\+\\?\\(\\)\\[\\]\\{\\}\\|';
assert.equal(escapeRegExp(specialChars), expectedEscaped, 'all special characters must be preceded by a backslash');
assert.equal(escapePattern('[lodash](https://example.com/)'), '\\[lodash\\]\\(https://example\\.com/\\)');

// 3. escapeRegExp preserves regular strings and characters that do not require escaping
assert.equal(escapeRegExp('hello world 123'), 'hello world 123', 'alphanumeric text without special characters should remain unchanged');
assert.equal(escapeRegExp(''), '', 'empty string should return empty string');
assert.equal(escapeRegExp('abc_def-ghi'), 'abc_def-ghi', 'regular punctuation like underscore and hyphen should not be escaped');

// 4. escapeRegExp converts null and undefined to empty strings
assert.equal(escapeRegExp(null), '', 'null input should return empty string');
assert.equal(escapeRegExp(undefined), '', 'undefined input should return empty string');

// 5. escapeRegExp converts numbers and other non-string primitives to strings
assert.equal(escapeRegExp(42), '42', 'number should be converted to string');
assert.equal(escapeRegExp(0), '0', 'zero should be converted to string');
assert.equal(escapeRegExp(-0), '-0', 'negative zero should preserve sign');
assert.equal(escapeRegExp(true), 'true', 'boolean should be converted to string');

// 6. createExactMatcher creates regular expressions matching exact literal text with special characters
const literalText = 'Item: [Special $10.00] (Discount: 20% + 5% bonus?)';
const matcher = createExactMatcher(literalText);
assert.ok(matcher instanceof RegExp, 'matcher should be an instance of RegExp');
assert.equal(matcher.test(literalText), true, 'matcher should match the exact literal string');
assert.equal(matcher.test('Item: Special $10.00'), false, 'matcher should not match text missing escaped brackets');

const textWithTarget = 'Start of text. ' + literalText + ' End of text.';
const matches = textWithTarget.match(createExactMatcher(literalText, 'g'));
assert.equal(matches?.length, 1, 'should find exactly one match in larger string');
assert.equal(matches?.[0], literalText, 'matched text should equal the literal text');

console.log('All lodash.escaperegexp contract tests passed successfully.');

Seeder d'origine

anonyme