CodeSampleX

Beispiel

js-yaml 4.1.0: dump

Verifiziertes Beispiel für npm js-yaml 4.1.0: dump. Der Vertrag lief auf node 22 · linux alpine/x64 · docker und bestand: dump serializes JavaScript objects…

sha256:5b5952a5f28948eb9e20c09016b75be18ccb832ae103d7b19265bdc2a15970a5

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 linux 24 · ubuntu · glibc 2.39 x64 npm

Umgebungen der Verifizierungsläufe

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

Fall

HOW
Ziel
verify js-yaml.dump in pkg:npm/js-yaml@4.1.0
Pakete
Symbole
  • js-yaml.dump
Erstellt
2026-08-28T03:35:51Z

Contract

  1. dump serializes JavaScript objects, arrays, and primitives into standard YAML format
  2. dump supports custom indent widths for nested objects
  3. dump sorts dictionary keys alphabetically when sortKeys is true
  4. dump formats collections in inline flow style when flowLevel is configured
  5. dump enforces explicit double or single quotes around strings with forceQuotes and quotingType
  6. dump omits non-serializable values such as functions without throwing when skipInvalid is true
  7. dump duplicates repeated object references instead of generating anchors when noRefs is true

Dateien

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

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 js-yaml.dump in pkg:npm/js-yaml@4.1.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/js-yaml@4.1.0
Demonstrate these symbols/APIs:
  - js-yaml.dump

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:f6cceacb9b7e65177eda99b1e915bdbe4d6fc1f629703eb59da9a09b8b6e83d9","contract":["dump serializes JavaScript objects, arrays, and primitives into standard YAML format","dump supports custom indent widths for nested objects","dump sorts dictionary keys alphabetically when sortKeys is true","dump formats collections in inline flow style when flowLevel is configured","dump enforces explicit double or single quotes around strings with forceQuotes and quotingType","dump omits non-serializable values such as functions without throwing when skipInvalid is true","dump duplicates repeated object references instead of generating anchors when noRefs is true"],"goal":"verify js-yaml.dump in pkg:npm/js-yaml@4.1.0","kind":"HOW","packages":["pkg:npm/js-yaml@4.1.0"],"schemaVersion":1,"symbols":["js-yaml.dump"]},"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/js-yaml@4.1.0"],"schemaVersion":1,"subject":"pkg:npm/js-yaml@4.1.0","symbols":["js-yaml.dump"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-js-yaml-dump",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-js-yaml-dump",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "js-yaml": "4.1.0"
      }
    },
    "node_modules/argparse": {
      "version": "2.0.1",
      "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz",
      "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==",
      "license": "Python-2.0"
    },
    "node_modules/js-yaml": {
      "version": "4.1.0",
      "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz",
      "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==",
      "license": "MIT",
      "dependencies": {
        "argparse": "^2.0.1"
      },
      "bin": {
        "js-yaml": "bin/js-yaml.js"
      }
    }
  }
}
package.json
{
  "name": "sample-js-yaml-dump",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of js-yaml.dump in pkg:npm/js-yaml@4.1.0",
  "main": "src/index.js",
  "license": "MIT-0",
  "dependencies": {
    "js-yaml": "4.1.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify js-yaml.dump in pkg:npm/js-yaml@4.1.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/js-yaml@4.1.0"
  ],
  "symbols": [
    "js-yaml.dump"
  ]
}
src/index.js
const yaml = require('js-yaml');

function dumpYaml(data, options) {
  return yaml.dump(data, options);
}

function dumpWithIndent(data, indent = 2) {
  return yaml.dump(data, { indent });
}

function dumpSorted(data) {
  return yaml.dump(data, { sortKeys: true });
}

function dumpFlow(data, flowLevel = 0) {
  return yaml.dump(data, { flowLevel });
}

function dumpQuoted(data, quotingType = '"') {
  return yaml.dump(data, { forceQuotes: true, quotingType });
}

function dumpSafeSkippingInvalid(data) {
  return yaml.dump(data, { skipInvalid: true });
}

function dumpNoRefs(data) {
  return yaml.dump(data, { noRefs: true });
}

