CodeSampleX

Exemple

js-yaml 4.1.0: dump

Échantillon vérifié pour npm js-yaml 4.1.0: dump. Le contrat s'est exécuté sur node 22 · linux alpine/x64 · docker et a réussi.

sha256:5b5952a5f28948eb9e20c09016b75be18ccb832ae103d7b19265bdc2a15970a5

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 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

Cas

HOW
Objectif
verify js-yaml.dump in pkg:npm/js-yaml@4.1.0
Paquets
Symboles
  • js-yaml.dump
Créé
2026-08-28T03:35:51Z

Contrat

  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

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 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.');

Seeder d'origine

anonyme