示例
iconv-lite 0.7.3
已验证示例 — npm iconv-lite 0.7.3. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: assert encoding existence checks return true for supported legacy…
sha256:e0e7327dd58c17b273e4f12583e945319a5ba7ab60fc2fa7271454ac0170de98
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 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@1 |
2026-08-20 |
案例
HOW- 目标
- verify pkg:npm/iconv-lite@0.7.3
- 环境
- node 22.23.2
- 创建时间
- 2026-08-20T13:29:18Z
契约
- assert encoding existence checks return true for supported legacy encodings and false for unknown encodings
- assert Korean EUC-KR encoding and decoding roundtrip preserves original text and produces valid byte buffer
- assert Japanese Shift_JIS encoding and decoding roundtrip preserves original multibyte text
- assert Cyrillic Windows-1251 encoding and decoding roundtrip preserves original text accurately
- assert UTF-8 encoding with addBOM prepends byte order mark 0xEF 0xBB 0xBF and default decoding strips BOM while explicit option retains BOM
- assert stateful chunked decoder correctly decodes multibyte character stream split across chunk boundaries
文件
- PROMPT.md
- csx.json
- index.js
- package-lock.json
- package.json
- spec.json
- test/contract.mjs
源代码
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/iconv-lite@0.7.3
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/iconv-lite@0.7.3
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.
{"case":{"caseId":"case:sha256:03ddb16f7a54c2d2c5ca0f555b0b855a34d53b3167634649f50d46d3514214be","constraints":{"executionContext":"node"},"contract":["assert encoding existence checks return true for supported legacy encodings and false for unknown encodings","assert Korean EUC-KR encoding and decoding roundtrip preserves original text and produces valid byte buffer","assert Japanese Shift_JIS encoding and decoding roundtrip preserves original multibyte text","assert Cyrillic Windows-1251 encoding and decoding roundtrip preserves original text accurately","assert UTF-8 encoding with addBOM prepends byte order mark 0xEF 0xBB 0xBF and default decoding strips BOM while explicit option retains BOM","assert stateful chunked decoder correctly decodes multibyte character stream split across chunk boundaries"],"goal":"verify pkg:npm/iconv-lite@0.7.3","kind":"HOW","packages":["pkg:npm/iconv-lite@0.7.3"],"schemaVersion":1},"contractCommand":["node","test/contract.mjs"],"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/iconv-lite@0.7.3"],"schemaVersion":1,"verifierAdapter":"node-typescript@1"}
const iconv = require('iconv-lite');
function convertEncoding(text, fromEncoding, toEncoding) {
const buf = iconv.encode(text, fromEncoding);
return iconv.decode(buf, toEncoding);
}
function encodeToBuffer(text, encoding, options) {
return iconv.encode(text, encoding, options);
}
function decodeFromBuffer(buf, encoding, options) {
return iconv.decode(buf, encoding, options);
}
function isEncodingSupported(encoding) {
return iconv.encodingExists(encoding);
}
function createChunkedDecoder(encoding) {
return iconv.getDecoder(encoding);
}
module.exports = {
convertEncoding,
encodeToBuffer,
decodeFromBuffer,
isEncodingSupported,
createChunkedDecoder,
iconv,
};
{
"name": "sample-iconv-lite",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-iconv-lite",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"iconv-lite": "0.7.3"
}
},
"node_modules/iconv-lite": {
"version": "0.7.3",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.7.3.tgz",
"integrity": "sha512-IKXpvIzjnC9XTAUbVBcMfGS0EPaIXtW6v+zr+RRp+hqULEpo0owZax6wyRwPOJbWbzjYspQwusTsfVr0ifh4uQ==",
"license": "MIT",
"dependencies": {
"safer-buffer": ">= 2.1.2 < 3.0.0"
},
"engines": {
"node": ">=0.10.0"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/safer-buffer": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==",
"license": "MIT"
}
}
}
{
"name": "sample-iconv-lite",
"version": "1.0.0",
"description": "Minimal clean-room sample verifying iconv-lite character encoding conversions",
"main": "index.js",
"license": "MIT-0",
"dependencies": {
"iconv-lite": "0.7.3"
}
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/iconv-lite@0.7.3",
"kind": "HOW",
"packages": [
"pkg:npm/iconv-lite@0.7.3"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
import assert from 'node:assert';
import iconv from 'iconv-lite';
import {
convertEncoding,
encodeToBuffer,
decodeFromBuffer,
isEncodingSupported,
createChunkedDecoder,
} from '../index.js';
// 1. Encoding existence checks
assert.strictEqual(isEncodingSupported('utf-8'), true, 'UTF-8 must be supported');
assert.strictEqual(isEncodingSupported('windows-1252'), true, 'Windows-1252 must be supported');
assert.strictEqual(isEncodingSupported('euc-kr'), true, 'EUC-KR must be supported');
assert.strictEqual(isEncodingSupported('shift_jis'), true, 'Shift_JIS must be supported');
assert.strictEqual(isEncodingSupported('win1251'), true, 'Windows-1251 must be supported');
assert.strictEqual(isEncodingSupported('non-existent-charset-12345'), false, 'Unknown encoding must return false');
// 2. Korean EUC-KR encode/decode roundtrip
const koreanText = '안녕하세요 세계';
const eucKrBuf = encodeToBuffer(koreanText, 'euc-kr');
assert(Buffer.isBuffer(eucKrBuf), 'encodeToBuffer must return a Buffer');
const decodedKorean = decodeFromBuffer(eucKrBuf, 'euc-kr');
assert.strictEqual(decodedKorean, koreanText, 'EUC-KR roundtrip decode must match original');
// 3. Japanese Shift_JIS encode/decode roundtrip
const japaneseText = 'こんにちは世界';
const shiftJisBuf = encodeToBuffer(japaneseText, 'shift_jis');
const decodedJapanese = decodeFromBuffer(shiftJisBuf, 'shift_jis');
assert.strictEqual(decodedJapanese, japaneseText, 'Shift_JIS roundtrip decode must match original');
// 4. Cyrillic Windows-1251 encode/decode roundtrip
const cyrillicText = 'Привет мир';
const win1251Buf = encodeToBuffer(cyrillicText, 'windows-1251');
const decodedCyrillic = decodeFromBuffer(win1251Buf, 'windows-1251');
assert.strictEqual(decodedCyrillic, cyrillicText, 'Windows-1251 roundtrip decode must match original');
// 5. UTF-8 BOM handling
const asciiText = 'Hello World';
const withBOM = encodeToBuffer(asciiText, 'utf-8', { addBOM: true });
assert.strictEqual(withBOM[0], 0xef, 'First byte of UTF-8 BOM must be 0xEF');
assert.strictEqual(withBOM[1], 0xbb, 'Second byte of UTF-8 BOM must be 0xBB');
assert.strictEqual(withBOM[2], 0xbf, 'Third byte of UTF-8 BOM must be 0xBF');
const strippedBOM = decodeFromBuffer(withBOM, 'utf-8');
assert.strictEqual(strippedBOM, asciiText, 'decode must strip BOM by default');
const retainedBOM = decodeFromBuffer(withBOM, 'utf-8', { stripBOM: false });
assert.strictEqual(retainedBOM.charCodeAt(0), 0xfeff, 'decode with stripBOM: false must retain BOM');
// 6. Stateful / Chunked decoding across byte boundaries
const decoder = createChunkedDecoder('utf-8');
const partial1 = Buffer.from([0xec, 0x95]);
const partial2 = Buffer.from([0x88, 0xeb, 0x85, 0x95]);
const chunk1 = decoder.write(partial1);
const chunk2 = decoder.write(partial2);
const finalChunk = decoder.end() || '';
const streamResult = (chunk1 || '') + (chunk2 || '') + finalChunk;
assert.strictEqual(streamResult, '안녕', 'Chunked decoding across multibyte split must reconstruct characters accurately');
console.log('All contract assertions passed.');
原始种子者
匿名