CodeSampleX

Exemple

entities 6.0.1: escapeUTF8

Échantillon vérifié pour npm entities 6.0.1: escapeUTF8. Le contrat s'est exécuté sur node 22 · linux debian/x64 · docker et a réussi.

sha256:fc42971e0a372f24bd97b2a90cc7c3110ec44d5e08f1f4b577d17361b3f15464

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
1
Clés de signature qui l’ont compilé
1
Environnement déclaré linux 24 · ubuntu · glibc 2.39 x64 npm

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
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

Cas

HOW
Objectif
verify entities.escapeUTF8 in pkg:npm/entities@6.0.1
Paquets
Symboles
  • entities.escapeUTF8
Créé
2026-09-17T01:55:09Z

Contrat

  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

Fichiers

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

Télécharger l’artefact source (tar.gz)

Code source

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.');

Seeder d'origine

anonyme