CodeSampleX

샘플

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 length

sha256:0188fabe9ee4db4df167a36463d50b25d0d954440911531c68dd8d2ddcf5ee0b

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. 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

컨트랙트

  1. assert empty string returns zero byte length
  2. assert ASCII strings return byte length equal to character count
  3. assert two-byte UTF-8 characters calculate to two bytes per character
  4. assert three-byte UTF-8 characters such as CJK and currency symbols calculate to three bytes per character
  5. assert four-byte UTF-8 characters such as emojis calculate to four bytes per character
  6. assert mixed strings containing ASCII and multi-byte unicode characters return correct total byte length
  7. assert direct utf8ByteLength symbol invocation returns identical byte length
  8. 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

소스 아티팩트 내려받기 (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 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.
csx.json
{"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"}
index.js
const utf8ByteLength = require('utf8-byte-length');

function calculateUtf8ByteLength(input) {
  return utf8ByteLength(input);
}

module.exports = {
  utf8ByteLength,
  calculateUtf8ByteLength,
};
package-lock.json
{
  "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)"
    }
  }
}
package.json
{
  "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"
  }
}
spec.json
{
  "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"
  ]
}
test/contract.mjs
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.');

오리진 시더

익명