CodeSampleX

Exemplo

strip-final-newline 2.0.0

Amostra verificada para npm strip-final-newline 2.0.0. O contrato rodou em node 22 · linux alpine/x64 · docker e passou: stripFinalNewline removes a single…

sha256:171441a697fd850f25cb5d9170b588b6a5c29249dcbd79c2d0ae5d328482a72a

Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu. Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas. MIT-0

Evidência de execução

O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.

Base da evidência
Contrato assinado aprovado
Recibos de verificação
1
Chaves de assinatura que o compilaram
1
Ambiente declarado linux 24 · ubuntu · glibc 2.39 x64 npm

Ambientes das execuções de verificação

Ambiente Contrato Etapas Execução
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

Caso

HOW
Objetivo
verify pkg:npm/strip-final-newline@2.0.0
Pacotes
Criado
2026-08-28T08:57:41Z

Contrato

  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

Arquivos

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

Baixar o artefato de código-fonte (tar.gz)

Código-fonte

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);
});

Seeder de origem

anônimo