CodeSampleX

Пример

@xmldom/xmldom 0.8.13: DOMImplementation

Проверенный пример — npm @xmldom/xmldom 0.8.13: DOMImplementation. Контракт выполнен на node 22 · linux alpine/x64 · docker и пройден.

sha256:2729677372bec43b5d9b4924f10cdf8fa0a37a3c86280acab8c6732eb6c23747

Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла. Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди. MIT-0

Свидетельства выполнения

Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.

Основа свидетельства
Подписанный контракт пройден
Квитанции проверки
2
Ключи подписи, собравшие его
1
Заявленная среда linux 24 · ubuntu · glibc 2.39 x64 npm

Среды запусков проверки

Окружение Контракт Этапы Запуск
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5…
2026-08-23
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-07

Кейс

HOW
Цель
verify @xmldom/xmldom.DOMImplementation in pkg:npm/%40xmldom/xmldom@0.8.13
Пакеты
Символы
  • @xmldom/xmldom.DOMImplementation
Создан
2026-08-23T13:59:57Z

Контракт

  1. DOMImplementation checks feature support via hasFeature
  2. DOMImplementation.createDocumentType creates a DocumentType node with qualifiedName, publicId, and systemId
  3. DOMImplementation.createDocument creates an XML Document with root element, namespace, doctype, and implementation reference
  4. DOMImplementation.createDocument creates a Document with namespaced qualified name prefix and populates child nodes

Файлы

  • PROMPT.md
  • csx.json
  • index.mjs
  • package-lock.json
  • package.json
  • spec.json
  • 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 @xmldom/xmldom.DOMImplementation in pkg:npm/%40xmldom/xmldom@0.8.13
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40xmldom/xmldom@0.8.13
Demonstrate these symbols/APIs:
  - @xmldom/xmldom.DOMImplementation

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:cbac5b5f5d5c8cfc92e6df2c408252d6278f13d2d3f400078e94bb20cce20b16","contract":["DOMImplementation checks feature support via hasFeature","DOMImplementation.createDocumentType creates a DocumentType node with qualifiedName, publicId, and systemId","DOMImplementation.createDocument creates an XML Document with root element, namespace, doctype, and implementation reference","DOMImplementation.createDocument creates a Document with namespaced qualified name prefix and populates child nodes"],"goal":"verify @xmldom/xmldom.DOMImplementation in pkg:npm/%40xmldom/xmldom@0.8.13","kind":"HOW","packages":["pkg:npm/%40xmldom/xmldom@0.8.13"],"schemaVersion":1,"symbols":["@xmldom/xmldom.DOMImplementation"]},"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/%40xmldom/xmldom@0.8.13"],"schemaVersion":1,"subject":"pkg:npm/%40xmldom/xmldom@0.8.13","symbols":["@xmldom/xmldom.DOMImplementation"],"verifierAdapter":"node-typescript@1"}
index.mjs
import { DOMImplementation } from '@xmldom/xmldom';

/**
 * Creates a new DOMImplementation instance.
 * @returns {DOMImplementation}
 */
export function getDOMImplementation() {
  return new DOMImplementation();
}

/**
 * Creates a DocumentType node using DOMImplementation.
 * @param {string} qualifiedName
 * @param {string} [publicId]
 * @param {string} [systemId]
 * @returns {DocumentType}
 */
export function createDocType(qualifiedName, publicId = '', systemId = '') {
  const impl = new DOMImplementation();
  return impl.createDocumentType(qualifiedName, publicId, systemId);
}

/**
 * Creates a new XML Document using DOMImplementation with optional namespace, qualifiedName, and doctype.
 * @param {string|null} [namespaceURI]
 * @param {string|null} [qualifiedName]
 * @param {DocumentType|null} [doctype]
 * @returns {Document}
 */
export function createXmlDocument(namespaceURI = null, qualifiedName = null, doctype = null) {
  const impl = new DOMImplementation();
  return impl.createDocument(namespaceURI, qualifiedName, doctype);
}

/**
 * Checks if a feature and version is supported by DOMImplementation.
 * @param {string} feature
 * @param {string} [version]
 * @returns {boolean}
 */
export function checkFeature(feature, version) {
  const impl = new DOMImplementation();
  return impl.hasFeature(feature, version);
}

