CodeSampleX

샘플

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

sha256:5b5952a5f28948eb9e20c09016b75be18ccb832ae103d7b19265bdc2a15970a5

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. 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

컨트랙트

  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

파일

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • 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 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.');

오리진 시더

익명