CodeSampleX

Пример

minimatch 3.1.5

Проверенный пример — npm minimatch 3.1.5. Контракт выполнен на node 22 · linux alpine/x64 · docker и пройден: minimatch(path, pattern, options) evaluates…

sha256:4af93dae25dfef5fe443dc4980ba7e494dd94162c6d09cfebcbfb6b8d5e5cf08

Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла. Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди. 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@1
2026-08-21

Кейс

HOW
Цель
verify pkg:npm/minimatch@3.1.5
Пакеты
Окружение
node 22.23.2
Создан
2026-08-21T03:42:03Z

Контракт

  1. minimatch(path, pattern, options) evaluates whether a string path matches a glob pattern with support for wildcards, globstars, brace expansion, and dot matching
  2. minimatch.match(list, pattern, options) filters a string array against a glob pattern returning only matching elements
  3. minimatch.filter(pattern, options) returns a predicate function compatible with Array.prototype.filter
  4. minimatch.makeRe(pattern, options) compiles a glob pattern into a regular expression instance
  5. minimatch.Minimatch class creates an instance with a pre-parsed pattern set and a match method for repeated testing

Файлы

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

Скачать артефакт с исходным кодом (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/minimatch@3.1.5
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/minimatch@3.1.5
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

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:0cfd4f6e7de56df4a85098c03922cb48dd607a153de7b3e3a50437f8f560cede","constraints":{"executionContext":"node"},"contract":["minimatch(path, pattern, options) evaluates whether a string path matches a glob pattern with support for wildcards, globstars, brace expansion, and dot matching","minimatch.match(list, pattern, options) filters a string array against a glob pattern returning only matching elements","minimatch.filter(pattern, options) returns a predicate function compatible with Array.prototype.filter","minimatch.makeRe(pattern, options) compiles a glob pattern into a regular expression instance","minimatch.Minimatch class creates an instance with a pre-parsed pattern set and a match method for repeated testing"],"goal":"verify pkg:npm/minimatch@3.1.5","kind":"HOW","packages":["pkg:npm/minimatch@3.1.5"],"schemaVersion":1},"contractCommand":["node","test/contract.js"],"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/minimatch@3.1.5"],"schemaVersion":1,"subject":"pkg:npm/minimatch@3.1.5","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-minimatch-verify",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-minimatch-verify",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "minimatch": "3.1.5"
      }
    },
    "node_modules/balanced-match": {
      "version": "1.0.2",
      "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
      "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==",
      "license": "MIT"
    },
    "node_modules/brace-expansion": {
      "version": "1.1.18",
      "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.18.tgz",
      "integrity": "sha512-Edep/X9fGqVNmzKBVsDYIOtD+z1tuezV70LBjdCst9Tqu76lsnvRiZ6oTic1n+/BIwX6QDGAO94PN4N2SADvtw==",
      "license": "MIT",
      "dependencies": {
        "balanced-match": "^1.0.0",
        "concat-map": "0.0.1"
      }
    },
    "node_modules/concat-map": {
      "version": "0.0.1",
      "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
      "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==",
      "license": "MIT"
    },
    "node_modules/minimatch": {
      "version": "3.1.5",
      "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.5.tgz",
      "integrity": "sha512-VgjWUsnnT6n+NUk6eZq77zeFdpW2LWDzP6zFGrCbHXiYNul5Dzqk2HHQ5uFH2DNW5Xbp8+jVzaeNt94ssEEl4w==",
      "license": "ISC",
      "dependencies": {
        "brace-expansion": "^1.1.7"
      },
      "engines": {
        "node": "*"
      }
    }
  }
}
package.json
{
  "name": "sample-minimatch-verify",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification sample for minimatch 3.1.5",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "minimatch": "3.1.5"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/minimatch@3.1.5",
  "kind": "HOW",
  "packages": [
    "pkg:npm/minimatch@3.1.5"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.js
const minimatch = require('minimatch');

/**
 * Matches a single path against a pattern with optional configuration.
 * @param {string} pathString
 * @param {string} pattern
 * @param {object} [options]
 * @returns {boolean}
 */
function matchPath(pathString, pattern, options) {
  return minimatch(pathString, pattern, options);
}

/**
 * Filters a list of paths using a glob pattern.
 * @param {string[]} list
 * @param {string} pattern
 * @param {object} [options]
 * @returns {string[]}
 */
function filterPaths(list, pattern, options) {
  return minimatch.match(list, pattern, options);
}

/**
 * Creates a filter predicate function for Array.prototype.filter.
 * @param {string} pattern
 * @param {object} [options]
 * @returns {(element: string, index: number, array: string[]) => boolean}
 */
function createFilterPredicate(pattern, options) {
  return minimatch.filter(pattern, options);
}

/**
 * Compiles a glob pattern into a regular expression.
 * @param {string} pattern
 * @param {object} [options]
 * @returns {RegExp|false}
 */
function compilePattern(pattern, options) {
  return minimatch.makeRe(pattern, options);
}

/**
 * Creates a reusable Minimatch instance.
 * @param {string} pattern
 * @param {object} [options]
 * @returns {minimatch.Minimatch}
 */
function createMatcher(pattern, options) {
  return new minimatch.Minimatch(pattern, options);
}

module.exports = {
  matchPath,
  filterPaths,
  createFilterPredicate,
  compilePattern,
  createMatcher
};
test/contract.js
const assert = require('node:assert');
const minimatch = require('minimatch');
const {
  matchPath,
  filterPaths,
  createFilterPredicate,
  compilePattern,
  createMatcher
} = require('../src/index.js');

// 1. Direct function and matchPath behavior: wildcards, globstars, brace expansions, options
assert.strictEqual(typeof minimatch, 'function', 'minimatch should be exported as a function');
assert.strictEqual(matchPath('foo.js', '*.js'), true, 'wildcard match should succeed');
assert.strictEqual(matchPath('src/utils/file.ts', '**/*.ts'), true, 'globstar match should succeed');
assert.strictEqual(matchPath('doc.pdf', '*.{js,ts,pdf}'), true, 'brace expansion should match');
assert.strictEqual(matchPath('README.MD', '*.md', { nocase: true }), true, 'nocase option should ignore case');
assert.strictEqual(matchPath('.hidden', '*', { dot: false }), false, 'dotfiles should not match * when dot is false');
assert.strictEqual(matchPath('.hidden', '*', { dot: true }), true, 'dotfiles should match * when dot is true');
assert.strictEqual(matchPath('foo/bar.js', '*.js'), false, 'wildcard should not match across slash without globstar');

// 2. minimatch.match filters an array of strings
const pathList = ['src/index.js', 'src/style.css', 'test/test.js', 'README.md', 'lib/sub/mod.js'];
const jsFiles = filterPaths(pathList, '**/*.js');
assert.deepStrictEqual(jsFiles, ['src/index.js', 'test/test.js', 'lib/sub/mod.js'], 'match should filter js files');
const cssFiles = minimatch.match(pathList, '*.css', { matchBase: true });
assert.deepStrictEqual(cssFiles, ['src/style.css'], 'match with matchBase should match basename');

// 3. minimatch.filter returns a predicate compatible with Array.prototype.filter
const predicate = createFilterPredicate('**/*.js');
assert.strictEqual(typeof predicate, 'function', 'filter should return a function');
const filtered = pathList.filter(predicate);
assert.deepStrictEqual(filtered, ['src/index.js', 'test/test.js', 'lib/sub/mod.js'], 'Array filter with predicate should match js files');

// 4. minimatch.makeRe compiles pattern into a RegExp
const regex = compilePattern('**/*.{json,yaml}');
assert.ok(regex instanceof RegExp, 'makeRe should return a RegExp instance');
assert.strictEqual(regex.test('config/app.json'), true, 'compiled regex should match valid path');
assert.strictEqual(regex.test('config/app.txt'), false, 'compiled regex should reject non-matching path');

// 5. minimatch.Minimatch class creation and matching
const matcher = createMatcher('build/**/*.min.js', { nocase: true });
assert.ok(matcher instanceof minimatch.Minimatch, 'createMatcher should return Minimatch instance');
assert.strictEqual(matcher.pattern, 'build/**/*.min.js', 'pattern property should match input');
assert.strictEqual(matcher.match('build/bundle.min.js'), true, 'matcher.match should match single directory depth');
assert.strictEqual(matcher.match('build/sub/dir/bundle.MIN.JS'), true, 'matcher.match should match nested path with nocase');
assert.strictEqual(matcher.match('src/bundle.min.js'), false, 'matcher.match should reject different prefix');

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

Исходный сидер

аноним