CodeSampleX

Beispiel

netmask 2.1.1: Parse IPv4 CIDR blocks and test IP containment and subnet iteration with Netmask

Verifiziertes Beispiel für npm netmask 2.1.1: Parse IPv4 CIDR blocks and test IP containment and subnet iteration with Netmask. Der Vertrag lief auf node 22…

sha256:415e82427893cbc87032611a9452a0c496b69db5875a564b79593c6f697730c5

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
2
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
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-23
node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2…
2026-09-07

Fall

HOW
Ziel
Parse IPv4 CIDR blocks and test IP containment and subnet iteration with Netmask
Pakete
Symbole
  • Netmask
  • Netmask.prototype.contains
  • Netmask.prototype.forEach
Umgebung
node 22.23.2
Erstellt
2026-08-23T15:28:03Z

Contract

  1. Netmask constructor parses CIDR notation and calculates base, mask, bitmask, hostmask, broadcast, size, first, and last properties
  2. Netmask constructor parses separate IP and netmask arguments correctly
  3. Netmask.prototype.contains validates whether an IPv4 address is within the subnet
  4. Netmask.prototype.contains validates whether a subnet block is entirely contained within another block
  5. Netmask.prototype.forEach iterates through all usable host IP addresses with index and integer representation
  6. Netmask.prototype.next navigates forward and backward to adjacent network blocks
  7. Netmask.prototype.toString returns the canonical CIDR block string
  8. Netmask constructor throws Error on invalid IP address or netmask format

Dateien

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • test/contract.cjs

Quellartefakt herunterladen (tar.gz)

