Пример
pathe 2.0.3: basename
Проверенный пример — npm pathe 2.0.3: basename. Контракт выполнен на node 22 · linux debian/x64 · docker и пройден: pathe.basename extracts the last portion…
sha256:9a61e1cea052e0b26db8099b519f01ba33667c51d46190d6b1f131f042ae559c
Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла.
Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди.
MIT-0
Свидетельства выполнения
Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.
- Основа свидетельства
- Подписанный контракт пройден
- Квитанции проверки
- 1
- Ключи подписи, собравшие его
- 1
Заявленная среда
linux 24 · ubuntu · glibc 2.39 x64 npm
Среды запусков проверки
| Окружение | Контракт | Этапы | Запуск |
|---|---|---|---|
| node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2… |
2026-09-04 |
Кейс
HOW- Цель
- verify pathe.basename in pkg:npm/pathe@2.0.3
- Пакеты
- Символы
-
- pathe.basename
- Создан
- 2026-09-04T13:16:30Z
Контракт
- pathe.basename extracts the last portion of a POSIX path
- pathe.basename strips a specified file extension or suffix from the filename
- pathe.basename normalizes Windows backslashes and extracts filename from Windows path
- pathe.basename handles trailing slashes by ignoring them and returning directory basename
- pathe.basename returns an empty string for root or empty path inputs
- pathe.basename returns the input unchanged when given a bare filename without path separators
Файлы
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.mjs
Исходный код
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 pathe.basename in pkg:npm/pathe@2.0.3
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/pathe@2.0.3
Demonstrate these symbols/APIs:
- pathe.basename
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.
{"case":{"caseId":"case:sha256:20de455ed2020fa60d7572d724464c7c313b9d4922b700588f51d7f5d9f03f00","contract":["pathe.basename extracts the last portion of a POSIX path","pathe.basename strips a specified file extension or suffix from the filename","pathe.basename normalizes Windows backslashes and extracts filename from Windows path","pathe.basename handles trailing slashes by ignoring them and returning directory basename","pathe.basename returns an empty string for root or empty path inputs","pathe.basename returns the input unchanged when given a bare filename without path separators"],"goal":"verify pathe.basename in pkg:npm/pathe@2.0.3","kind":"HOW","packages":["pkg:npm/pathe@2.0.3"],"schemaVersion":1,"symbols":["pathe.basename"]},"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/pathe@2.0.3"],"schemaVersion":1,"subject":"pkg:npm/pathe@2.0.3","symbols":["pathe.basename"],"verifierAdapter":"node-typescript@1"}
{
"name": "sample-pathe-basename",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-pathe-basename",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"pathe": "2.0.3"
}
},
"node_modules/pathe": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/pathe/-/pathe-2.0.3.tgz",
"integrity": "sha512-WUjGcAqP1gQacoQe+OBJsFA7Ld4DyXuUIjZ5cc75cLHvJ7dtNsTugphxIADwspS+AraAUePCKrSVtPLFj/F88w==",
"license": "MIT"
}
}
}
{
"name": "sample-pathe-basename",
"version": "1.0.0",
"private": true,
"description": "Clean-room verification of pathe.basename in pkg:npm/pathe@2.0.3",
"main": "src/index.js",
"license": "MIT-0",
"dependencies": {
"pathe": "2.0.3"
}
}
{
"schemaVersion": 1,
"goal": "verify pathe.basename in pkg:npm/pathe@2.0.3",
"kind": "HOW",
"packages": [
"pkg:npm/pathe@2.0.3"
],
"symbols": [
"pathe.basename"
]
}
const { basename } = require('pathe');
/**
* Returns the last portion of a path, similar to the Unix basename command.
* Trailing directory separators are ignored, and Windows backslashes are normalized to forward slashes.
*
* @param {string} path - The path to evaluate.
* @param {string} [ext] - An optional extension to remove from the result.
* @returns {string} The last portion of the given path.
*/
function getBasename(path, ext) {
return basename(path, ext);
}
/**
* Extracts the filename without the specified extension.
*
* @param {string} path - The path to evaluate.
* @param {string} ext - The extension to strip.
* @returns {string} The filename without extension.
*/
function getFilenameWithoutExtension(path, ext) {
return basename(path, ext);
}
module.exports = {
basename,
getBasename,
getFilenameWithoutExtension
};
import assert from 'node:assert';
import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
const { basename, getBasename, getFilenameWithoutExtension } = require('../src/index.js');
// 1. pathe.basename extracts the last portion of a POSIX path
assert.strictEqual(basename('/path/to/file.ext'), 'file.ext');
assert.strictEqual(basename('path/to/file.ext'), 'file.ext');
assert.strictEqual(basename('/a/b/c'), 'c');
assert.strictEqual(getBasename('/path/to/file.ext'), 'file.ext');
// 2. pathe.basename strips a specified file extension or suffix from the filename
assert.strictEqual(basename('/path/to/file.ext', '.ext'), 'file');
assert.strictEqual(basename('script.test.js', '.js'), 'script.test');
assert.strictEqual(basename('document.pdf', '.txt'), 'document.pdf');
assert.strictEqual(basename('/path/to/file.ext', 'ext'), 'file.');
assert.strictEqual(getFilenameWithoutExtension('/path/to/file.ext', '.ext'), 'file');
// 3. pathe.basename normalizes Windows backslashes and extracts filename from Windows path
assert.strictEqual(basename('foo\\bar\\file.txt'), 'file.txt');
assert.strictEqual(basename('dir\\subdir\\test.json'), 'test.json');
assert.strictEqual(basename('dir\\subdir\\test.json', '.json'), 'test');
assert.strictEqual(getBasename('foo\\bar\\file.txt'), 'file.txt');
// 4. pathe.basename handles trailing slashes by ignoring them and returning directory basename
assert.strictEqual(basename('/dir/subdir/'), 'subdir');
assert.strictEqual(basename('a/b/c/'), 'c');
assert.strictEqual(basename('dir\\subdir\\'), 'subdir');
assert.strictEqual(getBasename('/dir/subdir/'), 'subdir');
// 5. pathe.basename returns an empty string for root or empty path inputs
assert.strictEqual(basename(''), '');
assert.strictEqual(basename('/'), '');
assert.strictEqual(basename('///'), '');
assert.strictEqual(getBasename(''), '');
// 6. pathe.basename returns the input unchanged when given a bare filename without path separators
assert.strictEqual(basename('file.txt'), 'file.txt');
assert.strictEqual(basename('filename'), 'filename');
assert.strictEqual(getBasename('file.txt'), 'file.txt');
console.log('Contract tests passed successfully.');
Исходный сидер
аноним