module.exports = {
  yaml,
  dumpYaml,
  dumpWithIndent,
  dumpSorted,
  dumpFlow,
  dumpQuoted,
  dumpSafeSkippingInvalid,
  dumpNoRefs
};
test/contract.mjs
import assert from 'node:assert';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const {
  yaml,
  dumpYaml,
  dumpWithIndent,
  dumpSorted,
  dumpFlow,
  dumpQuoted,
  dumpSafeSkippingInvalid,
  dumpNoRefs
} = require('../src/index.js');

// 1. Basic object serialization to YAML
const basicObj = {
  name: 'code-sample',
  version: 1,
  enabled: true,
  items: ['alpha', 'beta']
};
const basicYaml = dumpYaml(basicObj);
assert.strictEqual(typeof basicYaml, 'string', 'dumpYaml should return a string');
const parsedBasic = yaml.load(basicYaml);
assert.deepStrictEqual(parsedBasic, basicObj, 'yaml.load of dumped YAML should match original object');
assert(basicYaml.includes('name: code-sample'), 'output should contain name field');
assert(basicYaml.includes('- alpha'), 'output should format array elements with hyphen');

// 2. Custom indentation options
const nestedObj = {
  parent: {
    child: {
      value: 42
    }
  }
};
const yamlIndent4 = dumpWithIndent(nestedObj, 4);
assert(yamlIndent4.includes('    child:'), 'dumpWithIndent with 4 should use 4-space indentation');
const parsedIndent = yaml.load(yamlIndent4);
assert.deepStrictEqual(parsedIndent, nestedObj, 'yaml.load of indented YAML should match original object');

// 3. Key sorting with sortKeys: true
const unsortedObj = {
  zebra: 1,
  apple: 2,
  mango: 3
};
const sortedYaml = dumpSorted(unsortedObj);
const lines = sortedYaml.trim().split('\n');
assert.strictEqual(lines[0], 'apple: 2', 'first sorted key should be apple');
assert.strictEqual(lines[1], 'mango: 3', 'second sorted key should be mango');
assert.strictEqual(lines[2], 'zebra: 1', 'third sorted key should be zebra');

// 4. Flow style formatting with flowLevel
const flowObj = {
  coords: [10, 20, 30]
};
const flowYaml = dumpFlow(flowObj, 1);
assert(flowYaml.includes('coords: [10, 20, 30]'), 'flowLevel should format array in inline flow style');
const parsedFlow = yaml.load(flowYaml);
assert.deepStrictEqual(parsedFlow, flowObj, 'yaml.load of flow YAML should match original object');

// 5. Force quotes and quoting type
const quoteObj = {
  greeting: 'hello world',
  status: 'active'
};
const quotedYaml = dumpQuoted(quoteObj, '"');
assert(quotedYaml.includes('greeting: "hello world"'), 'forceQuotes should wrap strings in double quotes');
assert(quotedYaml.includes('status: "active"'), 'forceQuotes should quote all string values');
const parsedQuoted = yaml.load(quotedYaml);
assert.deepStrictEqual(parsedQuoted, quoteObj, 'yaml.load of quoted YAML should match original object');

// 6. skipInvalid skips unsupported types like functions without throwing
const objWithFunc = {
  validKey: 'present',
  funcKey: function () { return 123; }
};
assert.doesNotThrow(() => {
  const result = dumpSafeSkippingInvalid(objWithFunc);
  assert(result.includes('validKey: present'), 'valid keys should remain in output');
  assert(!result.includes('funcKey'), 'invalid function key should be omitted when skipInvalid is true');
}, 'dump with skipInvalid should not throw on function properties');

// 7. noRefs prevents creating YAML anchors/aliases for repeated object references
const shared = { sharedKey: 'sharedVal' };
const multiRefObj = {
  first: shared,
  second: shared
};
const noRefsYaml = dumpNoRefs(multiRefObj);
assert(!noRefsYaml.includes('&') && !noRefsYaml.includes('*'), 'noRefs should prevent YAML anchor/alias generation');
const parsedNoRefs = yaml.load(noRefsYaml);
assert.deepStrictEqual(parsedNoRefs.first, parsedNoRefs.second, 'parsed objects should have identical content');

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

Ursprungs-Seeder

anonym