export { DOMImplementation };
package-lock.json
{
  "name": "sample-xmldom-domimplementation",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-xmldom-domimplementation",
      "version": "1.0.0",
      "dependencies": {
        "@xmldom/xmldom": "0.8.13"
      }
    },
    "node_modules/@xmldom/xmldom": {
      "version": "0.8.13",
      "resolved": "https://registry.npmjs.org/@xmldom/xmldom/-/xmldom-0.8.13.tgz",
      "integrity": "sha512-KRYzxepc14G/CEpEGc3Yn+JKaAeT63smlDr+vjB8jRfgTBBI9wRj/nkQEO+ucV8p8I9bfKLWp37uHgFrbntPvw==",
      "deprecated": "this version has critical issues, please update to the latest version",
      "license": "MIT",
      "engines": {
        "node": ">=10.0.0"
      }
    }
  }
}
package.json
{
  "name": "sample-xmldom-domimplementation",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "dependencies": {
    "@xmldom/xmldom": "0.8.13"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify @xmldom/xmldom.DOMImplementation in pkg:npm/%40xmldom/xmldom@0.8.13",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40xmldom/xmldom@0.8.13"
  ],
  "symbols": [
    "@xmldom/xmldom.DOMImplementation"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import {
  getDOMImplementation,
  createDocType,
  createXmlDocument,
  checkFeature,
  DOMImplementation
} from '../index.mjs';

// 1. DOMImplementation checks feature support via hasFeature
{
  const impl = getDOMImplementation();
  assert.ok(impl instanceof DOMImplementation, 'Expected DOMImplementation instance');
  assert.strictEqual(checkFeature('XML', '2.0'), true, 'XML 2.0 feature should be supported');
  assert.strictEqual(checkFeature('Core', '1.0'), true, 'Core 1.0 feature should be supported');
  assert.strictEqual(impl.hasFeature('XML', '1.0'), true, 'hasFeature should return true on instance');
}

// 2. DOMImplementation.createDocumentType creates a DocumentType node with qualifiedName, publicId, and systemId
{
  const name = 'html';
  const publicId = '-//W3C//DTD XHTML 1.0 Strict//EN';
  const systemId = 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd';

  const doctype = createDocType(name, publicId, systemId);
  assert.ok(doctype, 'DocumentType node should be created');
  assert.strictEqual(doctype.name, name);
  assert.strictEqual(doctype.publicId, publicId);
  assert.strictEqual(doctype.systemId, systemId);
  assert.strictEqual(doctype.nodeType, 10, 'nodeType should be DOCUMENT_TYPE_NODE (10)');
}

// 3. DOMImplementation.createDocument creates an XML Document with root element, namespace, doctype, and implementation reference
{
  const impl = getDOMImplementation();
  const doctype = impl.createDocumentType(
    'html',
    '-//W3C//DTD XHTML 1.0 Strict//EN',
    'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'
  );
  const doc = impl.createDocument('http://www.w3.org/1999/xhtml', 'html', doctype);

  assert.ok(doc, 'Document should be created');
  assert.strictEqual(doc.nodeType, 9, 'nodeType should be DOCUMENT_NODE (9)');
  assert.strictEqual(doc.doctype, doctype, 'Document doctype should match the provided doctype');
  assert.strictEqual(doc.documentElement.tagName, 'html', 'Root element tag name should be html');
  assert.strictEqual(doc.documentElement.namespaceURI, 'http://www.w3.org/1999/xhtml', 'Root element should have specified namespace');
  assert.ok(doc.implementation, 'Document should have implementation reference');
}

// 4. DOMImplementation.createDocument creates a Document with namespaced qualified name prefix and populates child nodes
{
  const ns = 'http://www.w3.org/2000/svg';
  const doc = createXmlDocument(ns, 'svg:svg', null);

  assert.ok(doc, 'SVG Document should be created');
  assert.strictEqual(doc.documentElement.tagName, 'svg:svg');
  assert.strictEqual(doc.documentElement.prefix, 'svg');
  assert.strictEqual(doc.documentElement.localName, 'svg');
  assert.strictEqual(doc.documentElement.namespaceURI, ns);

  const circle = doc.createElementNS(ns, 'circle');
  circle.setAttribute('cx', '50');
  circle.setAttribute('cy', '50');
  circle.setAttribute('r', '40');
  doc.documentElement.appendChild(circle);

  assert.strictEqual(doc.documentElement.childNodes.length, 1);
  assert.strictEqual(doc.documentElement.firstChild, circle);
  assert.strictEqual(doc.documentElement.firstChild.getAttribute('r'), '40');
}

console.log('All DOMImplementation contracts passed.');

Исходный сидер

аноним