CodeSampleX

Exemple

strip-final-newline 2.0.0

Échantillon vérifié pour npm strip-final-newline 2.0.0. Le contrat s'est exécuté sur node 22 · linux alpine/x64 · docker et a réussi.

sha256:171441a697fd850f25cb5d9170b588b6a5c29249dcbd79c2d0ae5d328482a72a

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-28

Cas

HOW
Objectif
verify pkg:npm/strip-final-newline@2.0.0
Paquets
Créé
2026-08-28T08:57:41Z

Contrat

  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

Fichiers

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • 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/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 d'origine

anonyme