CodeSampleX

示例

text-decoder 1.2.7

已验证示例 — npm text-decoder 1.2.7. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: TextDecoder defaults to utf8 and decodes multibyte UTF-8 characters…

sha256:50f8c8d2efc61b98dc4752ba85486751ce54966d84e726855bbe433319a7d6eb

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 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-23

案例

HOW
目标
verify pkg:npm/text-decoder@1.2.7
包
创建时间
2026-08-23T15:18:30Z

契约

  1. TextDecoder defaults to utf8 and decodes multibyte UTF-8 characters across streamed chunk boundaries
  2. TextDecoder remaining property returns the number of buffered incomplete multibyte bytes
  3. TextDecoder passes through string input unchanged
  4. TextDecoder write method aliases push for stream compatibility
  5. TextDecoder end flushes any buffered bytes and resets remaining state to zero
  6. TextDecoder supports pass-through encodings like ascii and hex, and throws on unsupported or unknown encodings

文件

  • PROMPT.md
  • csx.json
  • 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 pkg:npm/text-decoder@1.2.7
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/text-decoder@1.2.7

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:dbec213d9df95a222094f9b1738510a49fb68bece83d5ee84cc54af4d6af23a4","contract":["TextDecoder defaults to utf8 and decodes multibyte UTF-8 characters across streamed chunk boundaries","TextDecoder remaining property returns the number of buffered incomplete multibyte bytes","TextDecoder passes through string input unchanged","TextDecoder write method aliases push for stream compatibility","TextDecoder end flushes any buffered bytes and resets remaining state to zero","TextDecoder supports pass-through encodings like ascii and hex, and throws on unsupported or unknown encodings"],"goal":"verify pkg:npm/text-decoder@1.2.7","kind":"HOW","packages":["pkg:npm/text-decoder@1.2.7"],"schemaVersion":1},"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/text-decoder@1.2.7"],"schemaVersion":1,"subject":"pkg:npm/text-decoder@1.2.7","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-text-decoder",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-text-decoder",
      "version": "1.0.0",
      "dependencies": {
        "text-decoder": "1.2.7"
      }
    },
    "node_modules/b4a": {
      "version": "1.8.1",
      "resolved": "https://registry.npmjs.org/b4a/-/b4a-1.8.1.tgz",
      "integrity": "sha512-aiqre1Nr0B/6DgE2N5vwTc+2/oQZ4Wh1t4NznYY4E00y8LCt6NqdRv81so00oo27D8MVKTpUa/MwUUtBLXCoDw==",
      "license": "Apache-2.0",
      "peerDependencies": {
        "react-native-b4a": "*"
      },
      "peerDependenciesMeta": {
        "react-native-b4a": {
          "optional": true
        }
      }
    },
    "node_modules/text-decoder": {
      "version": "1.2.7",
      "resolved": "https://registry.npmjs.org/text-decoder/-/text-decoder-1.2.7.tgz",
      "integrity": "sha512-vlLytXkeP4xvEq2otHeJfSQIRyWxo/oZGEbXrtEEF9Hnmrdly59sUbzZ/QgyWuLYHctCHxFF4tRQZNQ9k60ExQ==",
      "license": "Apache-2.0",
      "dependencies": {
        "b4a": "^1.6.4"
      }
    }
  }
}
package.json
{
  "name": "sample-text-decoder",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "dependencies": {
    "text-decoder": "1.2.7"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/text-decoder@1.2.7",
  "kind": "HOW",
  "packages": [
    "pkg:npm/text-decoder@1.2.7"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import TextDecoder from 'text-decoder';

// 1. TextDecoder defaults to utf8 and decodes multibyte UTF-8 characters across streamed chunk boundaries
const td = new TextDecoder();
// UTF-8 bytes for '💩' (U+1F4A9): F0 9F 92 A9 (4 bytes)
const chunk1 = Buffer.of(0xf0, 0x9f, 0x92);
const chunk2 = Buffer.of(0xa9);

assert.strictEqual(td.push(chunk1), '', 'Incomplete 3-byte chunk of 4-byte sequence returns empty string');
assert.strictEqual(td.remaining, 3, 'Remaining bytes should be 3');
assert.strictEqual(td.push(chunk2), '💩', 'Final byte completes the character and returns decoded string');
assert.strictEqual(td.remaining, 0, 'Remaining bytes should now be 0');

// Multi-character streaming: 'hello 🌍!' where 🌍 is F0 9F 8C 8D
const tdStream = new TextDecoder();
const part1 = Buffer.concat([Buffer.from('hello '), Buffer.of(0xf0, 0x9f)]);
const part2 = Buffer.concat([Buffer.of(0x8c, 0x8d), Buffer.from('!')]);
assert.strictEqual(tdStream.push(part1), 'hello ', 'Decodes prefix ASCII before incomplete multibyte sequence');
assert.strictEqual(tdStream.push(part2), '🌍!', 'Completes emoji and continues decoding remainder');

// 2. TextDecoder remaining property returns the number of buffered incomplete multibyte bytes
const tdRem = new TextDecoder();
assert.strictEqual(tdRem.remaining, 0);
tdRem.push(Buffer.of(0xe2, 0x82)); // Euro sign € is E2 82 AC (3 bytes)
assert.strictEqual(tdRem.remaining, 2);
tdRem.push(Buffer.of(0xac));
assert.strictEqual(tdRem.remaining, 0);

// 3. TextDecoder passes through string input unchanged
const tdStr = new TextDecoder();
assert.strictEqual(tdStr.push('already string'), 'already string');
assert.strictEqual(tdStr.push(' another string'), ' another string');

// 4. TextDecoder write method aliases push for stream compatibility
const tdWrite = new TextDecoder();
assert.strictEqual(tdWrite.write(Buffer.from('stream data ')), 'stream data ');
assert.strictEqual(tdWrite.write('string data'), 'string data');

// 5. TextDecoder end flushes any buffered bytes and resets remaining state to zero
const tdEnd = new TextDecoder();
tdEnd.push(Buffer.of(0xf0, 0x9f)); // partial sequence
assert.strictEqual(tdEnd.remaining, 2);
const flushed = tdEnd.end(); // flushes remaining
assert.strictEqual(tdEnd.remaining, 0, 'Remaining reset after end');
assert.strictEqual(typeof flushed, 'string');

const tdEndWithData = new TextDecoder();
const endResult = tdEndWithData.end(Buffer.from('final chunk'));
assert.strictEqual(endResult, 'final chunk');

// 6. TextDecoder supports pass-through encodings like ascii and hex, and throws on unsupported or unknown encodings
const tdAscii = new TextDecoder('ascii');
assert.strictEqual(tdAscii.push(Buffer.from('abc')), 'abc');

const tdHex = new TextDecoder('hex');
assert.strictEqual(tdHex.push(Buffer.from('hi')), '6869');

assert.throws(() => new TextDecoder('utf16le'), {
  name: 'Error',
  message: 'Unsupported encoding: utf16le'
});
assert.throws(() => new TextDecoder('base64'), {
  name: 'Error',
  message: 'Unsupported encoding: base64'
});
assert.throws(() => new TextDecoder('invalid-enc'), {
  name: 'Error',
  message: 'Unknown encoding: invalid-enc'
});

console.log('Contract tests passed successfully.');

原始种子者

匿名