サンプル
utf8-byte-length 1.0.5: utf8ByteLength
検証済みサンプル — npm utf8-byte-length 1.0.5: utf8ByteLength. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました: assert empty string returns zero byte…
sha256:0188fabe9ee4db4df167a36463d50b25d0d954440911531c68dd8d2ddcf5ee0b
このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。
合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。
MIT-0
実行証拠
宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。
- 証拠の基準
- 署名済みコントラクト合格
- 検証レシート
- 2
- ビルドした署名鍵
- 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@1node:22-alpine@sha256:c610fcdfb1d5… |
2026-08-26 |
| 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-07 |
ケース
HOW- ゴール
- verify utf8ByteLength in pkg:npm/utf8-byte-length@1.0.5
- パッケージ
- シンボル
-
- utf8ByteLength
- 環境
- node 22.23.2
- 作成日
- 2026-08-26T11:22:35Z
コントラクト
- assert empty string returns zero byte length
- assert ASCII strings return byte length equal to character count
- assert two-byte UTF-8 characters calculate to two bytes per character
- assert three-byte UTF-8 characters such as CJK and currency symbols calculate to three bytes per character
- assert four-byte UTF-8 characters such as emojis calculate to four bytes per character
- assert mixed strings containing ASCII and multi-byte unicode characters return correct total byte length
- assert direct utf8ByteLength symbol invocation returns identical byte length
- assert non-string inputs throw an Error indicating input must be string
ファイル
- 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 utf8ByteLength in pkg:npm/utf8-byte-length@1.0.5
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/utf8-byte-length@1.0.5
Demonstrate these symbols/APIs:
- utf8ByteLength
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:73593877e43fb56e32ada3db4ab9ca2dde0035863a55ff66f8619c82e55e294b","contract":["assert empty string returns zero byte length","assert ASCII strings return byte length equal to character count","assert two-byte UTF-8 characters calculate to two bytes per character","assert three-byte UTF-8 characters such as CJK and currency symbols calculate to three bytes per character","assert four-byte UTF-8 characters such as emojis calculate to four bytes per character","assert mixed strings containing ASCII and multi-byte unicode characters return correct total byte length","assert direct utf8ByteLength symbol invocation returns identical byte length","assert non-string inputs throw an Error indicating input must be string"],"goal":"verify utf8ByteLength in pkg:npm/utf8-byte-length@1.0.5","kind":"HOW","packages":["pkg:npm/utf8-byte-length@1.0.5"],"schemaVersion":1,"symbols":["utf8ByteLength"]},"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/utf8-byte-length@1.0.5"],"schemaVersion":1,"subject":"pkg:npm/utf8-byte-length@1.0.5","symbols":["utf8ByteLength"],"verifierAdapter":"node-typescript@1"}
const utf8ByteLength = require('utf8-byte-length');
function calculateUtf8ByteLength(input) {
return utf8ByteLength(input);
}
module.exports = {
utf8ByteLength,
calculateUtf8ByteLength,
};
{
"name": "sample-utf8-byte-length",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-utf8-byte-length",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"utf8-byte-length": "1.0.5"
}
},
"node_modules/utf8-byte-length": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/utf8-byte-length/-/utf8-byte-length-1.0.5.tgz",
"integrity": "sha512-Xn0w3MtiQ6zoz2vFyUVruaCL53O/DwUvkEeOvj+uulMm0BkUGYWmBYVyElqZaSLhY6ZD0ulfU3aBra2aVT4xfA==",
"license": "(WTFPL OR MIT)"
}
}
}
{
"name": "sample-utf8-byte-length",
"version": "1.0.0",
"description": "Minimal clean-room sample verifying utf8ByteLength in utf8-byte-length",
"main": "index.js",
"license": "MIT-0",
"dependencies": {
"utf8-byte-length": "1.0.5"
}
}
{
"schemaVersion": 1,
"goal": "verify utf8ByteLength in pkg:npm/utf8-byte-length@1.0.5",
"kind": "HOW",
"packages": [
"pkg:npm/utf8-byte-length@1.0.5"
],
"symbols": [
"utf8ByteLength"
]
}
import assert from 'node:assert';
import utf8ByteLength from 'utf8-byte-length';
import { calculateUtf8ByteLength } from '../index.js';
// 1. Empty string returns 0 bytes
const emptyLen = calculateUtf8ByteLength('');
assert.strictEqual(emptyLen, 0, 'Empty string must return 0 bytes');
// 2. ASCII strings return byte length equal to character count
const asciiStr = 'Hello, World!';
const asciiLen = calculateUtf8ByteLength(asciiStr);
assert.strictEqual(asciiLen, asciiStr.length, 'ASCII string byte length must match character count');
assert.strictEqual(asciiLen, 13, 'ASCII string "Hello, World!" must be 13 bytes');
// 3. Two-byte UTF-8 characters calculate to 2 bytes per character
const twoByteStr = 'café';
const twoByteLen = calculateUtf8ByteLength(twoByteStr);
assert.strictEqual(twoByteLen, 5, 'String "café" must have byte length of 5');
const latinGreekStr = 'αβγ';
assert.strictEqual(calculateUtf8ByteLength(latinGreekStr), 6, 'Three 2-byte Greek characters must be 6 bytes');
// 4. Three-byte UTF-8 characters such as CJK characters and currency symbols calculate to 3 bytes per character
const euroSymbol = '€';
assert.strictEqual(calculateUtf8ByteLength(euroSymbol), 3, 'Euro symbol "€" must be 3 bytes');
const cjkStr = '한국어';
assert.strictEqual(calculateUtf8ByteLength(cjkStr), 9, 'Three CJK characters must be 9 bytes');
// 5. Four-byte UTF-8 characters such as emojis calculate to 4 bytes per character
const emojiStr = '🚀';
assert.strictEqual(calculateUtf8ByteLength(emojiStr), 4, 'Rocket emoji "🚀" must be 4 bytes');
const multipleEmojis = '👍🎉🌟';
assert.strictEqual(calculateUtf8ByteLength(multipleEmojis), 12, 'Three 4-byte emojis must be 12 bytes');
// 6. Mixed strings containing ASCII and multi-byte unicode characters return correct total byte length
const mixedStr = 'CodeSampleX 🚀 한국어 café €100';
const expectedMixedLength = Buffer.byteLength(mixedStr, 'utf8');
assert.strictEqual(
calculateUtf8ByteLength(mixedStr),
expectedMixedLength,
'Mixed unicode string byte length must match Buffer.byteLength'
);
// 7. Direct symbol invocation produces identical results
assert.strictEqual(
utf8ByteLength('Hello 🌍'),
Buffer.byteLength('Hello 🌍', 'utf8'),
'Direct utf8ByteLength invocation must return correct byte length'
);
// 8. Non-string inputs throw an Error indicating input must be string
const invalidInputs = [123, true, false, null, undefined, {}, [], Symbol('test')];
for (const invalid of invalidInputs) {
assert.throws(
() => calculateUtf8ByteLength(invalid),
{
name: 'Error',
message: 'Input must be string',
},
`Expected error for invalid input: ${String(invalid)}`
);
}
console.log('All utf8-byte-length contract assertions passed.');
オリジンシーダー
匿名