CodeSampleX

示例

entities 6.0.1: escapeUTF8

已验证示例 — npm entities 6.0.1: escapeUTF8. contract 在 node 22 · linux debian/x64 · docker 上运行并通过: entities.escapeUTF8 is exported as a function

sha256:fc42971e0a372f24bd97b2a90cc7c3110ec44d5e08f1f4b577d17361b3f15464

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

执行证据

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

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

验证运行环境

环境 契约 阶段 运行日期
node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2…
2026-09-17

案例

HOW
目标
verify entities.escapeUTF8 in pkg:npm/entities@6.0.1
包
符号
  • entities.escapeUTF8
创建时间
2026-09-17T01:55:09Z

契约

  1. entities.escapeUTF8 is exported as a function
  2. entities.escapeUTF8 escapes the five XML syntax characters (&, <, >, ", ') into corresponding XML entities
  3. entities.escapeUTF8 preserves non-ASCII UTF-8 unicode characters without numeric references
  4. entities.escapeUTF8 leaves safe ASCII text and punctuation untouched
  5. entities.escapeUTF8 handles repeated and consecutive special characters correctly
  6. entities.escapeUTF8 handles empty input and plain text strings unchanged

文件

  • PROMPT.md
  • csx.json
  • index.mjs
  • package-lock.json
  • package.json
  • spec.json
  • 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 entities.escapeUTF8 in pkg:npm/entities@6.0.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/entities@6.0.1
Demonstrate these symbols/APIs:
  - entities.escapeUTF8

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:91d2c0ae5c0603aee6aa91dfb7414895ff341f58448f9c0ce05e829f0e578280","contract":["entities.escapeUTF8 is exported as a function","entities.escapeUTF8 escapes the five XML syntax characters (\u0026, \u003c, \u003e, \", ') into corresponding XML entities","entities.escapeUTF8 preserves non-ASCII UTF-8 unicode characters without numeric references","entities.escapeUTF8 leaves safe ASCII text and punctuation untouched","entities.escapeUTF8 handles repeated and consecutive special characters correctly","entities.escapeUTF8 handles empty input and plain text strings unchanged"],"goal":"verify entities.escapeUTF8 in pkg:npm/entities@6.0.1","kind":"HOW","packages":["pkg:npm/entities@6.0.1"],"schemaVersion":1,"symbols":["entities.escapeUTF8"]},"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/entities@6.0.1"],"schemaVersion":1,"subject":"pkg:npm/entities@6.0.1","symbols":["entities.escapeUTF8"],"verifierAdapter":"node-typescript@1"}
index.mjs
import * as entities from 'entities';

export const escapeUTF8 = entities.escapeUTF8;

/**
 * Escapes XML special characters in a UTF-8 string while leaving non-ASCII characters intact.
 *
 * @param {string} input - Text to escape.
 * @returns {string} Escaped XML string.
 */
export function escapeXmlUTF8(input) {
  return entities.escapeUTF8(input);
}

export default entities;
package-lock.json
{
  "name": "sample-entities-escape-utf8",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-entities-escape-utf8",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "entities": "6.0.1"
      }
    },
    "node_modules/entities": {
      "version": "6.0.1",
      "resolved": "https://registry.npmjs.org/entities/-/entities-6.0.1.tgz",
      "integrity": "sha512-aN97NXWF6AWBTahfVOIrB/NShkzi5H7F9r1s9mD3cDj4Ko5f2qhhVoYMibXF7GlLveb/D2ioWay8lxI97Ven3g==",
      "license": "BSD-2-Clause",
      "engines": {
        "node": ">=0.12"
      },
      "funding": {
        "url": "https://github.com/fb55/entities?sponsor=1"
      }
    }
  }
}
package.json
{
  "name": "sample-entities-escape-utf8",
  "version": "1.0.0",
  "type": "module",
  "main": "index.mjs",
  "license": "MIT-0",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "entities": "6.0.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify entities.escapeUTF8 in pkg:npm/entities@6.0.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/entities@6.0.1"
  ],
  "symbols": [
    "entities.escapeUTF8"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import * as entities from 'entities';
import { escapeUTF8, escapeXmlUTF8 } from '../index.mjs';

// 1. entities.escapeUTF8 is exported as a function
assert.equal(typeof entities.escapeUTF8, 'function');
assert.equal(typeof escapeUTF8, 'function');
assert.equal(typeof escapeXmlUTF8, 'function');

// 2. entities.escapeUTF8 escapes the five XML syntax characters (&, <, >, ", ') into corresponding XML entities
assert.equal(escapeUTF8('&'), '&amp;');
assert.equal(escapeUTF8('<'), '&lt;');
assert.equal(escapeUTF8('>'), '&gt;');
assert.equal(escapeUTF8('"'), '&quot;');
assert.equal(escapeUTF8("'"), '&apos;');
assert.equal(
  escapeUTF8('<tag attr="val" other=\'val\'>foo & bar</tag>'),
  '&lt;tag attr=&quot;val&quot; other=&apos;val&apos;&gt;foo &amp; bar&lt;/tag&gt;'
);

// 3. entities.escapeUTF8 preserves non-ASCII UTF-8 unicode characters without numeric references
assert.equal(escapeUTF8('Café & Restaurant: 100€'), 'Café &amp; Restaurant: 100€');
assert.equal(escapeUTF8('안녕하세요 <세계> 🚀'), '안녕하세요 &lt;세계&gt; 🚀');
assert.equal(escapeUTF8('Grüße & Küsschen'), 'Grüße &amp; Küsschen');
assert.equal(escapeUTF8('日本語・中文・한국어 — & " < > \''), '日本語・中文・한국어 — &amp; &quot; &lt; &gt; &apos;');

// 4. entities.escapeUTF8 leaves safe ASCII text and punctuation untouched
assert.equal(escapeUTF8(''), '');
assert.equal(escapeUTF8('plain text 12345'), 'plain text 12345');
assert.equal(escapeUTF8('hello world!'), 'hello world!');

// 5. entities.escapeUTF8 handles repeated and consecutive special characters correctly
assert.equal(escapeUTF8('&&&&'), '&amp;&amp;&amp;&amp;');
assert.equal(escapeUTF8('<<<>>>'), '&lt;&lt;&lt;&gt;&gt;&gt;');
assert.equal(escapeUTF8('"""\'\'\''), '&quot;&quot;&quot;&apos;&apos;&apos;');

// 6. module index wrapper matches entities.escapeUTF8 output
assert.equal(
  escapeXmlUTF8('<sample text & "quotes">'),
  entities.escapeUTF8('<sample text & "quotes">')
);

console.log('All entities.escapeUTF8 contract assertions passed.');

原始种子者

匿名