CodeSampleX

サンプル

wrap-ansi 8.1.0

検証済みサンプル — npm wrap-ansi 8.1.0. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました: wrapAnsi wraps plain text to specified column width at word…

sha256:d629a0c5f54ec2d5afc94f0cd8830821d4f325981e2d97ab6b300254a96a418a

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 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/wrap-ansi@8.1.0
パッケージ
作成日
2026-08-23T07:27:01Z

コントラクト

  1. wrapAnsi wraps plain text to specified column width at word boundaries
  2. wrapAnsi preserves and reopens ANSI styling codes across wrapped lines
  3. wrapAnsi breaks words exceeding column width when hard option is true
  4. wrapAnsi preserves leading and trailing whitespace when trim option is false
  5. wrapAnsi splits on character boundaries rather than words when wordWrap option is false

ファイル

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • 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 pkg:npm/wrap-ansi@8.1.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/wrap-ansi@8.1.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:3b29aaea03280445ab8752eb99c4d7205db87d012df42c675da3cb4aea1e99ed","contract":["wrapAnsi wraps plain text to specified column width at word boundaries","wrapAnsi preserves and reopens ANSI styling codes across wrapped lines","wrapAnsi breaks words exceeding column width when hard option is true","wrapAnsi preserves leading and trailing whitespace when trim option is false","wrapAnsi splits on character boundaries rather than words when wordWrap option is false"],"goal":"verify pkg:npm/wrap-ansi@8.1.0","kind":"HOW","packages":["pkg:npm/wrap-ansi@8.1.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/wrap-ansi@8.1.0"],"schemaVersion":1,"subject":"pkg:npm/wrap-ansi@8.1.0","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-wrap-ansi",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-wrap-ansi",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "wrap-ansi": "8.1.0"
      }
    },
    "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/ansi-styles": {
      "version": "6.2.3",
      "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-6.2.3.tgz",
      "integrity": "sha512-4Dj6M28JB+oAH8kFkTLUo+a2jwOFkuqb3yucU0CANcRRUbxS0cP0nZYCGjcc3BNXwRIsUVmDGgzawme7zvJHvg==",
      "license": "MIT",
      "engines": {
        "node": ">=12"
      },
      "funding": {
        "url": "https://github.com/chalk/ansi-styles?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"
      }
    },
    "node_modules/wrap-ansi": {
      "version": "8.1.0",
      "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-8.1.0.tgz",
      "integrity": "sha512-si7QWI6zUMq56bESFvagtmzMdGOtoxfR+Sez11Mobfc7tm+VkUckk9bW2UeffTGVUbOksxmSw0AA2gs8g71NCQ==",
      "license": "MIT",
      "dependencies": {
        "ansi-styles": "^6.1.0",
        "string-width": "^5.0.1",
        "strip-ansi": "^7.0.1"
      },
      "engines": {
        "node": ">=12"
      },
      "funding": {
        "url": "https://github.com/chalk/wrap-ansi?sponsor=1"
      }
    }
  }
}
package.json
{
  "name": "sample-wrap-ansi",
  "version": "1.0.0",
  "description": "Clean-room verification of wrap-ansi word wrapping and ANSI styling preservation",
  "type": "module",
  "main": "src/index.js",
  "license": "MIT-0",
  "dependencies": {
    "wrap-ansi": "8.1.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/wrap-ansi@8.1.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/wrap-ansi@8.1.0"
  ]
}
src/index.js
import wrapAnsi from 'wrap-ansi';

/**
 * Wrap text to a given column width with word wrapping and ANSI style preservation.
 *
 * @param {string} text - Input text containing optional ANSI escape codes.
 * @param {number} columns - Target column width.
 * @param {object} [options] - Wrapping options (hard, trim, wordWrap).
 * @returns {string} Wrapped text.
 */
export function formatTerminalText(text, columns, options) {
  return wrapAnsi(text, columns, options);
}

/**
 * Hard wrap long text breaking long words at the column boundary.
 *
 * @param {string} text - Input text.
 * @param {number} columns - Column width.
 * @returns {string} Hard-wrapped text.
 */
export function hardWrapText(text, columns) {
  return wrapAnsi(text, columns, { hard: true });
}

/**
 * Wrap text while preserving leading and trailing whitespace.
 *
 * @param {string} text - Input text.
 * @param {number} columns - Column width.
 * @returns {string} Wrapped text preserving whitespace.
 */
export function wrapPreservingWhitespace(text, columns) {
  return wrapAnsi(text, columns, { trim: false });
}

/**
 * Wrap text character by character ignoring word boundaries.
 *
 * @param {string} text - Input text.
 * @param {number} columns - Column width.
 * @returns {string} Character-wrapped text.
 */
export function wrapByCharacters(text, columns) {
  return wrapAnsi(text, columns, { wordWrap: false });
}

export default wrapAnsi;
test/contract.mjs
import assert from 'node:assert/strict';
import wrapAnsi, {
  formatTerminalText,
  hardWrapText,
  wrapPreservingWhitespace,
  wrapByCharacters,
} from '../src/index.js';
import directWrapAnsi from 'wrap-ansi';

// Export check
assert.equal(typeof wrapAnsi, 'function', 'wrapAnsi must be a function');
assert.equal(wrapAnsi, directWrapAnsi, 'default export must match wrap-ansi');

// 1. wrapAnsi wraps plain text to specified column width at word boundaries
{
  const input = 'The quick brown fox jumped over the lazy dog';
  const result = formatTerminalText(input, 15);
  const lines = result.split('\n');
  assert.deepEqual(lines, [
    'The quick brown',
    'fox jumped over',
    'the lazy dog',
  ], 'Plain text should wrap at word boundaries within column limit');
  assert.ok(lines.every((line) => line.length <= 15), 'Every line must be within 15 columns');
}

// 2. wrapAnsi preserves and reopens ANSI styling codes across wrapped lines
{
  const greenStart = '\u001b[32m';
  const greenEnd = '\u001b[39m';
  const input = `${greenStart}hello green world today${greenEnd}`;
  const result = wrapAnsi(input, 11);
  const lines = result.split('\n');
  assert.equal(lines.length, 2, 'Should wrap into 2 lines');
  assert.equal(lines[0], `${greenStart}hello green${greenEnd}`, 'First line must reopen and close ANSI code');
  assert.equal(lines[1], `${greenStart}world today${greenEnd}`, 'Second line must reopen and close ANSI code');
}

// 3. wrapAnsi breaks words exceeding column width when hard option is true
{
  const input = 'supercalifragilisticexpialidocious';
  const result = hardWrapText(input, 10);
  const lines = result.split('\n');
  assert.deepEqual(lines, [
    'supercalif',
    'ragilistic',
    'expialidoc',
    'ious',
  ], 'Long word must break at column limit when hard is true');
}

// 4. wrapAnsi preserves leading and trailing whitespace when trim option is false
{
  const input = '   leading and trailing   ';
  const result = wrapPreservingWhitespace(input, 10);
  const expected = '   leading\n and \ntrailing  \n ';
  assert.equal(result, expected, 'Whitespace should be preserved across wrapped lines when trim is false');
}

// 5. wrapAnsi splits on character boundaries rather than words when wordWrap option is false
{
  const input = 'hello world';
  const result = wrapByCharacters(input, 3);
  const lines = result.split('\n');
  assert.deepEqual(lines, [
    'hel',
    'lo',
    'wor',
    'ld',
  ], 'Text must wrap strictly at column intervals when wordWrap is false');
}

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

オリジンシーダー

匿名