CodeSampleX

샘플

ansi-escapes 4.3.2: default

검증된 샘플 — npm ansi-escapes 4.3.2: default. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: ansiEscapes.default provides the default export…

sha256:9b8e817032c74d24bece7903eaf0ec9f5f23146bbb672bca64fb681ce60b75c0

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

실행 증거

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

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

검증 실행 환경

환경 컨트랙트 단계 실행일
node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2…
2026-09-05

케이스

HOW
목표
verify ansi-escapes.default in pkg:npm/ansi-escapes@4.3.2
패키지
심벌
  • ansi-escapes.default
환경
node 22.23.2
생성일
2026-09-05T18:22:41Z

컨트랙트

  1. ansiEscapes.default provides the default export referencing the ansiEscapes function and property suite
  2. cursorTo generates absolute cursor positioning ANSI escape sequences for given column and row coordinates
  3. cursorTo throws a TypeError when the x coordinate argument is missing or not a number
  4. cursorMove generates relative cursor movement ANSI escape sequences for horizontal and vertical offsets
  5. cursorUp, cursorDown, cursorForward, and cursorBackward produce directional cursor displacement codes
  6. eraseLines produces ANSI escape sequences to clear the specified number of terminal lines
  7. link produces OSC 8 terminal hyperlink escape sequences for given text and URL
  8. clearScreen and clearTerminal emit terminal clearing ANSI escape sequences

파일

  • 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 ansi-escapes.default in pkg:npm/ansi-escapes@4.3.2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/ansi-escapes@4.3.2
