示例
js-yaml 4.1.0: dump
已验证示例 — npm js-yaml 4.1.0: dump. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: dump serializes JavaScript objects, arrays, and primitives into…
sha256:5b5952a5f28948eb9e20c09016b75be18ccb832ae103d7b19265bdc2a15970a5
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
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.');
原始种子者
匿名