CodeSampleX

샘플

strip-final-newline 2.0.0

검증된 샘플 — npm strip-final-newline 2.0.0. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: stripFinalNewline removes a single trailing LF (\n) from…

sha256:171441a697fd850f25cb5d9170b588b6a5c29249dcbd79c2d0ae5d328482a72a

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

케이스

HOW
목표
verify pkg:npm/strip-final-newline@2.0.0
패키지
생성일
2026-08-28T08:57:41Z

컨트랙트

  1. stripFinalNewline removes a single trailing LF (\n) from a string
  2. stripFinalNewline removes a single trailing CRLF (\r\n) from a string
  3. stripFinalNewline preserves preceding newlines and only strips the final newline
  4. stripFinalNewline leaves strings without trailing newlines unchanged
  5. stripFinalNewline handles empty strings by returning an empty string
  6. stripFinalNewline removes trailing newline bytes from Buffer and Uint8Array instances
  7. stripFinalNewline preserves Buffer content when no trailing newline bytes exist

파일

  • 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/strip-final-newline@2.0.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/strip-final-newline@2.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:d63699b45a124ce8117a24e5f3de8b4e5f6910d1eefb4d1dcae045baec607d38","contract":["stripFinalNewline removes a single trailing LF (\\n) from a string","stripFinalNewline removes a single trailing CRLF (\\r\\n) from a string","stripFinalNewline preserves preceding newlines and only strips the final newline","stripFinalNewline leaves strings without trailing newlines unchanged","stripFinalNewline handles empty strings by returning an empty string","stripFinalNewline removes trailing newline bytes from Buffer and Uint8Array instances","stripFinalNewline preserves Buffer content when no trailing newline bytes exist"],"goal":"verify pkg:npm/strip-final-newline@2.0.0","kind":"HOW","packages":["pkg:npm/strip-final-newline@2.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/strip-final-newline@2.0.0"],"schemaVersion":1,"subject":"pkg:npm/strip-final-newline@2.0.0","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-strip-final-newline",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-strip-final-newline",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "strip-final-newline": "2.0.0"
      }
    },
    "node_modules/strip-final-newline": {
      "version": "2.0.0",
      "resolved": "https://registry.npmjs.org/strip-final-newline/-/strip-final-newline-2.0.0.tgz",
      "integrity": "sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==",
      "license": "MIT",
      "engines": {
        "node": ">=6"
      }
    }
  }
}
package.json
{
  "name": "sample-strip-final-newline",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room code sample for strip-final-newline@2.0.0",
  "main": "src/index.js",
  "license": "MIT-0",
  "dependencies": {
    "strip-final-newline": "2.0.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/strip-final-newline@2.0.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/strip-final-newline@2.0.0"
  ]
}
src/index.js
'use strict';

const stripFinalNewline = require('strip-final-newline');

/**
 * Strips the final newline character from a string or Buffer/Uint8Array.
 *
 * @param {string|Buffer|Uint8Array} input - The input string or buffer.
 * @returns {string|Buffer|Uint8Array} - The input without the trailing newline.
 */
function stripNewline(input) {
  return stripFinalNewline(input);
}

module.exports = {
  stripFinalNewline,
  stripNewline
};
test/contract.mjs
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const { stripFinalNewline, stripNewline } = require('../src/index.js');

async function testAll() {
  // 1. Export verification
  assert.equal(typeof stripFinalNewline, 'function', 'stripFinalNewline must be a function');
  assert.equal(typeof stripNewline, 'function', 'stripNewline helper must be a function');

  // 2. Trailing LF (\n) removal from string
  assert.equal(
    stripFinalNewline('hello world\n'),
    'hello world',
    'should strip trailing LF'
  );
  assert.equal(
    stripNewline('foo\n'),
    'foo',
    'helper should strip trailing LF'
  );

  // 3. Trailing CRLF (\r\n) removal from string
  assert.equal(
    stripFinalNewline('hello world\r\n'),
    'hello world',
    'should strip trailing CRLF'
  );
  assert.equal(
    stripFinalNewline('windows style line\r\n'),
    'windows style line',
    'should strip trailing CRLF'
  );

  // 4. Multiple trailing newlines: only the last newline is removed
  assert.equal(
    stripFinalNewline('hello\n\n'),
    'hello\n',
    'should only strip the single final LF when multiple trailing newlines exist'
  );
  assert.equal(
    stripFinalNewline('hello\r\n\r\n'),
    'hello\r\n',
    'should only strip the single final CRLF when multiple trailing newlines exist'
  );
  assert.equal(
    stripFinalNewline('first line\nsecond line\n'),
    'first line\nsecond line',
    'should preserve intermediate newlines and strip final newline'
  );

  // 5. Strings without trailing newline remain unchanged
  assert.equal(
    stripFinalNewline('hello world'),
    'hello world',
    'should not modify strings without trailing newlines'
  );
  assert.equal(
    stripFinalNewline(''),
    '',
    'should return empty string for empty string input'
  );
  assert.equal(
    stripFinalNewline('\n'),
    '',
    'single newline should become empty string'
  );
  assert.equal(
    stripFinalNewline('\r\n'),
    '',
    'single CRLF should become empty string'
  );

  // 6. Buffer / Uint8Array support: removes trailing LF and CRLF
  const bufLF = Buffer.from('hello buffer\n');
  const strippedBufLF = stripFinalNewline(bufLF);
  assert.ok(Buffer.isBuffer(strippedBufLF), 'result should be a Buffer');
  assert.equal(strippedBufLF.toString('utf8'), 'hello buffer', 'Buffer with trailing LF should be stripped');

  const bufCRLF = Buffer.from('hello buffer\r\n');
  const strippedBufCRLF = stripFinalNewline(bufCRLF);
  assert.ok(Buffer.isBuffer(strippedBufCRLF), 'result should be a Buffer');
  assert.equal(strippedBufCRLF.toString('utf8'), 'hello buffer', 'Buffer with trailing CRLF should be stripped');

  const uint8LF = new Uint8Array([104, 101, 121, 10]); // "hey\n"
  const strippedUint8 = stripFinalNewline(uint8LF);
  assert.deepEqual(Array.from(strippedUint8), [104, 101, 121], 'Uint8Array with trailing LF should be stripped');

  // 7. Buffer without trailing newline remains intact
  const bufNoNL = Buffer.from('no newline');
  const strippedNoNL = stripFinalNewline(bufNoNL);
  assert.equal(strippedNoNL.toString('utf8'), 'no newline', 'Buffer without trailing newline should be unchanged');

  console.log('All strip-final-newline contract tests passed successfully.');
}

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

오리진 시더

익명