CodeSampleX

샘플

lodash.escaperegexp 4.1.2: escapeRegExp

검증된 샘플 — npm lodash.escaperegexp 4.1.2: escapeRegExp. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: escapeRegExp exports a function that…

sha256:8e56c58d990bebfbf887cb7666d7e0bb8722f650ce8101a26490df3fe32f3394

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

검증 실행 환경

환경 컨트랙트 단계 실행일
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

케이스

HOW
목표
verify pkg:npm/lodash.escaperegexp@4.1.2
패키지
심벌
  • escapeRegExp
  • lodash.escaperegexp
환경
node 22.23.2
생성일
2026-08-28T04:59:33Z

컨트랙트

  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

파일

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

소스 아티팩트 내려받기 (tar.gz)

소스

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

오리진 시더

익명