Demonstrate these symbols/APIs:
  - ansi-escapes.default

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:0544c427bd52d56e611d9127f88b05f080732bb5f53433bfed1482e948792cff","contract":["ansiEscapes.default provides the default export referencing the ansiEscapes function and property suite","cursorTo generates absolute cursor positioning ANSI escape sequences for given column and row coordinates","cursorTo throws a TypeError when the x coordinate argument is missing or not a number","cursorMove generates relative cursor movement ANSI escape sequences for horizontal and vertical offsets","cursorUp, cursorDown, cursorForward, and cursorBackward produce directional cursor displacement codes","eraseLines produces ANSI escape sequences to clear the specified number of terminal lines","link produces OSC 8 terminal hyperlink escape sequences for given text and URL","clearScreen and clearTerminal emit terminal clearing ANSI escape sequences"],"goal":"verify ansi-escapes.default in pkg:npm/ansi-escapes@4.3.2","kind":"HOW","packages":["pkg:npm/ansi-escapes@4.3.2"],"schemaVersion":1,"symbols":["ansi-escapes.default"]},"contractCommand":["node","test/contract.mjs"],"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/ansi-escapes@4.3.2"],"schemaVersion":1,"subject":"pkg:npm/ansi-escapes@4.3.2","symbols":["ansi-escapes.default"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-ansi-escapes",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-ansi-escapes",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "ansi-escapes": "4.3.2"
      }
    },
    "node_modules/ansi-escapes": {
      "version": "4.3.2",
      "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-4.3.2.tgz",
      "integrity": "sha512-gKXj5ALrKWQLsYG9jlTRmR/xKluxHV+Z9QEwNIgCfM1/uwPMCuzVVnh5mwTd+OuBZcwSIMbqssNWRm1lE51QaQ==",
      "license": "MIT",
      "dependencies": {
        "type-fest": "^0.21.3"
      },
      "engines": {
        "node": ">=8"
      },
      "funding": {
        "url": "https://github.com/sponsors/sindresorhus"
      }
    },
    "node_modules/type-fest": {
      "version": "0.21.3",
      "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.21.3.tgz",
      "integrity": "sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w==",
      "license": "(MIT OR CC0-1.0)",
      "engines": {
        "node": ">=10"
      },
      "funding": {
        "url": "https://github.com/sponsors/sindresorhus"
      }
    }
  }
}
package.json
{
  "name": "sample-ansi-escapes",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room code sample for ansi-escapes@4.3.2",
  "main": "src/index.js",
  "license": "MIT-0",
  "dependencies": {
    "ansi-escapes": "4.3.2"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify ansi-escapes.default in pkg:npm/ansi-escapes@4.3.2",
  "kind": "HOW",
  "packages": [
    "pkg:npm/ansi-escapes@4.3.2"
  ],
  "symbols": [
    "ansi-escapes.default"
  ]
}
src/index.js
'use strict';

const ansiEscapes = require('ansi-escapes');

/**
 * Returns the default ansiEscapes instance.
 * Verifies that ansiEscapes and ansiEscapes.default point to the API.
 *
 * @returns {object} The ansi-escapes API object.
 */
function getDefaultExport() {
  return ansiEscapes.default || ansiEscapes;
}

/**
 * Positions cursor at (x, y) coordinates using cursorTo.
 *
 * @param {number} x - 0-based column coordinate.
 * @param {number} [y] - 0-based row coordinate.
 * @returns {string} ANSI escape sequence.
 */
function positionCursor(x, y) {
  const escapes = getDefaultExport();
  return escapes.cursorTo(x, y);
}

/**
 * Moves cursor relative to current position using cursorMove.
 *
 * @param {number} x - Horizontal relative movement.
 * @param {number} [y] - Vertical relative movement.
 * @returns {string} ANSI escape sequence.
 */
function moveCursor(x, y) {
  const escapes = getDefaultExport();
  return escapes.cursorMove(x, y);
}

/**
 * Formats a terminal hyperlink using link(text, url).
 *
 * @param {string} text - Display text.
 * @param {string} url - Target URL.
 * @returns {string} OSC 8 ANSI escape sequence.
 */
function createHyperlink(text, url) {
  const escapes = getDefaultExport();
  return escapes.link(text, url);
}

/**
 * Generates ANSI sequence to erase specified number of lines.
 *
 * @param {number} count - Number of lines to erase.
 * @returns {string} ANSI escape sequence.
 */
function eraseLines(count) {
  const escapes = getDefaultExport();
  return escapes.eraseLines(count);
}

module.exports = {
  ansiEscapes,
  getDefaultExport,
  positionCursor,
  moveCursor,
  createHyperlink,
  eraseLines
};
test/contract.mjs
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';
import ansiEscapesDirect from 'ansi-escapes';

const require = createRequire(import.meta.url);
const {
  ansiEscapes,
  getDefaultExport,
  positionCursor,
  moveCursor,
  createHyperlink,
  eraseLines
} = require('../src/index.js');

async function testAll() {
  // 1. Default export verification
  assert.ok(ansiEscapes, 'ansiEscapes export must exist');
  assert.equal(typeof ansiEscapes, 'object', 'ansiEscapes must be an object');
  assert.equal(ansiEscapes.default, ansiEscapes, 'ansiEscapes.default must reference ansiEscapes itself');
  assert.equal(ansiEscapesDirect, ansiEscapes, 'ESM default import must match CJS export');
  assert.equal(getDefaultExport(), ansiEscapes, 'getDefaultExport must return the default instance');

  // 2. cursorTo behavior and validation
  assert.equal(typeof ansiEscapes.cursorTo, 'function', 'cursorTo must be a function');
  assert.equal(ansiEscapes.cursorTo(0, 0), '\u001B[1;1H', 'cursorTo(0, 0) should position at row 1 col 1');
  assert.equal(ansiEscapes.cursorTo(4, 2), '\u001B[3;5H', 'cursorTo(4, 2) should position at row 3 col 5');
  assert.equal(ansiEscapes.cursorTo(7), '\u001B[8G', 'cursorTo(7) should position at col 8');
  assert.equal(positionCursor(2, 3), '\u001B[4;3H', 'positionCursor helper matches cursorTo output');

  assert.throws(
    () => ansiEscapes.cursorTo(),
    {
      name: 'TypeError',
      message: 'The `x` argument is required'
    },
    'cursorTo() must throw TypeError when x is missing'
  );

  assert.throws(
    () => ansiEscapes.cursorTo('0'),
    {
      name: 'TypeError',
      message: 'The `x` argument is required'
    },
    'cursorTo("0") must throw TypeError when x is not a number'
  );

  // 3. cursorMove behavior and validation
  assert.equal(typeof ansiEscapes.cursorMove, 'function', 'cursorMove must be a function');
  assert.equal(ansiEscapes.cursorMove(2, 3), '\u001B[2C\u001B[3B', 'cursorMove(2, 3) moves right and down');
  assert.equal(ansiEscapes.cursorMove(-1, -4), '\u001B[1D\u001B[4A', 'cursorMove(-1, -4) moves left and up');
  assert.equal(ansiEscapes.cursorMove(0, 0), '', 'cursorMove(0, 0) returns empty string');
  assert.equal(moveCursor(1, -1), '\u001B[1C\u001B[1A', 'moveCursor helper matches cursorMove output');

  assert.throws(
    () => ansiEscapes.cursorMove(),
    {
      name: 'TypeError',
      message: 'The `x` argument is required'
    },
    'cursorMove() must throw TypeError when x is missing'
  );

  // 4. Directional cursor helpers and constants
  assert.equal(ansiEscapes.cursorUp(), '\u001B[1A', 'cursorUp default is 1');
  assert.equal(ansiEscapes.cursorUp(3), '\u001B[3A', 'cursorUp(3) moves up 3');
  assert.equal(ansiEscapes.cursorDown(), '\u001B[1B', 'cursorDown default is 1');
  assert.equal(ansiEscapes.cursorDown(5), '\u001B[5B', 'cursorDown(5) moves down 5');
  assert.equal(ansiEscapes.cursorForward(2), '\u001B[2C', 'cursorForward(2) moves forward 2');
  assert.equal(ansiEscapes.cursorBackward(2), '\u001B[2D', 'cursorBackward(2) moves backward 2');
  assert.equal(ansiEscapes.cursorLeft, '\u001B[G', 'cursorLeft constant matches');
  assert.equal(ansiEscapes.cursorHide, '\u001B[?25l', 'cursorHide constant matches');
  assert.equal(ansiEscapes.cursorShow, '\u001B[?25h', 'cursorShow constant matches');

  // 5. Erase methods and constants
  assert.equal(typeof ansiEscapes.eraseLines, 'function', 'eraseLines must be a function');
  assert.equal(ansiEscapes.eraseLines(0), '', 'eraseLines(0) returns empty string');
  assert.equal(ansiEscapes.eraseLines(1), '\u001B[2K\u001B[G', 'eraseLines(1) clears line and moves left');
  assert.equal(
    ansiEscapes.eraseLines(2),
    '\u001B[2K\u001B[1A\u001B[2K\u001B[G',
    'eraseLines(2) clears 2 lines with cursor movement'
  );
  assert.equal(eraseLines(1), '\u001B[2K\u001B[G', 'eraseLines helper matches output');
  assert.equal(ansiEscapes.eraseLine, '\u001B[2K', 'eraseLine matches');
  assert.equal(ansiEscapes.eraseEndLine, '\u001B[K', 'eraseEndLine matches');
  assert.equal(ansiEscapes.eraseStartLine, '\u001B[1K', 'eraseStartLine matches');
  assert.equal(ansiEscapes.eraseScreen, '\u001B[2J', 'eraseScreen matches');

  // 6. Clear screen and terminal sequences
  assert.equal(ansiEscapes.clearScreen, '\u001Bc', 'clearScreen escape code matches');
  assert.equal(ansiEscapes.clearTerminal, '\u001B[2J\u001B[3J\u001B[H', 'clearTerminal escape code matches Linux terminal');
  assert.equal(ansiEscapes.beep, '\u0007', 'beep matches BEL');

  // 7. Hyperlink formatting
  assert.equal(typeof ansiEscapes.link, 'function', 'link must be a function');
  const expectedLink = '\u001B]8;;https://example.com\u0007Example Text\u001B]8;;\u0007';
  assert.equal(ansiEscapes.link('Example Text', 'https://example.com'), expectedLink, 'link generates OSC 8 escape code');
  assert.equal(createHyperlink('Example Text', 'https://example.com'), expectedLink, 'createHyperlink helper matches output');

  console.log('All ansi-escapes.default contract tests passed successfully.');
}

testAll().catch((err) => {
  console.error('Contract test failure:', err);
  process.exit(1);
});

오리진 시더

익명