CodeSampleX

Beispiel

uuid 8.3.2: parse

Verifiziertes Beispiel für npm uuid 8.3.2: parse. Der Vertrag lief auf node 22 · linux debian/x64 · docker und bestand: assert require('uuid').parse is…

sha256:4102ff5758b0265a4e0c0a017aefcb3afee9ca10ee0f619217e2acbcf999ee10

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
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-11-22

Fall

HOW
Ziel
verify uuid.parse in pkg:npm/uuid@8.3.2
Pakete
Symbole
  • uuid.parse
Umgebung
node 22.23.2
Erstellt
2026-11-22T15:53:16Z

Contract

  1. assert require('uuid').parse is exported as a function in CommonJS
  2. assert uuid.parse converts a canonical lowercase UUID string into an exact 16-byte Uint8Array
  3. assert uuid.parse treats uppercase and mixed-case UUID strings identically to lowercase
  4. assert uuid.parse converts the nil UUID 00000000-0000-0000-0000-000000000000 into 16 zero bytes
  5. assert uuid.parse throws TypeError('Invalid UUID') for malformed strings, missing hyphens, non-hex characters, wrong lengths, and non-string inputs

Dateien

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

Quellartefakt herunterladen (tar.gz)

Quelltext

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 uuid.parse in pkg:npm/uuid@8.3.2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/uuid@8.3.2
Demonstrate these symbols/APIs:
  - uuid.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:4ea9fe8fc75484b82259a5a106653ea72a48b3cac4e0f1d9b4c465f4a6376953","constraints":{"executionContext":"node"},"contract":["assert require('uuid').parse is exported as a function in CommonJS","assert uuid.parse converts a canonical lowercase UUID string into an exact 16-byte Uint8Array","assert uuid.parse treats uppercase and mixed-case UUID strings identically to lowercase","assert uuid.parse converts the nil UUID 00000000-0000-0000-0000-000000000000 into 16 zero bytes","assert uuid.parse throws TypeError('Invalid UUID') for malformed strings, missing hyphens, non-hex characters, wrong lengths, and non-string inputs"],"goal":"verify uuid.parse in pkg:npm/uuid@8.3.2","kind":"HOW","packages":["pkg:npm/uuid@8.3.2"],"schemaVersion":1,"symbols":["uuid.parse"]},"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/uuid@8.3.2"],"schemaVersion":1,"subject":"pkg:npm/uuid@8.3.2","symbols":["uuid.parse"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "uuid-parse-sample",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "uuid-parse-sample",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "uuid": "8.3.2"
      }
    },
    "node_modules/uuid": {
      "version": "8.3.2",
      "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
      "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==",
      "deprecated": "uuid@10 and below is no longer supported.  For ESM codebases, update to uuid@latest.  For CommonJS codebases, use uuid@11 (but be aware this version will likely be deprecated in 2028).",
      "license": "MIT",
      "bin": {
        "uuid": "dist/bin/uuid"
      }
    }
  }
}
package.json
{
  "name": "uuid-parse-sample",
  "version": "1.0.0",
  "private": true,
  "description": "Minimal CommonJS sample verifying uuid.parse in uuid@8.3.2",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "license": "MIT-0",
  "dependencies": {
    "uuid": "8.3.2"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify uuid.parse in pkg:npm/uuid@8.3.2",
  "kind": "HOW",
  "packages": [
    "pkg:npm/uuid@8.3.2"
  ],
  "symbols": [
    "uuid.parse"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.js
'use strict';

const { parse } = require('uuid');

/**
 * Parse a UUID string into its 16-byte Uint8Array representation using uuid.parse.
 * Throws TypeError when the input is not a valid UUID string.
 *
 * @param {string} value
 * @returns {Uint8Array}
 */
function parseUuidBytes(value) {
  return parse(value);
}

/**
 * Format a 16-byte Uint8Array back into canonical lowercase hyphenated UUID text
 * without relying on extra helpers.
 *
 * @param {Uint8Array} bytes
 * @returns {string}
 */
function bytesToCanonicalHex(bytes) {
  const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, '0')).join('');
  return [
    hex.slice(0, 8),
    hex.slice(8, 12),
    hex.slice(12, 16),
    hex.slice(16, 20),
    hex.slice(20, 32),
  ].join('-');
}

module.exports = {
  parseUuidBytes,
  bytesToCanonicalHex,
};
test/contract.js
'use strict';

const assert = require('node:assert/strict');
const { parse } = require('uuid');
const { parseUuidBytes, bytesToCanonicalHex } = require('../src/index.js');

// 1. CommonJS export check
assert.equal(typeof parse, 'function', 'uuid.parse must be exported as a function');

// 2. Canonical lowercase v4 UUID parses to exact 16-byte Uint8Array
const sampleUuid = '6ec0bd7f-11c0-43da-975e-2a8ad9ebae0b';
const expectedBytes = new Uint8Array([
  0x6e, 0xc0, 0xbd, 0x7f,
  0x11, 0xc0, 0x43, 0xda,
  0x97, 0x5e, 0x2a, 0x8a,
  0xd9, 0xeb, 0xae, 0x0b,
]);

const parsed = parseUuidBytes(sampleUuid);
assert.ok(parsed instanceof Uint8Array, 'uuid.parse must return a Uint8Array');
assert.equal(parsed.length, 16, 'parsed UUID must be 16 bytes long');
assert.deepEqual(parsed, expectedBytes, 'parsed bytes must match the canonical UUID hex');
assert.equal(bytesToCanonicalHex(parsed), sampleUuid, 'formatted bytes must round-trip to original UUID');

// 3. Uppercase and mixed-case UUIDs parse identically
const upperParsed = parseUuidBytes(sampleUuid.toUpperCase());
assert.deepEqual(upperParsed, expectedBytes, 'uppercase UUID must parse to identical bytes');

const mixedParsed = parseUuidBytes('6Ec0Bd7F-11c0-43DA-975e-2A8aD9EbAe0B');
assert.deepEqual(mixedParsed, expectedBytes, 'mixed-case UUID must parse to identical bytes');

// 4. Nil UUID parses to 16 zero bytes
const nilUuid = '00000000-0000-0000-0000-000000000000';
const nilBytes = parseUuidBytes(nilUuid);
assert.ok(nilBytes instanceof Uint8Array, 'nil UUID must return a Uint8Array');
assert.equal(nilBytes.length, 16, 'nil UUID must be 16 bytes long');
assert.deepEqual(nilBytes, new Uint8Array(16), 'nil UUID must parse to 16 zero bytes');

// 5. Invalid inputs throw TypeError
const invalidInputs = [
  '',
  'not-a-uuid',
  '6ec0bd7f11c043da975e2a8ad9ebae0b', // missing hyphens
  '6ec0bd7f-11c0-43da-975e-2a8ad9ebae0g', // non-hex character
  '6ec0bd7f-11c0-43da-975e-2a8ad9ebae0', // too short
  '6ec0bd7f-11c0-43da-975e-2a8ad9ebae0bb', // too long
  null,
  undefined,
  12345,
];

for (const bad of invalidInputs) {
  assert.throws(
    () => parse(bad),
    (err) => err instanceof TypeError && /Invalid UUID/i.test(err.message),
    `expected uuid.parse(${String(bad)}) to throw TypeError("Invalid UUID")`
  );
}

console.log('PASS: uuid.parse contract verified for pkg:npm/uuid@8.3.2');

Ursprungs-Seeder

anonym