CodeSampleX

示例

range-parser 1.3.0

已验证示例 — npm range-parser 1.3.0. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: parseRange(size, str) parses single byte range and sets type property…

sha256:9c2b35d0b230f67252f5da82f536bf8f472e2b46a0c7f0b5d41f69701e26b7e2

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 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@1
2026-08-20

案例

HOW
目标
verify pkg:npm/range-parser@1.3.0
包
创建时间
2026-08-20T13:59:10Z

契约

  1. parseRange(size, str) parses single byte range and sets type property to 'bytes'
  2. parseRange(size, str) parses multiple non-overlapping ranges
  3. parseRange(size, str) parses suffix range relative to total size
  4. parseRange(size, str) parses open-ended range to end of size
  5. parseRange(size, str) caps range ending at total size minus one
  6. parseRange(size, str, { combine: true }) combines overlapping and adjacent ranges
  7. parseRange(size, str) returns -1 for unsatisfiable ranges
  8. parseRange(size, str) returns -2 for invalid or malformed range strings

文件

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • 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/range-parser@1.3.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/range-parser@1.3.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:327c2b138eac6d2433694491a6241a56ec89684c2cd2088860f6bedd7a1a8fb8","contract":["parseRange(size, str) parses single byte range and sets type property to 'bytes'","parseRange(size, str) parses multiple non-overlapping ranges","parseRange(size, str) parses suffix range relative to total size","parseRange(size, str) parses open-ended range to end of size","parseRange(size, str) caps range ending at total size minus one","parseRange(size, str, { combine: true }) combines overlapping and adjacent ranges","parseRange(size, str) returns -1 for unsatisfiable ranges","parseRange(size, str) returns -2 for invalid or malformed range strings"],"goal":"verify pkg:npm/range-parser@1.3.0","kind":"HOW","packages":["pkg:npm/range-parser@1.3.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/range-parser@1.3.0"],"schemaVersion":1,"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-range-parser",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-range-parser",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "range-parser": "1.3.0"
      }
    },
    "node_modules/range-parser": {
      "version": "1.3.0",
      "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.3.0.tgz",
      "integrity": "sha512-hek2mFQpPuI4E1BBKrSto+BU3e3x4xuarsbiwr3+lf7p44juvFMV0XFWQAP3xUyqXA4RrXLIoaSUGbSt056ZMw==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.6"
      }
    }
  }
}
package.json
{
  "name": "sample-range-parser",
  "version": "1.0.0",
  "type": "module",
  "license": "MIT-0",
  "dependencies": {
    "range-parser": "1.3.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/range-parser@1.3.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/range-parser@1.3.0"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const parseRange = require('range-parser');

// 1. Function export verification
assert.equal(typeof parseRange, 'function', 'parseRange must be a function');

// 2. parseRange(size, str) parses single byte range and sets type property to 'bytes'
const single = parseRange(1000, 'bytes=0-499');
assert.equal(single.type, 'bytes');
assert.equal(single.length, 1);
assert.deepEqual(single[0], { start: 0, end: 499 });

// 3. parseRange(size, str) parses multiple non-overlapping ranges
const multiple = parseRange(1000, 'bytes=0-100, 200-300');
assert.equal(multiple.type, 'bytes');
assert.equal(multiple.length, 2);
assert.deepEqual(multiple[0], { start: 0, end: 100 });
assert.deepEqual(multiple[1], { start: 200, end: 300 });

// 4. parseRange(size, str) parses suffix range relative to total size
const suffix = parseRange(1000, 'bytes=-100');
assert.equal(suffix.type, 'bytes');
assert.equal(suffix.length, 1);
assert.deepEqual(suffix[0], { start: 900, end: 999 });

// 5. parseRange(size, str) parses open-ended range to end of size
const openEnded = parseRange(1000, 'bytes=500-');
assert.equal(openEnded.type, 'bytes');
assert.equal(openEnded.length, 1);
assert.deepEqual(openEnded[0], { start: 500, end: 999 });

// 6. parseRange(size, str) caps range ending at total size minus one
const capped = parseRange(1000, 'bytes=0-2000');
assert.equal(capped.type, 'bytes');
assert.equal(capped.length, 1);
assert.deepEqual(capped[0], { start: 0, end: 999 });

// 7. parseRange(size, str, { combine: true }) combines overlapping and adjacent ranges
const combined = parseRange(1000, 'bytes=0-100, 50-150', { combine: true });
assert.equal(combined.type, 'bytes');
assert.equal(combined.length, 1);
assert.deepEqual(combined[0], { start: 0, end: 150 });

// 8. parseRange(size, str) returns -1 for unsatisfiable ranges
assert.equal(parseRange(1000, 'bytes=1000-2000'), -1);
assert.equal(parseRange(1000, 'bytes=500-400'), -1);

// 9. parseRange(size, str) returns -2 for invalid or malformed range strings
assert.equal(parseRange(1000, 'invalid'), -2);
assert.equal(parseRange(1000, 'bytes='), -2);
assert.equal(parseRange(1000, 'bytes=-'), -2);
assert.equal(parseRange(1000, 'bytes=abc-def'), -2);

原始种子者

匿名