CodeSampleX

サンプル

pathe 2.0.3: parse

検証済みサンプル — npm pathe 2.0.3: parse. node 22 · linux debian/x64 · docker で contract を実行し、成功しました: pathe.parse parses a POSIX absolute path into root, dir, base…

sha256:96378e6ef3133cb4663ccad17a647417c1183527c624c4d3b3ebcc141dc7e745

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 MIT-0

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
1
ビルドした署名鍵
1
宣言された環境 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

検証実行環境

環境 コントラクト ステージ 実行日
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.parse in pkg:npm/pathe@2.0.3
パッケージ
シンボル
  • pathe.parse
環境
node 22.23.2
作成日
2026-09-04T23:07:21Z

コントラクト

  1. pathe.parse parses a POSIX absolute path into root, dir, base, ext, and name components
  2. pathe.parse extracts file extension and base name correctly for single and multiple dots
  3. pathe.parse normalizes Windows backslashes extracting base name and extension
  4. pathe.parse parses relative file paths and single filenames with current directory fallback
  5. pathe.parse parses root path and empty path with appropriate component fallbacks
  6. pathe.parse handles directory paths with trailing slashes extracting directory basename

ファイル

  • 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 pathe.parse 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.parse
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:36280dbb87420b2207d5c00cfcaf239a1f400bec69ed25184ef42509c5a82b40","constraints":{"executionContext":"node"},"contract":["pathe.parse parses a POSIX absolute path into root, dir, base, ext, and name components","pathe.parse extracts file extension and base name correctly for single and multiple dots","pathe.parse normalizes Windows backslashes extracting base name and extension","pathe.parse parses relative file paths and single filenames with current directory fallback","pathe.parse parses root path and empty path with appropriate component fallbacks","pathe.parse handles directory paths with trailing slashes extracting directory basename"],"goal":"verify pathe.parse in pkg:npm/pathe@2.0.3","kind":"HOW","packages":["pkg:npm/pathe@2.0.3"],"schemaVersion":1,"symbols":["pathe.parse"]},"contractCommand":["node","test/contract.mjs"],"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/pathe@2.0.3"],"schemaVersion":1,"subject":"pkg:npm/pathe@2.0.3","symbols":["pathe.parse"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-pathe-parse",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-pathe-parse",
      "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-parse",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of pathe.parse 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.parse in pkg:npm/pathe@2.0.3",
  "kind": "HOW",
  "packages": [
    "pkg:npm/pathe@2.0.3"
  ],
  "symbols": [
    "pathe.parse"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.js
const { parse } = require('pathe');

/**
 * Parses a path string into an object with root, dir, base, ext, and name properties.
 * Normalizes Windows-style backslashes to forward slashes.
 *
 * @param {string} path - The path string to parse.
 * @returns {object} Object representing the path components.
 */
function parsePath(path) {
  return parse(path);
}

module.exports = {
  parse,
  parsePath
};
test/contract.mjs
import assert from 'node:assert';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const { parse, parsePath } = require('../src/index.js');

// 1. pathe.parse parses a POSIX absolute path into root, dir, base, ext, and name components
{
  const parsed = parse('/path/to/file.ext');
  assert.strictEqual(parsed.root, '/');
  assert.strictEqual(parsed.dir, '/path/to');
  assert.strictEqual(parsed.base, 'file.ext');
  assert.strictEqual(parsed.ext, '.ext');
  assert.strictEqual(parsed.name, 'file');

  const wrapper = parsePath('/a/b/c.txt');
  assert.strictEqual(wrapper.root, '/');
  assert.strictEqual(wrapper.dir, '/a/b');
  assert.strictEqual(wrapper.base, 'c.txt');
  assert.strictEqual(wrapper.ext, '.txt');
  assert.strictEqual(wrapper.name, 'c');
}

// 2. pathe.parse extracts file extension and base name correctly for single and multiple dots
{
  const multiDot = parse('archive.tar.gz');
  assert.strictEqual(multiDot.base, 'archive.tar.gz');
  assert.strictEqual(multiDot.ext, '.gz');
  assert.strictEqual(multiDot.name, 'archive.tar');

  const noExt = parse('/a/b/c');
  assert.strictEqual(noExt.base, 'c');
  assert.strictEqual(noExt.ext, '');
  assert.strictEqual(noExt.name, 'c');

  const dotfile = parse('.gitignore');
  assert.strictEqual(dotfile.base, '.gitignore');
  assert.strictEqual(dotfile.ext, '');
  assert.strictEqual(dotfile.name, '.gitignore');
}

// 3. pathe.parse normalizes Windows backslashes extracting base name and extension
{
  const winPath = parse('foo\\bar\\file.txt');
  assert.strictEqual(winPath.base, 'file.txt');
  assert.strictEqual(winPath.ext, '.txt');
  assert.strictEqual(winPath.name, 'file');

  const winSubdir = parse('dir\\subdir\\test.json');
  assert.strictEqual(winSubdir.base, 'test.json');
  assert.strictEqual(winSubdir.ext, '.json');
  assert.strictEqual(winSubdir.name, 'test');
}

// 4. pathe.parse parses relative file paths and single filenames with current directory fallback
{
  const relPath = parse('src/components/button.jsx');
  assert.strictEqual(relPath.root, '');
  assert.strictEqual(relPath.dir, 'src/components');
  assert.strictEqual(relPath.base, 'button.jsx');
  assert.strictEqual(relPath.ext, '.jsx');
  assert.strictEqual(relPath.name, 'button');

  const bareFile = parse('index.js');
  assert.strictEqual(bareFile.root, '');
  assert.strictEqual(bareFile.dir, '.');
  assert.strictEqual(bareFile.base, 'index.js');
  assert.strictEqual(bareFile.ext, '.js');
  assert.strictEqual(bareFile.name, 'index');
}

// 5. pathe.parse parses root path and empty path with appropriate component fallbacks
{
  const rootPath = parse('/');
  assert.strictEqual(rootPath.root, '/');
  assert.strictEqual(rootPath.dir, '/');
  assert.strictEqual(rootPath.base, '');
  assert.strictEqual(rootPath.ext, '');
  assert.strictEqual(rootPath.name, '');

  const emptyPath = parse('');
  assert.strictEqual(emptyPath.root, '');
  assert.strictEqual(emptyPath.dir, '.');
  assert.strictEqual(emptyPath.base, '');
  assert.strictEqual(emptyPath.ext, '');
  assert.strictEqual(emptyPath.name, '');
}

// 6. pathe.parse handles directory paths with trailing slashes extracting directory basename
{
  const trailingSlash = parse('/dir/subdir/');
  assert.strictEqual(trailingSlash.root, '/');
  assert.strictEqual(trailingSlash.dir, '/dir');
  assert.strictEqual(trailingSlash.base, 'subdir');
  assert.strictEqual(trailingSlash.ext, '');
  assert.strictEqual(trailingSlash.name, 'subdir');
}

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

オリジンシーダー

匿名