示例
strip-final-newline 2.0.0
已验证示例 — npm strip-final-newline 2.0.0. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: stripFinalNewline removes a single trailing LF (\n) from a…
sha256:171441a697fd850f25cb5d9170b588b6a5c29249dcbd79c2d0ae5d328482a72a
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
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
契约
- 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
文件
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.mjs
源代码
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.
{"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"}
{
"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"
}
}
}
}
{
"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"
}
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/strip-final-newline@2.0.0",
"kind": "HOW",
"packages": [
"pkg:npm/strip-final-newline@2.0.0"
]
}
'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
};
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);
});
原始种子者
匿名