CodeSampleX

샘플

string-width 4.2.3

검증된 샘플 — npm string-width 4.2.3. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: stringWidth calculates visual column width of standard ASCII…

sha256:97136172796d6c0e5d18c3cb886120876274c0c29572d23a1f32a277fe8cf077

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

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
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-23

케이스

HOW
목표
verify pkg:npm/string-width@4.2.3
패키지
환경
node 22.23.2
생성일
2026-08-23T07:29:38Z

컨트랙트

  1. stringWidth calculates visual column width of standard ASCII characters and strings
  2. stringWidth counts fullwidth and CJK characters as visual width 2
  3. stringWidth counts emoji characters as visual width 2
  4. stringWidth strips ANSI escape sequences without counting them in visual width
  5. stringWidth returns 0 for empty strings, control characters, and non-string inputs

파일

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • test/contract.cjs

소스 아티팩트 내려받기 (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/string-width@4.2.3
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/string-width@4.2.3

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:c4d0f688d44cd954315a9de8062a81fa51ad0f692f19ba60f595acf00de44780","contract":["stringWidth calculates visual column width of standard ASCII characters and strings","stringWidth counts fullwidth and CJK characters as visual width 2","stringWidth counts emoji characters as visual width 2","stringWidth strips ANSI escape sequences without counting them in visual width","stringWidth returns 0 for empty strings, control characters, and non-string inputs"],"goal":"verify pkg:npm/string-width@4.2.3","kind":"HOW","packages":["pkg:npm/string-width@4.2.3"],"schemaVersion":1},"contractCommand":["node","test/contract.cjs"],"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/string-width@4.2.3"],"schemaVersion":1,"subject":"pkg:npm/string-width@4.2.3","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-string-width",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-string-width",
      "version": "1.0.0",
      "dependencies": {
        "string-width": "4.2.3"
      }
    },
    "node_modules/ansi-regex": {
      "version": "5.0.1",
      "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
      "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
      "license": "MIT",
      "engines": {
        "node": ">=8"
      }
    },
    "node_modules/emoji-regex": {
      "version": "8.0.0",
      "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz",
      "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==",
      "license": "MIT"
    },
    "node_modules/is-fullwidth-code-point": {
      "version": "3.0.0",
      "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz",
      "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==",
      "license": "MIT",
      "engines": {
        "node": ">=8"
      }
    },
    "node_modules/string-width": {
      "version": "4.2.3",
      "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",
      "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==",
      "license": "MIT",
      "dependencies": {
        "emoji-regex": "^8.0.0",
        "is-fullwidth-code-point": "^3.0.0",
        "strip-ansi": "^6.0.1"
      },
      "engines": {
        "node": ">=8"
      }
    },
    "node_modules/strip-ansi": {
      "version": "6.0.1",
      "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz",
      "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==",
      "license": "MIT",
      "dependencies": {
        "ansi-regex": "^5.0.1"
      },
      "engines": {
        "node": ">=8"
      }
    }
  }
}
package.json
{
  "name": "sample-string-width",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of string-width",
  "dependencies": {
    "string-width": "4.2.3"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/string-width@4.2.3",
  "kind": "HOW",
  "packages": [
    "pkg:npm/string-width@4.2.3"
  ]
}
src/index.js
'use strict';

const stringWidth = require('string-width');

/**
 * Calculate visual column width of a string.
 *
 * @param {string} input - The string to measure.
 * @returns {number} Visual column width of the string.
 */
function measureWidth(input) {
  return stringWidth(input);
}

module.exports = {
  stringWidth,
  measureWidth
};
test/contract.cjs
'use strict';

const assert = require('node:assert/strict');
const stringWidthPkg = require('string-width');
const { stringWidth, measureWidth } = require('../src/index.js');

// 1. Export verification
assert.equal(typeof stringWidth, 'function', 'stringWidth must be exported as a function');
assert.equal(typeof measureWidth, 'function', 'measureWidth must be exported as a function');
assert.equal(stringWidth, stringWidthPkg, 'stringWidth must match library export');
assert.equal(measureWidth('abc'), stringWidthPkg('abc'), 'measureWidth must delegate to stringWidth');

// 2. ASCII characters and standard strings
{
  assert.equal(stringWidth('a'), 1, 'Single ASCII character has width 1');
  assert.equal(stringWidth('hello world'), 11, 'ASCII string width equals character count');
  assert.equal(stringWidth('12345'), 5, 'Numeric string width equals digit count');
  assert.equal(stringWidth('!@#$%^&*()'), 10, 'Punctuation width equals character count');
}

// 3. Fullwidth and CJK characters
{
  assert.equal(stringWidth('古'), 2, 'Single CJK ideograph has width 2');
  assert.equal(stringWidth('你好世界'), 8, 'Four CJK ideographs have width 8');
  assert.equal(stringWidth('안녕하세요'), 10, 'Hangul syllables have width 2 each');
  assert.equal(stringWidth('カタカナ'), 8, 'Fullwidth Katakana has width 2 each');
  assert.equal(stringWidth('hello你好'), 9, 'Mixed ASCII (5) and CJK (4) has width 9');
}

// 4. Emoji and surrogate characters
{
  assert.equal(stringWidth('🦄'), 2, 'Unicorn emoji has visual width 2');
  assert.equal(stringWidth('🎉'), 2, 'Party popper emoji has visual width 2');
  assert.equal(stringWidth('🐱'), 2, 'Cat emoji has visual width 2');
  assert.equal(stringWidth('a🐱b'), 4, 'Mixed ASCII and emoji has width 4');
}

// 5. ANSI escape sequences
{
  const colored = '\u001B[31mred\u001B[39m';
  assert.equal(stringWidth(colored), 3, 'ANSI color codes are ignored in width calculation');
  const styled = '\u001B[1m\u001B[4mbold underline\u001B[24m\u001B[22m';
  assert.equal(stringWidth(styled), 14, 'ANSI style sequences are ignored in width calculation');
}

// 6. Empty strings, control characters, and non-string inputs
{
  assert.equal(stringWidth(''), 0, 'Empty string has width 0');
  assert.equal(stringWidth('\x00\x01\x1F'), 0, 'Control characters are ignored and have width 0');
  assert.equal(stringWidth(null), 0, 'Null input returns 0');
  assert.equal(stringWidth(undefined), 0, 'Undefined input returns 0');
}

console.log('Contract test passed.');

오리진 시더

익명