CodeSampleX

Exemple

string-width 4.2.3

Échantillon vérifié pour npm string-width 4.2.3. Le contrat s'est exécuté sur node 22 · linux alpine/x64 · docker et a réussi.

sha256:97136172796d6c0e5d18c3cb886120876274c0c29572d23a1f32a277fe8cf077

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
1
Clés de signature qui l’ont compilé
1
Environnement déclaré node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
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

Cas

HOW
Objectif
verify pkg:npm/string-width@4.2.3
Paquets
Environnement
node 22.23.2
Créé
2026-08-23T07:29:38Z

Contrat

  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

Fichiers

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

Télécharger l’artefact source (tar.gz)

Code source

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.');

Seeder d'origine

anonyme