CodeSampleX

Beispiel

@img/sharp-wasm32 0.35.5: stats

Verifiziertes Beispiel für npm @img/sharp-wasm32 0.35.5: stats. Der Vertrag lief auf node 22 · linux debian/x64 · docker und bestand.

sha256:adadd60630665c01ad082a9c20141b80b11d5795be55ce88826f428d3986a058

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

Fall

HOW
Ziel
verify @img/sharp-wasm32.stats in pkg:npm/%40img/sharp-wasm32@0.35.5
Pakete
Symbole
  • @img/sharp-wasm32.stats
Umgebung
node 22.23.2
Erstellt
2026-11-28T01:24:17Z

Contract

  1. require('@img/sharp-wasm32/sharp.node').stats is a function accepting ({ input, debuglog }, callback)
  2. stats() on a 2x2 opaque 3-channel raw uchar RGB buffer returns 3 channels with exact min/max/sum/squaresSum/mean/minX/minY/maxX/maxY, positive stdev, finite entropy and sharpness, RGB dominant object, and isOpaque === true
  3. stats() on a 2x2 4-channel raw RGBA buffer with alpha < 255 returns 4 channels with alpha min 128 and max 255 and isOpaque === false
  4. stats() on a uniform 4x4 3-channel created image returns zero stdev, zero entropy, zero sharpness, isOpaque === true, and quantized dominant { r: 200, g: 40, b: 24 }
  5. stats() on an invalid non-image buffer invokes the callback with a non-empty Error
  6. calling stats() directly without required numeric input fields (limitInputPixels, limitInputChannels) throws TypeError synchronously

