CodeSampleX

Ejemplo

jest-regex-util 29.6.3: Escape special regex characters in strings using jest-regex-util escapeStrForRegex

Muestra verificada para npm jest-regex-util 29.6.3: Escape special regex characters in strings using jest-regex-util escapeStrForRegex. El contrato se…

sha256:b920b7181cf55760cfae70012ddb33c4d30bb56d99e6ceb84f9b64e268887bf6

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 linux 24 · ubuntu · glibc 2.39 x64 npm

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

Caso

HOW
Objetivo
Escape special regex characters in strings using jest-regex-util escapeStrForRegex
Paquetes
Símbolos
  • escapeStrForRegex
Creado
2026-08-27T12:16:13Z

Contrato

  1. escapeStrForRegex escapes all regular expression metacharacters with backslashes
  2. escapeStrForRegex escapes metacharacters within complex strings
  3. RegExp constructed from escaped string matches original string verbatim
  4. escapeStrForRegex leaves strings without metacharacters unchanged

Archivos

  • NOTES.md
  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • test/contract.mjs

Descargar el artefacto de código fuente (tar.gz)

Código fuente

NOTES.md
This contract measures the behavior of `escapeStrForRegex` from `jest-regex-util@29.6.3`.

It asserts that all regular expression metacharacters (`[`, `]`, `{`, `}`, `(`, `)`, `*`, `+`, `?`, `.`, `\`, `^`, `$`, `|`) are escaped with a preceding backslash, ensuring that a `RegExp` constructed from the escaped string matches the input literally and that strings without metacharacters remain unaltered.
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: Escape special regex characters in strings using jest-regex-util escapeStrForRegex
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/jest-regex-util@29.6.3

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:69989df27f1634f0c0746fd2266584db02eed2d70cd465620d2bcdeb21b0d90a","contract":["escapeStrForRegex escapes all regular expression metacharacters with backslashes","escapeStrForRegex escapes metacharacters within complex strings","RegExp constructed from escaped string matches original string verbatim","escapeStrForRegex leaves strings without metacharacters unchanged"],"goal":"Escape special regex characters in strings using jest-regex-util escapeStrForRegex","kind":"HOW","packages":["pkg:npm/jest-regex-util@29.6.3"],"schemaVersion":1,"symbols":["escapeStrForRegex"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/jest-regex-util@29.6.3"],"schemaVersion":1,"subject":"pkg:npm/jest-regex-util@29.6.3","symbols":["escapeStrForRegex"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-jest-regex-util",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-jest-regex-util",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "jest-regex-util": "29.6.3"
      }
    },
    "node_modules/jest-regex-util": {
      "version": "29.6.3",
      "resolved": "https://registry.npmjs.org/jest-regex-util/-/jest-regex-util-29.6.3.tgz",
      "integrity": "sha512-KJJBsRCyyLNWCNBOvZyRDnAIfUiRJ8v+hOBQYGn8gDyF3UegwiP4gwRR3/SDa42g1YbVycTidUF3rKjyLFDWbg==",
      "license": "MIT",
      "engines": {
        "node": "^14.15.0 || ^16.10.0 || >=18.0.0"
      }
    }
  }
}
package.json
{
  "name": "sample-jest-regex-util",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "license": "MIT-0",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "jest-regex-util": "29.6.3"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "Escape special regex characters in strings using jest-regex-util escapeStrForRegex",
  "kind": "HOW",
  "packages": [
    "pkg:npm/jest-regex-util@29.6.3"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import { escapeStrForRegex } from 'jest-regex-util';

// 1. Assert each special regex character is escaped with a backslash
const metacharacters = ['[', ']', '{', '}', '(', ')', '*', '+', '?', '.', '\\', '^', '$', '|'];
for (const char of metacharacters) {
  assert.equal(
    escapeStrForRegex(char),
    `\\${char}`,
    `escapeStrForRegex should escape regular expression character: ${char}`
  );
}

// 2. Assert escapeStrForRegex escapes all metacharacters within a complex string
const complexInput = 'resource (v1.0) [dev] *+?^$|{}';
const escaped = escapeStrForRegex(complexInput);
assert.equal(
  escaped,
  'resource \\(v1\\.0\\) \\[dev\\] \\*\\+\\?\\^\\$\\|\\{\\}',
  'escapeStrForRegex should escape all regex metacharacters in a complex string'
);

// 3. Assert RegExp constructed from escaped string matches the original string literally
const pattern = new RegExp(`^${escaped}$`);
assert.ok(
  pattern.test(complexInput),
  'RegExp compiled from escaped string must match original string verbatim'
);

// 4. Assert strings without regex metacharacters are unchanged
const alphanumeric = 'standard_filename-123';
assert.equal(
  escapeStrForRegex(alphanumeric),
  alphanumeric,
  'escapeStrForRegex should not modify strings without regex metacharacters'
);

Seeder de origen

anónimo