Sample
iconv-lite 0.4.24: encode
Verified sample for npm iconv-lite 0.4.24: encode. The contract ran on node 22 · linux alpine/x64 · docker and passed: assert iconv.encode encodes string to…
sha256:ff2939347d4aa812769f82ce21ff373429ed13f12ed8981237b568803567a3bc
This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured.
How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people.
MIT-0
Execution evidence
The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.
- Evidence basis
- Signed contract pass
- Verification receipts
- 1
- Signing keys that built it
- 1
Declared environment
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
Verification-run environments
| Environment | Contract | Stages | Run |
|---|---|---|---|
| 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 |
Case
HOW- Goal
- verify iconv-lite.encode in pkg:npm/iconv-lite@0.4.24
- Packages
- Symbols
-
- iconv-lite.encode
- Environment
- node 22.23.2
- Created
- 2026-08-20T19:02:54Z
Contract
- assert iconv.encode encodes string to UTF-8 buffer correctly and returns a Buffer instance
- assert iconv.encode encodes legacy single-byte encodings including Windows-1252 and Windows-1251
- assert iconv.encode encodes multibyte CJK strings to EUC-KR, Shift_JIS, and GBK byte buffers
- assert iconv.encode prepends byte order mark when addBOM option is enabled
- assert iconv.encode encodes UTF-16LE and UTF-16BE buffers correctly
Files
- PROMPT.md
- csx.json
- index.js
- package-lock.json
- package.json
- spec.json
- test/contract.mjs
Source
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 iconv-lite.encode in pkg:npm/iconv-lite@0.4.24
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/iconv-lite@0.4.24
Demonstrate these symbols/APIs:
- iconv-lite.encode
Constraints:
- executionContext: node
Required runtime conditions:
- ecosystem: npm
- language: javascript
- moduleSystem: cjs
- 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:826e74e4eb3d9d23a14403156875f405317bcb46f31b1dd71027b582fb5fd558","constraints":{"executionContext":"node"},"contract":["assert iconv.encode encodes string to UTF-8 buffer correctly and returns a Buffer instance","assert iconv.encode encodes legacy single-byte encodings including Windows-1252 and Windows-1251","assert iconv.encode encodes multibyte CJK strings to EUC-KR, Shift_JIS, and GBK byte buffers","assert iconv.encode prepends byte order mark when addBOM option is enabled","assert iconv.encode encodes UTF-16LE and UTF-16BE buffers correctly"],"goal":"verify iconv-lite.encode in pkg:npm/iconv-lite@0.4.24","kind":"HOW","packages":["pkg:npm/iconv-lite@0.4.24"],"schemaVersion":1,"symbols":["iconv-lite.encode"]},"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.4.24"],"schemaVersion":1,"subject":"pkg:npm/iconv-lite@0.4.24","symbols":["iconv-lite.encode"],"verifierAdapter":"node-typescript@1"}
const iconv = require('iconv-lite');
/**
* Encodes a string into a buffer using the specified encoding.
*
* @param {string} str - The string to encode.
* @param {string} encoding - The character encoding name (e.g. 'utf-8', 'euc-kr', 'shift_jis', 'win1251', 'utf16le').
* @param {Object} [options] - Optional encoding options (e.g. { addBOM: true }).
* @returns {Buffer} The encoded binary buffer.
*/
function encodeText(str, encoding, options) {
return iconv.encode(str, encoding, options);
}
module.exports = {
encodeText,
iconv,
};
{
"name": "sample-iconv-lite-encode",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-iconv-lite-encode",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"iconv-lite": "0.4.24"
}
},
"node_modules/iconv-lite": {
"version": "0.4.24",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
"integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==",
"license": "MIT",
"dependencies": {
"safer-buffer": ">= 2.1.2 < 3"
},
"engines": {
"node": ">=0.10.0"
}
},
"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-encode",
"version": "1.0.0",
"description": "Clean-room sample verifying iconv-lite.encode functionality",
"main": "index.js",
"license": "MIT-0",
"dependencies": {
"iconv-lite": "0.4.24"
}
}
{
"schemaVersion": 1,
"goal": "verify iconv-lite.encode in pkg:npm/iconv-lite@0.4.24",
"kind": "HOW",
"packages": [
"pkg:npm/iconv-lite@0.4.24"
],
"symbols": [
"iconv-lite.encode"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"runtime": "node@22.23.2"
}
}
import assert from 'node:assert';
import iconv from 'iconv-lite';
import { encodeText } from '../index.js';
// 1. Encode string to UTF-8 buffer
const utf8Buf = encodeText('Hello, World!', 'utf-8');
assert(Buffer.isBuffer(utf8Buf), 'iconv.encode must return a Buffer instance');
assert.deepStrictEqual(
Array.from(utf8Buf),
[0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x20, 0x57, 0x6f, 0x72, 0x6c, 0x64, 0x21],
'iconv.encode must encode string to UTF-8 buffer correctly'
);
// 2. Encode legacy single-byte encodings (Windows-1252 and Windows-1251)
const win1252Buf = encodeText('Café', 'windows-1252');
assert.deepStrictEqual(
Array.from(win1252Buf),
[0x43, 0x61, 0x66, 0xe9],
'iconv.encode must encode Windows-1252 correctly'
);
const win1251Buf = encodeText('Привет', 'win1251');
assert.deepStrictEqual(
Array.from(win1251Buf),
[0xcf, 0xf0, 0xe8, 0xe2, 0xe5, 0xf2],
'iconv.encode must encode Windows-1251 correctly'
);
// 3. Encode multibyte CJK encodings (EUC-KR, Shift_JIS, GBK)
const eucKrBuf = encodeText('안녕하세요', 'euc-kr');
assert.strictEqual(
iconv.decode(eucKrBuf, 'euc-kr'),
'안녕하세요',
'iconv.encode must encode EUC-KR multibyte sequences'
);
const sjisBuf = encodeText('こんにちは', 'shift_jis');
assert.strictEqual(
iconv.decode(sjisBuf, 'shift_jis'),
'こんにちは',
'iconv.encode must encode Shift_JIS multibyte sequences'
);
const gbkBuf = encodeText('你好世界', 'gbk');
assert.strictEqual(
iconv.decode(gbkBuf, 'gbk'),
'你好世界',
'iconv.encode must encode GBK multibyte sequences'
);
// 4. UTF-8 BOM handling: addBOM option prepends 0xEF, 0xBB, 0xBF
const bomBuf = encodeText('ABC', 'utf-8', { addBOM: true });
assert.deepStrictEqual(
Array.from(bomBuf),
[0xef, 0xbb, 0xbf, 0x41, 0x42, 0x43],
'iconv.encode must prepend BOM when addBOM is true'
);
// 5. UTF-16LE and UTF-16BE encoding
const utf16leBuf = encodeText('Sample Test', 'utf-16le');
assert.strictEqual(
iconv.decode(utf16leBuf, 'utf-16le'),
'Sample Test',
'iconv.encode must encode UTF-16LE correctly'
);
const utf16beBuf = encodeText('Sample Test', 'utf-16be');
assert.strictEqual(
iconv.decode(utf16beBuf, 'utf-16be'),
'Sample Test',
'iconv.encode must encode UTF-16BE correctly'
);
console.log('All contract assertions passed.');
Origin Seeder
anonymous