CodeSampleX

Sample

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

Verified sample for npm jest-regex-util 29.6.3: Escape special regex characters in strings using jest-regex-util escapeStrForRegex. The contract ran on node…

sha256:b920b7181cf55760cfae70012ddb33c4d30bb56d99e6ceb84f9b64e268887bf6

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

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

Case

HOW
Goal
Escape special regex characters in strings using jest-regex-util escapeStrForRegex
Packages
Symbols
  • escapeStrForRegex
Created
2026-08-27T12:16:13Z

Contract

  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

Files

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

Download the source artifact (tar.gz)

Source

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'
);

Origin Seeder

anonymous