CodeSampleX

Exemple

is-fullwidth-code-point 3.0.0

Échantillon vérifié pour npm is-fullwidth-code-point 3.0.0. Le contrat s'est exécuté sur node 22 · linux alpine/x64 · docker et a réussi.

sha256:aa6fdf87bad9070deaf4e9e1f1ca023eb2bbee9ffff73b305fe5900cba19f6fd

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é linux 24 · ubuntu · glibc 2.39 x64 npm

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/is-fullwidth-code-point@3.0.0
Paquets
Créé
2026-08-23T07:53:13Z

Contrat

  1. isFullwidthCodePoint returns true for CJK unified ideographs and Hangul syllables
  2. isFullwidthCodePoint returns true for fullwidth ASCII variants and CJK punctuation
  3. isFullwidthCodePoint returns true for supplementary plane ideographs
  4. isFullwidthCodePoint returns false for standard ASCII characters and whitespace
  5. isFullwidthCodePoint returns false for NaN or invalid code points
  6. checkCodePoint and isCharFullwidth helper functions correctly determine fullwidth status from code points and strings
  7. calculateStringWidth calculates display width by counting 2 columns for fullwidth characters and 1 column for standard characters

Fichiers

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

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/is-fullwidth-code-point@3.0.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/is-fullwidth-code-point@3.0.0

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:f76c6f46a804808daea252b1eeaaf6bce3c430b62d2f7c58075ba5c221591039","contract":["isFullwidthCodePoint returns true for CJK unified ideographs and Hangul syllables","isFullwidthCodePoint returns true for fullwidth ASCII variants and CJK punctuation","isFullwidthCodePoint returns true for supplementary plane ideographs","isFullwidthCodePoint returns false for standard ASCII characters and whitespace","isFullwidthCodePoint returns false for NaN or invalid code points","checkCodePoint and isCharFullwidth helper functions correctly determine fullwidth status from code points and strings","calculateStringWidth calculates display width by counting 2 columns for fullwidth characters and 1 column for standard characters"],"goal":"verify pkg:npm/is-fullwidth-code-point@3.0.0","kind":"HOW","packages":["pkg:npm/is-fullwidth-code-point@3.0.0"],"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/is-fullwidth-code-point@3.0.0"],"schemaVersion":1,"subject":"pkg:npm/is-fullwidth-code-point@3.0.0","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-is-fullwidth-code-point",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-is-fullwidth-code-point",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "is-fullwidth-code-point": "3.0.0"
      }
    },
    "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"
      }
    }
  }
}
package.json
{
  "name": "sample-is-fullwidth-code-point",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of pkg:npm/is-fullwidth-code-point@3.0.0",
  "main": "src/index.mjs",
  "type": "module",
  "license": "MIT-0",
  "dependencies": {
    "is-fullwidth-code-point": "3.0.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/is-fullwidth-code-point@3.0.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/is-fullwidth-code-point@3.0.0"
  ]
}
src/index.mjs
import isFullwidthCodePoint from "is-fullwidth-code-point";

/**
 * Checks whether a given Unicode code point is fullwidth.
 *
 * @param {number} codePoint - The Unicode code point to test.
 * @returns {boolean} True if the code point is fullwidth, false otherwise.
 */
export function checkCodePoint(codePoint) {
  return isFullwidthCodePoint(codePoint);
}

/**
 * Checks whether a character at the specified index in a string is fullwidth.
 *
 * @param {string} str - The input string.
 * @param {number} [index=0] - Character index.
 * @returns {boolean} True if character at index is fullwidth.
 */
export function isCharFullwidth(str, index = 0) {
  const codePoint = str.codePointAt(index);
  if (codePoint === undefined) {
    return false;
  }
  return isFullwidthCodePoint(codePoint);
}

/**
 * Calculates the display width of a string considering fullwidth characters (width 2) vs standard characters (width 1).
 *
 * @param {string} str - The string to measure.
 * @returns {number} The calculated column width.
 */
export function calculateStringWidth(str) {
  let width = 0;
  for (const char of str) {
    const cp = char.codePointAt(0);
    width += isFullwidthCodePoint(cp) ? 2 : 1;
  }
  return width;
}

export { isFullwidthCodePoint };
export default isFullwidthCodePoint;
test/contract.mjs
import assert from "node:assert/strict";
import isFullwidthCodePoint, {
  checkCodePoint,
  isCharFullwidth,
  calculateStringWidth,
} from "../src/index.mjs";

