CodeSampleX

サンプル

utf8-byte-length 1.0.5

検証済みサンプル — npm utf8-byte-length 1.0.5. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました: utf8ByteLength returns 0 bytes for an empty string

sha256:ddd82985346606f111b4e743db8ac139292693152fdebe6746ac171376cf1cbc

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。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@1
2026-08-21
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 pkg:npm/utf8-byte-length@1.0.5
パッケージ
環境
node 22.23.2
作成日
2026-08-21T05:22:35Z

コントラクト

  1. utf8ByteLength returns 0 bytes for an empty string
  2. utf8ByteLength calculates 1 byte per ASCII character
  3. utf8ByteLength calculates 2 bytes per 2-byte UTF-8 character
  4. utf8ByteLength calculates 3 bytes per 3-byte UTF-8 character
  5. utf8ByteLength calculates 4 bytes per 4-byte UTF-8 character such as emojis
  6. utf8ByteLength calculates the exact total byte length for mixed multi-byte strings
  7. utf8ByteLength throws an Error when passed non-string inputs

ファイル

  • PROMPT.md
  • csx.json
  • index.js
  • 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/utf8-byte-length@1.0.5
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/utf8-byte-length@1.0.5
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.
csx.json
{"case":{"caseId":"case:sha256:ca5410aa997c02bb32ae7fa6bddb355d94443017d1362653f0ddb506cb7832e6","constraints":{"executionContext":"node"},"contract":["utf8ByteLength returns 0 bytes for an empty string","utf8ByteLength calculates 1 byte per ASCII character","utf8ByteLength calculates 2 bytes per 2-byte UTF-8 character","utf8ByteLength calculates 3 bytes per 3-byte UTF-8 character","utf8ByteLength calculates 4 bytes per 4-byte UTF-8 character such as emojis","utf8ByteLength calculates the exact total byte length for mixed multi-byte strings","utf8ByteLength throws an Error when passed non-string inputs"],"goal":"verify pkg:npm/utf8-byte-length@1.0.5","kind":"HOW","packages":["pkg:npm/utf8-byte-length@1.0.5"],"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/utf8-byte-length@1.0.5"],"schemaVersion":1,"subject":"pkg:npm/utf8-byte-length@1.0.5","verifierAdapter":"node-typescript@1"}
index.js
'use strict';

const utf8ByteLength = require('utf8-byte-length');

function calculatePayloadSize(text) {
  return utf8ByteLength(text);
}

module.exports = {
  calculatePayloadSize,
};
package-lock.json
{
  "name": "sample",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample",
      "version": "1.0.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)"
    }
  }
}
package.json
{
  "name": "sample",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of utf8-byte-length",
  "main": "index.js",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "utf8-byte-length": "1.0.5"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/utf8-byte-length@1.0.5",
  "kind": "HOW",
  "packages": [
    "pkg:npm/utf8-byte-length@1.0.5"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.mjs
import assert from 'node:assert/strict';
import utf8ByteLength from 'utf8-byte-length';
import { calculatePayloadSize } from '../index.js';

// 1. utf8ByteLength returns 0 bytes for an empty string
assert.equal(utf8ByteLength(''), 0);
assert.equal(calculatePayloadSize(''), 0);

// 2. utf8ByteLength calculates 1 byte per ASCII character
assert.equal(utf8ByteLength('a'), 1);
assert.equal(utf8ByteLength('hello world'), 11);
assert.equal(calculatePayloadSize('12345'), 5);

// 3. utf8ByteLength calculates 2 bytes per 2-byte UTF-8 character
assert.equal(utf8ByteLength('é'), 2);
assert.equal(utf8ByteLength('ñ'), 2);
assert.equal(utf8ByteLength('α'), 2);
assert.equal(utf8ByteLength('д'), 2);

// 4. utf8ByteLength calculates 3 bytes per 3-byte UTF-8 character
assert.equal(utf8ByteLength('한'), 3);
assert.equal(utf8ByteLength('글'), 3);
assert.equal(utf8ByteLength('日'), 3);
assert.equal(utf8ByteLength('本'), 3);
assert.equal(utf8ByteLength('語'), 3);
assert.equal(utf8ByteLength('€'), 3);

// 5. utf8ByteLength calculates 4 bytes per 4-byte UTF-8 character such as emojis
assert.equal(utf8ByteLength('🚀'), 4);
assert.equal(utf8ByteLength('🎉'), 4);
assert.equal(utf8ByteLength('👍'), 4);

// 6. utf8ByteLength calculates the exact total byte length for mixed multi-byte strings
assert.equal(utf8ByteLength('Hello, 世界! 🚀'), 19);
assert.equal(calculatePayloadSize('Hello, 世界! 🚀'), 19);

// 7. utf8ByteLength throws an Error when passed non-string inputs
assert.throws(() => utf8ByteLength(null), {
  name: 'Error',
  message: 'Input must be string',
});
assert.throws(() => utf8ByteLength(undefined), {
  name: 'Error',
  message: 'Input must be string',
});
assert.throws(() => utf8ByteLength(12345), {
  name: 'Error',
  message: 'Input must be string',
});
assert.throws(() => utf8ByteLength({}), {
  name: 'Error',
  message: 'Input must be string',
});
assert.throws(() => utf8ByteLength(true), {
  name: 'Error',
  message: 'Input must be string',
});

console.log('All contract assertions passed.');

オリジンシーダー

匿名