サンプル
js-yaml 4.1.0: dump
検証済みサンプル — npm js-yaml 4.1.0: dump. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました: dump serializes JavaScript objects, arrays, and primitives…
sha256:5b5952a5f28948eb9e20c09016b75be18ccb832ae103d7b19265bdc2a15970a5
このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。
合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。
MIT-0
実行証拠
宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。
- 証拠の基準
- 署名済みコントラクト合格
- 検証レシート
- 1
- ビルドした署名鍵
- 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-28 |
ケース
HOW- ゴール
- verify js-yaml.dump in pkg:npm/js-yaml@4.1.0
- パッケージ
- シンボル
-
- js-yaml.dump
- 作成日
- 2026-08-28T03:35:51Z
コントラクト
- 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
ファイル
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.mjs
ソース
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.
{"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"}
{
"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"
}
}
}
}
{
"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"
}
}
{
"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"
]
}
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
};
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.');
オリジンシーダー
匿名