サンプル
pathe 2.0.3: basename
検証済みサンプル — npm pathe 2.0.3: basename. node 22 · linux debian/x64 · docker で contract を実行し、成功しました: pathe.basename extracts the last portion of a POSIX path
sha256:9a61e1cea052e0b26db8099b519f01ba33667c51d46190d6b1f131f042ae559c
このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。
合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。
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.');
オリジンシーダー
匿名