Beispiel
netmask 2.1.2: Netmask
Verifiziertes Beispiel für npm netmask 2.1.2: Netmask. Der Vertrag lief auf node 22 · linux debian/x64 · docker und bestand: new Netmask('192.0.2.42/24')…
sha256:86980da99e7564399ff947226eb1b0c4b75ff7f8cdefe8822421952236ace6ea
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
- 1
- 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 debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2… |
2026-11-22 |
Fall
HOW- Ziel
- verify netmask.Netmask in pkg:npm/netmask@2.1.2
- Pakete
- Symbole
-
- netmask.Netmask
- Umgebung
- node 22.23.2
- Erstellt
- 2026-11-22T19:56:17Z
Contract
- new Netmask('192.0.2.42/24') normalizes base to '192.0.2.0', mask '255.255.255.0', hostmask '0.0.0.255', bitmask 24, size 256, first '192.0.2.1', last '192.0.2.254', broadcast '192.0.2.255', and toString() '192.0.2.0/24'
- new Netmask(net, mask) accepts separate dotted-quad or numeric bitmask arguments and produces identical CIDR blocks
- IPv4 /31 and /32 (including omitted mask defaulting to /32) set broadcast to undefined and include base in first/last
- contains() returns true for in-range single IPs, enclosed CIDR strings, and enclosed Netmask instances, and false for out-of-range or wider blocks
- next(count) returns adjacent Netmask instances for default (1), positive, and negative offsets
- forEach() iterates usable host addresses from first through last with sequential indices
- IPv6 CIDR inputs (e.g. '2001:db8::2/126') parse base, bitmask, size, first, last, set broadcast to undefined and maskLong/netLong to 0, and support contains() and next()
- Missing net parameter, out-of-range IPv4 (>32) or IPv6 (>128) bitmasks, and invalid addresses throw Error
Dateien
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.js
Quelltext
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 netmask.Netmask in pkg:npm/netmask@2.1.2
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/netmask@2.1.2
Demonstrate these symbols/APIs:
- netmask.Netmask
Constraints:
- executionContext: node
Required runtime conditions:
- ecosystem: npm
- language: javascript
- moduleSystem: cjs
- packageManager: npm@10.9.8
- runtime: node@22.23.2
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:db9b080b8d846ebc97a485cc8aa6c83fcd711ca8a6fe496e5b5eec6d98ef6755","constraints":{"executionContext":"node"},"contract":["new Netmask('192.0.2.42/24') normalizes base to '192.0.2.0', mask '255.255.255.0', hostmask '0.0.0.255', bitmask 24, size 256, first '192.0.2.1', last '192.0.2.254', broadcast '192.0.2.255', and toString() '192.0.2.0/24'","new Netmask(net, mask) accepts separate dotted-quad or numeric bitmask arguments and produces identical CIDR blocks","IPv4 /31 and /32 (including omitted mask defaulting to /32) set broadcast to undefined and include base in first/last","contains() returns true for in-range single IPs, enclosed CIDR strings, and enclosed Netmask instances, and false for out-of-range or wider blocks","next(count) returns adjacent Netmask instances for default (1), positive, and negative offsets","forEach() iterates usable host addresses from first through last with sequential indices","IPv6 CIDR inputs (e.g. '2001:db8::2/126') parse base, bitmask, size, first, last, set broadcast to undefined and maskLong/netLong to 0, and support contains() and next()","Missing net parameter, out-of-range IPv4 (\u003e32) or IPv6 (\u003e128) bitmasks, and invalid addresses throw Error"],"goal":"verify netmask.Netmask in pkg:npm/netmask@2.1.2","kind":"HOW","packages":["pkg:npm/netmask@2.1.2"],"schemaVersion":1,"symbols":["netmask.Netmask"]},"contractCommand":["node","test/contract.js"],"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.2"],"schemaVersion":1,"subject":"pkg:npm/netmask@2.1.2","symbols":["netmask.Netmask"],"verifierAdapter":"node-typescript@1"}
{
"name": "netmask-netmask-sample",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "netmask-netmask-sample",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"netmask": "2.1.2"
}
},
"node_modules/netmask": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/netmask/-/netmask-2.1.2.tgz",
"integrity": "sha512-In/qjEgPWP3EEKRBrATKSHRCcempKN/gUl97rrB1mTreVQfvPGthTJVwNXwbQHtIzzLf1bYyh8M50xpeYk0r6Q==",
"license": "MIT",
"engines": {
"node": ">= 0.4.0"
}
}
}
}
{
"name": "netmask-netmask-sample",
"version": "1.0.0",
"private": true,
"license": "MIT-0",
"scripts": {
"test": "node test/contract.js"
},
"dependencies": {
"netmask": "2.1.2"
}
}
{
"schemaVersion": 1,
"goal": "verify netmask.Netmask in pkg:npm/netmask@2.1.2",
"kind": "HOW",
"packages": [
"pkg:npm/netmask@2.1.2"
],
"symbols": [
"netmask.Netmask"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
'use strict';
const { Netmask } = require('netmask');
function inspectBlock(net, mask) {
const block = mask === undefined ? new Netmask(net) : new Netmask(net, mask);
return {
cidr: block.toString(),
base: block.base,
mask: block.mask,
hostmask: block.hostmask,
bitmask: block.bitmask,
size: block.size,
first: block.first,
last: block.last,
broadcast: block.broadcast,
block,
};
}
function listHosts(block) {
const hosts = [];
block.forEach((ip, _long, index) => {
hosts.push({ index, ip });
});
return hosts;
}
module.exports = {
inspectBlock,
listHosts,
};
'use strict';
const assert = require('node:assert/strict');
const { Netmask } = require('netmask');
const { inspectBlock, listHosts } = require('../src/index');
// 1. IPv4 CIDR parsing normalizes host bits and computes network metadata
const v4 = inspectBlock('192.0.2.42/24');
assert.equal(v4.cidr, '192.0.2.0/24');
assert.equal(v4.base, '192.0.2.0');
assert.equal(v4.mask, '255.255.255.0');
assert.equal(v4.hostmask, '0.0.0.255');
assert.equal(v4.bitmask, 24);
assert.equal(v4.size, 256);
assert.equal(v4.first, '192.0.2.1');
assert.equal(v4.last, '192.0.2.254');
assert.equal(v4.broadcast, '192.0.2.255');
// 2. Separate dotted-quad and numeric mask arguments produce identical blocks
const fromDotted = inspectBlock('192.0.2.19', '255.255.255.240');
const fromNumber = inspectBlock('192.0.2.19', 28);
assert.equal(fromDotted.cidr, '192.0.2.16/28');
assert.equal(fromNumber.cidr, '192.0.2.16/28');
assert.equal(fromDotted.size, 16);
assert.equal(fromDotted.first, '192.0.2.17');
assert.equal(fromDotted.last, '192.0.2.30');
assert.equal(fromDotted.broadcast, '192.0.2.31');
// 3. /31 and /32 (default mask when omitted) set broadcast to undefined
const p2p = new Netmask('192.0.2.4/31');
assert.equal(p2p.size, 2);
assert.equal(p2p.first, '192.0.2.4');
assert.equal(p2p.last, '192.0.2.5');
assert.equal(p2p.broadcast, undefined);
const singleHost = new Netmask('192.0.2.9');
assert.equal(singleHost.bitmask, 32);
assert.equal(singleHost.size, 1);
assert.equal(singleHost.first, '192.0.2.9');
assert.equal(singleHost.last, '192.0.2.9');
assert.equal(singleHost.broadcast, undefined);
// 4. contains() accepts single IP strings, CIDR strings, and Netmask instances
assert.equal(v4.block.contains('192.0.2.0'), true);
assert.equal(v4.block.contains('192.0.2.255'), true);
assert.equal(v4.block.contains('192.0.3.1'), false);
assert.equal(v4.block.contains('192.0.2.16/28'), true);
assert.equal(v4.block.contains('192.0.0.0/22'), false);
assert.equal(v4.block.contains(fromDotted.block), true);
assert.equal(fromDotted.block.contains(v4.block), false);
// 5. next() returns adjacent Netmask blocks for default, positive, and negative offsets
const nextOne = fromDotted.block.next();
assert.ok(nextOne instanceof Netmask);
assert.equal(nextOne.toString(), '192.0.2.32/28');
assert.equal(fromDotted.block.next(2).toString(), '192.0.2.48/28');
assert.equal(nextOne.next(-1).toString(), '192.0.2.16/28');
// 6. forEach() iterates host addresses from first to last with sequential indices
const small = new Netmask('192.0.2.0/30');
assert.deepEqual(listHosts(small), [
{ index: 0, ip: '192.0.2.1' },
{ index: 1, ip: '192.0.2.2' },
]);
// 7. IPv6 CIDR parsing, containment, and next() with maskLong/netLong zeroed and broadcast undefined
const v6 = inspectBlock('2001:db8::2/126');
assert.equal(v6.cidr, '2001:db8::/126');
assert.equal(v6.base, '2001:db8::');
assert.equal(v6.bitmask, 126);
assert.equal(v6.size, 4);
assert.equal(v6.first, '2001:db8::');
assert.equal(v6.last, '2001:db8::3');
assert.equal(v6.broadcast, undefined);
assert.equal(v6.block.maskLong, 0);
assert.equal(v6.block.netLong, 0);
assert.equal(v6.block.contains('2001:db8::3'), true);
assert.equal(v6.block.contains('2001:db8::4'), false);
assert.equal(v6.block.contains('2001:db8::/127'), true);
assert.equal(v6.block.next().toString(), '2001:db8::4/126');
// 8. Invalid inputs throw Error
assert.throws(() => new Netmask(), /Missing `net' parameter/);
assert.throws(() => new Netmask('192.0.2.0/33'), /Invalid mask/);
assert.throws(() => new Netmask('2001:db8::/129'), /Invalid mask for IPv6/);
assert.throws(() => new Netmask('999.0.0.1/24'), /Invalid net address/);
console.log('netmask.Netmask contract passed');
Ursprungs-Seeder
anonym