CodeSampleX

示例

plist 3.1.0: build

已验证示例 — npm plist 3.1.0: build. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: plist.build serializes JavaScript primitives and objects into standard…

sha256:dcbf1d0744a14a1ea7a0e0282670f2a049c9a17c3b7823e17e74da359acf8c5c

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 MIT-0

执行证据

声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。

证据依据
签名契约通过
验证回执
1
构建过它的签名密钥
1
声明的环境 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

验证运行环境

环境 契约 阶段 运行日期
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-26

案例

HOW
目标
verify plist.build in pkg:npm/plist@3.1.0
包
符号
  • plist.build
环境
node 22.23.2
创建时间
2026-08-26T11:07:04Z

契约

  1. plist.build serializes JavaScript primitives and objects into standard XML property list format
  2. plist.build encodes numbers into integer or real tags and buffers into base64 data tags
  3. plist.build encodes Date objects into ISO 8601 date tags and booleans into true and false tags
  4. plist.build handles nested dictionaries and arrays with proper tag hierarchy
  5. plist.build escapes special XML characters in string values and keys
  6. plist.build applies custom formatting options such as custom indentation

文件

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

下载源代码构件 (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 plist.build in pkg:npm/plist@3.1.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/plist@3.1.0
Demonstrate these symbols/APIs:
  - plist.build
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

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:2bdfc37b9346c87ebf102c2cb1032235e551d053048334f6708d9559a09ce3ca","constraints":{"executionContext":"node"},"contract":["plist.build serializes JavaScript primitives and objects into standard XML property list format","plist.build encodes numbers into integer or real tags and buffers into base64 data tags","plist.build encodes Date objects into ISO 8601 date tags and booleans into true and false tags","plist.build handles nested dictionaries and arrays with proper tag hierarchy","plist.build escapes special XML characters in string values and keys","plist.build applies custom formatting options such as custom indentation"],"goal":"verify plist.build in pkg:npm/plist@3.1.0","kind":"HOW","packages":["pkg:npm/plist@3.1.0"],"schemaVersion":1,"symbols":["plist.build"]},"contractCommand":["node","test/contract.js"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/plist@3.1.0"],"schemaVersion":1,"subject":"pkg:npm/plist@3.1.0","symbols":["plist.build"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "plist-build-sample",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "plist-build-sample",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "plist": "3.1.0"
      }
    },
    "node_modules/@xmldom/xmldom": {
      "version": "0.8.15",
      "resolved": "https://registry.npmjs.org/@xmldom/xmldom/-/xmldom-0.8.15.tgz",
      "integrity": "sha512-/5NV/vDALVFDXgLmfsy9TRCBlKwO2LNBFzpzvb9iIj+jR+eSc6DLYYvVOdivT/jm7MtU6TebYuRmzEOI7w40UA==",
      "license": "MIT",
      "engines": {
        "node": ">=10.0.0"
      }
    },
    "node_modules/base64-js": {
      "version": "1.5.1",
      "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz",
      "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==",
      "funding": [
        {
          "type": "github",
          "url": "https://github.com/sponsors/feross"
        },
        {
          "type": "patreon",
          "url": "https://www.patreon.com/feross"
        },
        {
          "type": "consulting",
          "url": "https://feross.org/support"
        }
      ],
      "license": "MIT"
    },
    "node_modules/plist": {
      "version": "3.1.0",
      "resolved": "https://registry.npmjs.org/plist/-/plist-3.1.0.tgz",
      "integrity": "sha512-uysumyrvkUX0rX/dEVqt8gC3sTBzd4zoWfLeS29nb53imdaXVvLINYXTI2GNqzaMuvacNx4uJQ8+b3zXR0pkgQ==",
      "license": "MIT",
      "dependencies": {
        "@xmldom/xmldom": "^0.8.8",
        "base64-js": "^1.5.1",
        "xmlbuilder": "^15.1.1"
      },
      "engines": {
        "node": ">=10.4.0"
      }
    },
    "node_modules/xmlbuilder": {
      "version": "15.1.1",
      "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-15.1.1.tgz",
      "integrity": "sha512-yMqGBqtXyeN1e3TGYvgNgDVZ3j84W4cwkOXQswghol6APgZWaff9lnbvN7MHYJOiXsvGPXtjTYJEiC9J2wv9Eg==",
      "license": "MIT",
      "engines": {
        "node": ">=8.0"
      }
    }
  }
}
package.json
{
  "name": "plist-build-sample",
  "version": "1.0.0",
  "description": "verify plist.build in pkg:npm/plist@3.1.0",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "plist": "3.1.0"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify plist.build in pkg:npm/plist@3.1.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/plist@3.1.0"
  ],
  "symbols": [
    "plist.build"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.js
const plist = require('plist');

/**
 * Builds an XML Property List string from any JavaScript value.
 *
 * @param {*} data - JavaScript data structure to serialize.
 * @param {object} [options] - Optional formatting options (indent, offset, head).
 * @returns {string} The formatted XML Property List document string.
 */
function buildPlist(data, options) {
  return plist.build(data, options);
}

/**
 * Builds a Property List representing a dictionary (object) structure.
 *
 * @param {Record<string, *>} entries - Key-value map to serialize as a plist dictionary.
 * @param {object} [options] - Optional formatting options.
 * @returns {string} The formatted XML Property List string.
 */
function buildDictionary(entries, options) {
  return plist.build(entries, options);
}

/**
 * Builds a Property List representing an array structure.
 *
 * @param {Array<*>} items - Array of elements to serialize.
 * @param {object} [options] - Optional formatting options.
 * @returns {string} The formatted XML Property List string.
 */
function buildArray(items, options) {
  return plist.build(items, options);
}

/**
 * Builds a Property List with custom indentation.
 *
 * @param {*} data - JavaScript value to serialize.
 * @param {string} indentString - Indentation string (e.g., '\t' or '  ').
 * @returns {string} The formatted XML Property List string.
 */
function buildFormattedPlist(data, indentString) {
  return plist.build(data, { indent: indentString });
}

module.exports = {
  buildPlist,
  buildDictionary,
  buildArray,
  buildFormattedPlist,
};
test/contract.js
const assert = require('node:assert/strict');
const plist = require('plist');
const {
  buildPlist,
  buildDictionary,
  buildArray,
  buildFormattedPlist,
} = require('../src/index.js');

// Contract 1: plist.build serializes JavaScript primitives and objects into standard XML property list format
{
  const input = { title: 'App Configuration', version: 1 };
  const xml = buildPlist(input);

  assert.ok(xml.includes('<?xml version="1.0" encoding="UTF-8"?>'), 'Must include XML declaration');
  assert.ok(xml.includes('DOCTYPE plist PUBLIC') && xml.includes('PropertyList-1.0.dtd'), 'Must include Apple plist DOCTYPE');
  assert.ok(xml.includes('<plist version="1.0">'), 'Must include plist root tag with version');
  assert.ok(xml.includes('<dict>'), 'Object root should serialize as dict');
  assert.ok(xml.includes('<key>title</key>'), 'Object keys should serialize as key tags');
  assert.ok(xml.includes('<string>App Configuration</string>'), 'String values should serialize as string tags');
}

// Contract 2: plist.build encodes numbers into integer or real tags and buffers into base64 data tags
{
  const bufferContent = Buffer.from('CodeSampleX payload', 'utf8');
  const input = {
    count: 42,
    ratio: 3.14159,
    binaryPayload: bufferContent,
  };
  const xml = buildDictionary(input);

  assert.ok(xml.includes('<key>count</key>\n    <integer>42</integer>'), 'Integer numbers should serialize as integer tags');
  assert.ok(xml.includes('<key>ratio</key>\n    <real>3.14159</real>'), 'Floating point numbers should serialize as real tags');
  assert.ok(xml.includes('<key>binaryPayload</key>\n    <data>' + bufferContent.toString('base64') + '</data>'), 'Buffers should serialize as base64 data tags');
}

// Contract 3: plist.build encodes Date objects into ISO 8601 date tags and booleans into true and false tags
{
  const timestamp = new Date('2026-08-26T11:00:00.000Z');
  const input = {
    createdAt: timestamp,
    isActive: true,
    isDeprecated: false,
  };
  const xml = buildDictionary(input);

  assert.ok(xml.includes('<key>createdAt</key>\n    <date>2026-08-26T11:00:00Z</date>') || xml.includes('<date>' + timestamp.toISOString() + '</date>'), 'Date objects should serialize into ISO date tags');
  assert.ok(xml.includes('<key>isActive</key>\n    <true/>'), 'True boolean should serialize as true tag');
  assert.ok(xml.includes('<key>isDeprecated</key>\n    <false/>'), 'False boolean should serialize as false tag');
}

// Contract 4: plist.build handles nested dictionaries and arrays with proper tag hierarchy
{
  const input = [
    {
      id: 101,
      tags: ['alpha', 'beta'],
      settings: {
        enabled: true,
      },
    },
  ];
  const xml = buildArray(input);

  assert.ok(xml.includes('<plist version="1.0">\n  <array>'), 'Array root should serialize as array tag');
  assert.ok(xml.includes('<dict>'), 'Nested dictionary inside array');
  assert.ok(xml.includes('<key>tags</key>\n      <array>'), 'Nested array under key');
  assert.ok(xml.includes('<string>alpha</string>'), 'Array items serialized properly');
  assert.ok(xml.includes('<string>beta</string>'), 'Array items serialized properly');

  // Verify round-trip parsing
  const parsed = plist.parse(xml);
  assert.strictEqual(parsed[0].id, 101);
  assert.deepStrictEqual(parsed[0].tags, ['alpha', 'beta']);
  assert.strictEqual(parsed[0].settings.enabled, true);
}

// Contract 5: plist.build escapes special XML characters in string values and keys
{
  const input = {
    'custom&key': '<script>alert("xss") & \'test\'</script>',
  };
  const xml = buildPlist(input);

  assert.ok(xml.includes('&lt;script&gt;'), 'Unescaped tag brackets should be escaped');
  assert.ok(xml.includes('&amp;'), 'Ampersands must be escaped');
  assert.ok(!xml.includes('<script>'), 'Raw script tags must not appear in XML output');

  const parsed = plist.parse(xml);
  assert.strictEqual(parsed['custom&key'], '<script>alert("xss") & \'test\'</script>');
}

// Contract 6: plist.build applies custom formatting options such as custom indentation
{
  const input = { item: 1 };
  const tabFormatted = buildFormattedPlist(input, '\t');
  const spaceFormatted = buildFormattedPlist(input, '    ');

  assert.ok(tabFormatted.includes('\t<dict>'), 'Custom tab indentation should be applied');
  assert.ok(spaceFormatted.includes('    <dict>'), 'Custom 4-space indentation should be applied');
}

console.log('All contract tests passed successfully.');

原始种子者

匿名