샘플
string-width 5.1.2
검증된 샘플 — npm string-width 5.1.2. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: stringWidth calculates visual display width for ASCII characters
sha256:8df4295de66c562da7e7cb71b84fdc6953ace556aac1278cf49e0071939a1350
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
MIT-0
실행 증거
선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.
- 증거 기준
- 서명된 컨트랙트 통과
- 검증 영수증
- 1
- 빌드한 서명 키
- 1
선언된 환경
linux 24 · ubuntu · glibc 2.39 x64 npm
검증 실행 환경
| 환경 | 컨트랙트 | 단계 | 실행일 |
|---|---|---|---|
| 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-23 |
케이스
HOW- 목표
- verify pkg:npm/string-width@5.1.2
- 생성일
- 2026-08-23T13:39:07Z
컨트랙트
- stringWidth calculates visual display width for ASCII characters
- stringWidth counts fullwidth CJK characters as width 2
- stringWidth counts emoji characters as width 2
- stringWidth ignores ANSI escape sequences when computing visual width
- stringWidth handles ambiguous width characters according to ambiguousIsNarrow option
- stringWidth returns 0 for empty 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 pkg:npm/string-width@5.1.2
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/string-width@5.1.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:1776d7ae384548407d3cb7d178c7818f18abbbf8de1bb4d3f59594d3b9eb868a","contract":["stringWidth calculates visual display width for ASCII characters","stringWidth counts fullwidth CJK characters as width 2","stringWidth counts emoji characters as width 2","stringWidth ignores ANSI escape sequences when computing visual width","stringWidth handles ambiguous width characters according to ambiguousIsNarrow option","stringWidth returns 0 for empty string"],"goal":"verify pkg:npm/string-width@5.1.2","kind":"HOW","packages":["pkg:npm/string-width@5.1.2"],"schemaVersion":1},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/string-width@5.1.2"],"schemaVersion":1,"subject":"pkg:npm/string-width@5.1.2","verifierAdapter":"node-typescript@1"}
import stringWidth from 'string-width';
/**
* Calculates visual display width of a string.
*
* @param {string} text - The input string to measure.
* @param {object} [options] - Options for width calculation.
* @param {boolean} [options.ambiguousIsNarrow] - Whether ambiguous characters count as width 1.
* @returns {number} Visual column width.
*/
export function getVisualWidth(text, options) {
return stringWidth(text, options);
}
export default stringWidth;
{
"name": "sample-string-width",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-string-width",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"string-width": "5.1.2"
}
},
"node_modules/ansi-regex": {
"version": "6.3.0",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.3.0.tgz",
"integrity": "sha512-WpDfL7NO6j7tH88IDBNVdUJxDh9nmCteAVW9dsep846XdwF4naCBK+/tGLX3KJgcpgMRXCFlTM2hKGoK9FsdrQ==",
"license": "MIT",
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://github.com/chalk/ansi-regex?sponsor=1"
}
},
"node_modules/eastasianwidth": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz",
"integrity": "sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==",
"license": "MIT"
},
"node_modules/emoji-regex": {
"version": "9.2.2",
"resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-9.2.2.tgz",
"integrity": "sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==",
"license": "MIT"
},
"node_modules/string-width": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-5.1.2.tgz",
"integrity": "sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA==",
"license": "MIT",
"dependencies": {
"eastasianwidth": "^0.2.0",
"emoji-regex": "^9.2.2",
"strip-ansi": "^7.0.1"
},
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/strip-ansi": {
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.2.0.tgz",
"integrity": "sha512-yDPMNjp4WyfYBkHnjIRLfca1i6KMyGCtsVgoKe/z1+6vukgaENdgGBZt+ZmKPc4gavvEZ5OgHfHdrazhgNyG7w==",
"license": "MIT",
"dependencies": {
"ansi-regex": "^6.2.2"
},
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://github.com/chalk/strip-ansi?sponsor=1"
}
}
}
}
{
"name": "sample-string-width",
"version": "1.0.0",
"description": "Clean-room sample verifying string-width functionality",
"type": "module",
"main": "index.js",
"license": "MIT-0",
"dependencies": {
"string-width": "5.1.2"
}
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/string-width@5.1.2",
"kind": "HOW",
"packages": [
"pkg:npm/string-width@5.1.2"
]
}
import assert from 'node:assert';
import stringWidth, { getVisualWidth } from '../index.js';
// 1. ASCII characters: single width
assert.strictEqual(stringWidth('hello'), 5, 'ASCII characters should have width 1 per char');
assert.strictEqual(getVisualWidth('world!'), 6, 'Wrapper function should match stringWidth');
// 2. CJK / Fullwidth characters: double width
assert.strictEqual(stringWidth('你好'), 4, 'CJK characters should have width 2');
assert.strictEqual(stringWidth('한글'), 4, 'Korean characters should have width 2');
assert.strictEqual(stringWidth('テスト'), 6, 'Japanese katakana should have width 2 per char');
// 3. Emoji: width 2
assert.strictEqual(stringWidth('🚀'), 2, 'Emoji character should have width 2');
assert.strictEqual(stringWidth('🎉'), 2, 'Emoji character should have width 2');
// 4. ANSI escape codes: stripped, width 0 for escape sequences
assert.strictEqual(stringWidth('\u001B[31mred\u001B[39m'), 3, 'ANSI color codes should not add to visual width');
assert.strictEqual(stringWidth('\u001B[1mbold\u001B[22m'), 4, 'ANSI style codes should not add to visual width');
// 5. Ambiguous width characters
// By default ambiguousIsNarrow is true -> width 1
assert.strictEqual(stringWidth('α'), 1, 'Ambiguous char defaults to width 1');
assert.strictEqual(stringWidth('α', { ambiguousIsNarrow: true }), 1, 'ambiguousIsNarrow: true gives width 1');
assert.strictEqual(stringWidth('α', { ambiguousIsNarrow: false }), 2, 'ambiguousIsNarrow: false gives width 2');
// 6. Empty and control characters
assert.strictEqual(stringWidth(''), 0, 'Empty string should have width 0');
assert.strictEqual(stringWidth('\0'), 0, 'Null character should have width 0');
console.log('All contract assertions passed.');
오리진 시더
익명