Dateien

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.cjs
  • 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: verify @img/sharp-wasm32.stats in pkg:npm/%40img/sharp-wasm32@0.35.5
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40img/sharp-wasm32@0.35.5
Demonstrate these symbols/APIs:
  - @img/sharp-wasm32.stats
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.
csx.json
{"case":{"caseId":"case:sha256:688790e577c2cdc36d2993e9962a316c17533723e0f5a7a1d2dee6f19a5dde96","constraints":{"executionContext":"node"},"contract":["require('@img/sharp-wasm32/sharp.node').stats is a function accepting ({ input, debuglog }, callback)","stats() on a 2x2 opaque 3-channel raw uchar RGB buffer returns 3 channels with exact min/max/sum/squaresSum/mean/minX/minY/maxX/maxY, positive stdev, finite entropy and sharpness, RGB dominant object, and isOpaque === true","stats() on a 2x2 4-channel raw RGBA buffer with alpha \u003c 255 returns 4 channels with alpha min 128 and max 255 and isOpaque === false","stats() on a uniform 4x4 3-channel created image returns zero stdev, zero entropy, zero sharpness, isOpaque === true, and quantized dominant { r: 200, g: 40, b: 24 }","stats() on an invalid non-image buffer invokes the callback with a non-empty Error","calling stats() directly without required numeric input fields (limitInputPixels, limitInputChannels) throws TypeError synchronously"],"goal":"verify @img/sharp-wasm32.stats in pkg:npm/%40img/sharp-wasm32@0.35.5","kind":"HOW","packages":["pkg:npm/%40img/sharp-wasm32@0.35.5"],"schemaVersion":1,"symbols":["@img/sharp-wasm32.stats"]},"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/%40img/sharp-wasm32@0.35.5"],"schemaVersion":1,"subject":"pkg:npm/%40img/sharp-wasm32@0.35.5","symbols":["@img/sharp-wasm32.stats"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sharp-wasm32-stats-sample",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sharp-wasm32-stats-sample",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "@img/sharp-wasm32": "0.35.5"
      }
    },
    "node_modules/@emnapi/runtime": {
      "version": "1.11.3",
      "resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.11.3.tgz",
      "integrity": "sha512-Xz4Tpyki7XyrpbUK1jR1AhdAdaXyhhY4lZ3neLodmhpuWfy2PAQN5B46sAiU4liOXGLkHypn/qU+jvfWSCYYLA==",
      "license": "MIT",
      "dependencies": {
        "tslib": "^2.4.0"
      }
    },
    "node_modules/@img/sharp-wasm32": {
      "version": "0.35.5",
      "resolved": "https://registry.npmjs.org/@img/sharp-wasm32/-/sharp-wasm32-0.35.5.tgz",
      "integrity": "sha512-Ptsga1su4tQx+LLF1ECS9U6nz5kmrXKo6XVbtR48Ke3ZRxxgaWBu7IDtEe1quo8hiupwm6WFqxVlXaSf7IINGQ==",
      "license": "Apache-2.0 AND LGPL-3.0-or-later AND MIT",
      "dependencies": {
        "@emnapi/runtime": "^1.11.3"
      },
      "engines": {
        "node": ">=20.9.0"
      },
      "funding": {
        "url": "https://opencollective.com/libvips"
      }
    },
    "node_modules/tslib": {
      "version": "2.9.1",
      "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.9.1.tgz",
      "integrity": "sha512-a4Ux9VKuIMHsOS7ENbEq6hK2ZGYIT27Rtl0E4eD9KqwxhKiQeMZE/9xb3IdYwWaSOyIBQLExhQgXDTYoiCxnWA==",
      "license": "0BSD"
    }
  }
}
package.json
{
  "name": "sharp-wasm32-stats-sample",
  "version": "1.0.0",
  "private": true,
  "type": "commonjs",
  "license": "MIT-0",
  "scripts": {
    "test": "node test/contract.cjs"
  },
  "dependencies": {
    "@img/sharp-wasm32": "0.35.5"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify @img/sharp-wasm32.stats in pkg:npm/%40img/sharp-wasm32@0.35.5",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40img/sharp-wasm32@0.35.5"
  ],
  "symbols": [
    "@img/sharp-wasm32.stats"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.cjs
'use strict';

const sharpWasm = require('@img/sharp-wasm32/sharp.node');

const DEFAULT_INPUT = {
  failOn: 'warning',
  limitInputPixels: 268402689,
  limitInputChannels: 16,
  unlimited: false,
  autoOrient: false
};

function computeStats(input, debuglog = () => {}) {
  const fullInput = { ...DEFAULT_INPUT, ...input };
  return new Promise((resolve, reject) => {
    sharpWasm.stats({ input: fullInput, debuglog }, (err, result) => {
      if (err) {
        reject(err);
        return;
      }
      resolve(result);
    });
  });
}

module.exports = {
  sharpWasm,
  computeStats
};
test/contract.cjs
'use strict';

const assert = require('node:assert/strict');
const { sharpWasm, computeStats } = require('../src/index.cjs');

async function main() {
  assert.equal(typeof sharpWasm.stats, 'function', 'sharp.node exports stats()');

  // 1. 2x2 opaque 3-channel raw RGB pixel buffer
  const rgbBuffer = Buffer.from([
    10, 100, 200,
    30, 120, 220,
    50, 140, 240,
    70, 160, 240
  ]);

  const rgbStats = await computeStats({
    buffer: rgbBuffer,
    failOn: 'warning',
    rawDepth: 'uchar',
    rawChannels: 3,
    rawWidth: 2,
    rawHeight: 2,
    rawPremultiplied: false,
    rawPageHeight: 0
  });

  assert.equal(rgbStats.channels.length, 3);
  assert.equal(rgbStats.isOpaque, true);

  assert.equal(rgbStats.channels[0].min, 10);
  assert.equal(rgbStats.channels[0].max, 70);
  assert.equal(rgbStats.channels[0].sum, 160);
  assert.equal(rgbStats.channels[0].squaresSum, 8400);
  assert.equal(rgbStats.channels[0].mean, 40);
  assert.equal(rgbStats.channels[0].minX, 0);
  assert.equal(rgbStats.channels[0].minY, 0);
  assert.equal(rgbStats.channels[0].maxX, 1);
  assert.equal(rgbStats.channels[0].maxY, 1);
  assert.ok(rgbStats.channels[0].stdev > 0);

  assert.equal(rgbStats.channels[1].min, 100);
  assert.equal(rgbStats.channels[1].max, 160);
  assert.equal(rgbStats.channels[1].sum, 520);
  assert.equal(rgbStats.channels[1].mean, 130);

  assert.equal(rgbStats.channels[2].min, 200);
  assert.equal(rgbStats.channels[2].max, 240);
  assert.equal(rgbStats.channels[2].sum, 900);
  assert.equal(rgbStats.channels[2].mean, 225);

  assert.equal(typeof rgbStats.entropy, 'number');
  assert.ok(Number.isFinite(rgbStats.entropy) && rgbStats.entropy >= 0);
  assert.equal(typeof rgbStats.sharpness, 'number');
  assert.ok(Number.isFinite(rgbStats.sharpness) && rgbStats.sharpness >= 0);
  assert.equal(typeof rgbStats.dominant.r, 'number');
  assert.equal(typeof rgbStats.dominant.g, 'number');
  assert.equal(typeof rgbStats.dominant.b, 'number');

  // 2. 2x2 4-channel RGBA raw buffer with a semi-transparent pixel
  const rgbaBuffer = Buffer.from([
    255, 0, 0, 255,
    0, 255, 0, 128,
    0, 0, 255, 255,
    255, 255, 255, 255
  ]);

  const rgbaStats = await computeStats({
    buffer: rgbaBuffer,
    failOn: 'warning',
    rawDepth: 'uchar',
    rawChannels: 4,
    rawWidth: 2,
    rawHeight: 2,
    rawPremultiplied: false,
    rawPageHeight: 0
  });

  assert.equal(rgbaStats.channels.length, 4);
  assert.equal(rgbaStats.channels[3].min, 128);
  assert.equal(rgbaStats.channels[3].max, 255);
  assert.equal(rgbaStats.isOpaque, false);

  // 3. Uniform solid created image
  const solidStats = await computeStats({
    failOn: 'warning',
    createChannels: 3,
    createWidth: 4,
    createHeight: 4,
    createPageHeight: 0,
    createBackground: [200, 40, 20]
  });

  assert.equal(solidStats.channels.length, 3);
  assert.equal(solidStats.channels[0].min, 200);
  assert.equal(solidStats.channels[0].max, 200);
  assert.equal(solidStats.channels[0].mean, 200);
  assert.equal(solidStats.channels[0].stdev, 0);
  assert.equal(solidStats.channels[1].mean, 40);
  assert.equal(solidStats.channels[2].mean, 20);
  assert.equal(solidStats.isOpaque, true);
  assert.equal(solidStats.entropy, 0);
  assert.equal(solidStats.sharpness, 0);
  assert.deepEqual(solidStats.dominant, { r: 200, g: 40, b: 24 });

  // 4. Invalid non-image buffer reports an Error via callback
  await assert.rejects(
    () => computeStats({
      buffer: Buffer.from('not-an-image'),
      failOn: 'warning'
    }),
    (err) => err instanceof Error && err.message.length > 0
  );

  // 5. Omitting required numeric input fields throws TypeError synchronously
  assert.throws(
    () => {
      sharpWasm.stats(
        {
          input: {
            buffer: rgbBuffer,
            failOn: 'warning',
            rawDepth: 'uchar',
            rawChannels: 3,
            rawWidth: 2,
            rawHeight: 2,
            rawPremultiplied: false,
            rawPageHeight: 0
          },
          debuglog: () => {}
        },
        () => {}
      );
    },
    TypeError
  );

  console.log('PASS: @img/sharp-wasm32.stats contract verified');
}

main().catch((err) => {
  console.error(err);
  process.exit(1);
});

Ursprungs-Seeder

anonym