CodeSampleX

Exemple

pathe 2.0.3: basename

Échantillon vérifié pour npm pathe 2.0.3: basename. Le contrat s'est exécuté sur node 22 · linux debian/x64 · docker et a réussi.

sha256:9a61e1cea052e0b26db8099b519f01ba33667c51d46190d6b1f131f042ae559c

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
1
Clés de signature qui l’ont compilé
1
Environnement déclaré linux 24 · ubuntu · glibc 2.39 x64 npm

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
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

Cas

HOW
Objectif
verify pathe.basename in pkg:npm/pathe@2.0.3
Paquets
Symboles
  • pathe.basename
Créé
2026-09-04T13:16:30Z

Contrat

  1. pathe.basename extracts the last portion of a POSIX path
  2. pathe.basename strips a specified file extension or suffix from the filename
  3. pathe.basename normalizes Windows backslashes and extracts filename from Windows path
  4. pathe.basename handles trailing slashes by ignoring them and returning directory basename
  5. pathe.basename returns an empty string for root or empty path inputs
  6. pathe.basename returns the input unchanged when given a bare filename without path separators

Fichiers

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

Télécharger l’artefact source (tar.gz)

Code source

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 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.
csx.json
{"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"}
package-lock.json
{
  "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"
    }
  }
}
package.json
{
  "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"
  }
}
spec.json
{
  "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"
  ]
}
src/index.js
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
};
test/contract.mjs
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.');

Seeder d'origine

anonyme