function testCJKAndHangul() {
  // Hangul Jamo (0x1100 - 0x115F)
  assert.strictEqual(isFullwidthCodePoint(0x1100), true, "Hangul Jamo should be fullwidth");
  assert.strictEqual(isFullwidthCodePoint(0x115f), true, "Hangul Jamo end should be fullwidth");

  // Hangul Syllables (0xAC00 - 0xD7A3)
  assert.strictEqual(isFullwidthCodePoint(0xac00), true, "Hangul syllable '가' should be fullwidth");
  assert.strictEqual(isFullwidthCodePoint(0xd7a3), true, "Hangul syllable '힣' should be fullwidth");

  // CJK Unified Ideographs (0x4E00 - 0xA4C6)
  assert.strictEqual(isFullwidthCodePoint(0x4e00), true, "CJK ideograph '一' should be fullwidth");
  assert.strictEqual(isFullwidthCodePoint(0x9fa5), true, "CJK ideograph should be fullwidth");
}

function testFullwidthVariantsAndSymbols() {
  // Fullwidth Forms (0xFF01 - 0xFF60, 0xFFE0 - 0xFFE6)
  assert.strictEqual(isFullwidthCodePoint(0xff01), true, "Fullwidth exclamation mark should be fullwidth");
  assert.strictEqual(isFullwidthCodePoint(0xff21), true, "Fullwidth Latin capital A should be fullwidth");
  assert.strictEqual(isFullwidthCodePoint(0xffe0), true, "Fullwidth cent sign should be fullwidth");

  // Angle brackets
  assert.strictEqual(isFullwidthCodePoint(0x2329), true, "Left-pointing angle bracket should be fullwidth");
  assert.strictEqual(isFullwidthCodePoint(0x232a), true, "Right-pointing angle bracket should be fullwidth");
}

function testSupplementaryPlanes() {
  // Supplementary Ideographic Plane (0x20000 - 0x3FFFD)
  assert.strictEqual(isFullwidthCodePoint(0x20000), true, "Extension B ideograph should be fullwidth");
  assert.strictEqual(isFullwidthCodePoint(0x2a6d6), true, "Supplementary ideograph should be fullwidth");
}

function testStandardAsciiAndNarrow() {
  // ASCII Latin letters and numbers
  assert.strictEqual(isFullwidthCodePoint(0x41), false, "ASCII 'A' is not fullwidth");
  assert.strictEqual(isFullwidthCodePoint(0x61), false, "ASCII 'a' is not fullwidth");
  assert.strictEqual(isFullwidthCodePoint(0x30), false, "ASCII '0' is not fullwidth");
  assert.strictEqual(isFullwidthCodePoint(0x20), false, "ASCII space is not fullwidth");

  // Halfwidth Katakana (0xFF61 - 0xFFDC) are not fullwidth
  assert.strictEqual(isFullwidthCodePoint(0xff61), false, "Halfwidth ideographic full stop is not fullwidth");
  assert.strictEqual(isFullwidthCodePoint(0xff71), false, "Halfwidth Katakana letter A is not fullwidth");
}

function testInvalidAndNaN() {
  assert.strictEqual(isFullwidthCodePoint(NaN), false, "NaN should return false");
  assert.strictEqual(isFullwidthCodePoint(Number.NaN), false, "Number.NaN should return false");
}

function testHelperFunctions() {
  assert.strictEqual(checkCodePoint(0xac00), true);
  assert.strictEqual(checkCodePoint(0x41), false);

  assert.strictEqual(isCharFullwidth("가나다", 0), true);
  assert.strictEqual(isCharFullwidth("abc", 0), false);
  assert.strictEqual(isCharFullwidth("", 0), false);

  // String width calculation: 'Hello 세계!' -> 5 (Hello) + 1 (space) + 2*2 (세계) + 1 (!) = 11
  const text = "Hello 세계!";
  assert.strictEqual(calculateStringWidth(text), 11, "Width of 'Hello 세계!' should be 11");
  assert.strictEqual(calculateStringWidth(""), 0);
  assert.strictEqual(calculateStringWidth("全角"), 4);
}

function main() {
  testCJKAndHangul();
  testFullwidthVariantsAndSymbols();
  testSupplementaryPlanes();
  testStandardAsciiAndNarrow();
  testInvalidAndNaN();
  testHelperFunctions();

  console.log("All pkg:npm/is-fullwidth-code-point@3.0.0 contracts passed successfully.");
}

main();

Seeder d'origine

anonyme