Quelltext

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: Parse IPv4 CIDR blocks and test IP containment and subnet iteration with Netmask
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/netmask@2.1.1
Demonstrate these symbols/APIs:
  - Netmask
  - Netmask.prototype.contains
  - Netmask.prototype.forEach

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:7cf2e0bae4f0e150ab90ee9aee5297bdef35570ce01dd5dc1213fc189d1a9eaf","contract":["Netmask constructor parses CIDR notation and calculates base, mask, bitmask, hostmask, broadcast, size, first, and last properties","Netmask constructor parses separate IP and netmask arguments correctly","Netmask.prototype.contains validates whether an IPv4 address is within the subnet","Netmask.prototype.contains validates whether a subnet block is entirely contained within another block","Netmask.prototype.forEach iterates through all usable host IP addresses with index and integer representation","Netmask.prototype.next navigates forward and backward to adjacent network blocks","Netmask.prototype.toString returns the canonical CIDR block string","Netmask constructor throws Error on invalid IP address or netmask format"],"goal":"Parse IPv4 CIDR blocks and test IP containment and subnet iteration with Netmask","kind":"HOW","packages":["pkg:npm/netmask@2.1.1"],"schemaVersion":1,"symbols":["Netmask","Netmask.prototype.contains","Netmask.prototype.forEach"]},"contractCommand":["node","test/contract.cjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/netmask@2.1.1"],"schemaVersion":1,"subject":"pkg:npm/netmask@2.1.1","symbols":["Netmask","Netmask.prototype.contains","Netmask.prototype.forEach"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "netmask-sample",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "netmask-sample",
      "version": "1.0.0",
      "dependencies": {
        "netmask": "2.1.1"
      }
    },
    "node_modules/netmask": {
      "version": "2.1.1",
      "resolved": "https://registry.npmjs.org/netmask/-/netmask-2.1.1.tgz",
      "integrity": "sha512-eonl3sLUha+S1GzTPxychyhnUzKyeQkZ7jLjKrBagJgPla13F+uQ71HgpFefyHgqrjEbCPkDArxYsjY8/+gLKA==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.4.0"
      }
    }
  }
}
package.json
{
  "name": "netmask-sample",
  "version": "1.0.0",
  "private": true,
  "description": "Verification sample for netmask 2.1.1",
  "dependencies": {
    "netmask": "2.1.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "Parse IPv4 CIDR blocks and test IP containment and subnet iteration with Netmask",
  "kind": "HOW",
  "packages": [
    "pkg:npm/netmask@2.1.1"
  ],
  "symbols": [
    "Netmask",
    "Netmask.prototype.contains",
    "Netmask.prototype.forEach"
  ]
}
test/contract.cjs
const assert = require("node:assert/strict");
const { Netmask } = require("netmask");

// 1. Netmask constructor parses CIDR notation and calculates base, mask, bitmask, hostmask, broadcast, size, first, and last properties
const block = new Netmask("192.168.1.0/24");
assert.equal(block.base, "192.168.1.0");
assert.equal(block.mask, "255.255.255.0");
assert.equal(block.bitmask, 24);
assert.equal(block.hostmask, "0.0.0.255");
assert.equal(block.broadcast, "192.168.1.255");
assert.equal(block.size, 256);
assert.equal(block.first, "192.168.1.1");
assert.equal(block.last, "192.168.1.254");

// 2. Netmask constructor parses separate IP and netmask arguments correctly
const blockWithMask = new Netmask("10.0.0.0", "255.255.0.0");
assert.equal(blockWithMask.base, "10.0.0.0");
assert.equal(blockWithMask.bitmask, 16);
assert.equal(blockWithMask.mask, "255.255.0.0");
assert.equal(blockWithMask.broadcast, "10.0.255.255");
assert.equal(blockWithMask.size, 65536);

// 3. Netmask.prototype.contains validates whether an IPv4 address is within the subnet
assert.equal(block.contains("192.168.1.1"), true);
assert.equal(block.contains("192.168.1.100"), true);
assert.equal(block.contains("192.168.1.254"), true);
assert.equal(block.contains("192.168.2.1"), false);
assert.equal(block.contains("10.0.0.1"), false);

// 4. Netmask.prototype.contains validates whether a subnet block is entirely contained within another block
const subBlock = new Netmask("192.168.1.64/26");
const outsideBlock = new Netmask("192.168.2.0/24");
const parentBlock = new Netmask("192.168.0.0/16");
assert.equal(block.contains(subBlock), true);
assert.equal(block.contains(outsideBlock), false);
assert.equal(block.contains(parentBlock), false);

// 5. Netmask.prototype.forEach iterates through all usable host IP addresses with index and integer representation
const smallBlock = new Netmask("172.16.0.0/29");
const visited = [];
smallBlock.forEach((ip, long, index) => {
  visited.push({ ip, index, isNumber: typeof long === "number" });
});

assert.equal(visited.length, 6);
assert.equal(visited[0].ip, "172.16.0.1");
assert.equal(visited[0].index, 0);
assert.equal(visited[0].isNumber, true);
assert.equal(visited[5].ip, "172.16.0.6");
assert.equal(visited[5].index, 5);

// 6. Netmask.prototype.next navigates forward and backward to adjacent network blocks
const nextBlock = block.next();
assert.equal(nextBlock.base, "192.168.2.0");
assert.equal(nextBlock.bitmask, 24);

const prevBlock = nextBlock.next(-1);
assert.equal(prevBlock.base, "192.168.1.0");
assert.equal(prevBlock.bitmask, 24);

// 7. Netmask.prototype.toString returns the canonical CIDR block string
assert.equal(block.toString(), "192.168.1.0/24");
assert.equal(smallBlock.toString(), "172.16.0.0/29");

// 8. Netmask constructor throws Error on invalid IP address or netmask format
assert.throws(
  () => new Netmask("999.999.999.999/24"),
  (err) => err instanceof Error && /Invalid/i.test(err.message)
);
assert.throws(
  () => new Netmask("192.168.1.0/35"),
  (err) => err instanceof Error && /Invalid/i.test(err.message)
);

console.log("Contract verified successfully.");

Ursprungs-Seeder

anonym