CodeSampleX

示例

loupe 3.2.1

已验证示例 — npm loupe 3.2.1. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: inspect formats primitive values including strings, numbers, booleans, null…

sha256:4a4c68b2f6f9a388fb401a3f15388e84b442aec062a5ebe619be0d1b79afc385

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

案例

HOW
目标
verify pkg:npm/loupe@3.2.1
包
创建时间
2026-08-21T03:30:11Z

契约

  1. inspect formats primitive values including strings, numbers, booleans, null, undefined, BigInt, and Symbols
  2. inspect formats structured objects, arrays, Sets, and Maps
  3. inspect detects circular references and formats them with [Circular] placeholders
  4. inspect formats RegExp patterns and Error objects
  5. inspect supports configuration options such as truncate length and ANSI color formatting
  6. custom symbol enables user-defined custom inspection methods on objects
  7. registerConstructor registers custom inspector functions for specific class constructors
  8. registerStringTag registers custom inspector functions matching Symbol.toStringTag values

文件

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.mjs
  • 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/loupe@3.2.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/loupe@3.2.1

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:9423f73d91cfd26b5fe3e0886210c7bbb3a53650288b40f7b3dbc429bca67e5d","contract":["inspect formats primitive values including strings, numbers, booleans, null, undefined, BigInt, and Symbols","inspect formats structured objects, arrays, Sets, and Maps","inspect detects circular references and formats them with [Circular] placeholders","inspect formats RegExp patterns and Error objects","inspect supports configuration options such as truncate length and ANSI color formatting","custom symbol enables user-defined custom inspection methods on objects","registerConstructor registers custom inspector functions for specific class constructors","registerStringTag registers custom inspector functions matching Symbol.toStringTag values"],"goal":"verify pkg:npm/loupe@3.2.1","kind":"HOW","packages":["pkg:npm/loupe@3.2.1"],"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/loupe@3.2.1"],"schemaVersion":1,"subject":"pkg:npm/loupe@3.2.1","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "verify-loupe",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "verify-loupe",
      "version": "1.0.0",
      "dependencies": {
        "loupe": "3.2.1"
      }
    },
    "node_modules/loupe": {
      "version": "3.2.1",
      "resolved": "https://registry.npmjs.org/loupe/-/loupe-3.2.1.tgz",
      "integrity": "sha512-CdzqowRJCeLU72bHvWqwRBBlLcMEtIvGrlvef74kMnV2AolS9Y8xUv1I0U/MNAWMhBlKIoyuEgoJ0t/bbwHbLQ==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "verify-loupe",
  "version": "1.0.0",
  "type": "module",
  "dependencies": {
    "loupe": "3.2.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/loupe@3.2.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/loupe@3.2.1"
  ]
}
src/index.mjs
import { inspect, custom, registerConstructor, registerStringTag } from 'loupe';

export function inspectValue(value, options) {
  return inspect(value, options);
}

export { inspect, custom, registerConstructor, registerStringTag };
export default inspect;
test/contract.mjs
import assert from 'node:assert';
import inspect, { custom, registerConstructor, registerStringTag } from '../src/index.mjs';

// 1. Primitive formatting
assert.strictEqual(inspect(null), 'null', 'inspect must format null correctly');
assert.strictEqual(inspect(undefined), 'undefined', 'inspect must format undefined correctly');
assert.strictEqual(inspect(42), '42', 'inspect must format numbers correctly');
assert.strictEqual(inspect('hello'), "'hello'", 'inspect must format strings with quotes');
assert.strictEqual(inspect(true), 'true', 'inspect must format boolean true correctly');
assert.strictEqual(inspect(false), 'false', 'inspect must format boolean false correctly');
assert.strictEqual(inspect(100n), '100n', 'inspect must format BigInt with n suffix');
assert.strictEqual(inspect(Symbol('test')), 'Symbol(test)', 'inspect must format Symbol correctly');

// 2. Structured objects, arrays, Sets, and Maps
assert.strictEqual(inspect([1, 2, 3]), '[ 1, 2, 3 ]', 'inspect must format arrays correctly');
assert.strictEqual(inspect({ a: 1, b: 'two' }), "{ a: 1, b: 'two' }", 'inspect must format object properties correctly');
assert.strictEqual(inspect(new Set([1, 2])), 'Set{ 1, 2 }', 'inspect must format Set elements');
assert.strictEqual(inspect(new Map([['key', 'val']])), "Map{ 'key' => 'val' }", 'inspect must format Map entries');

// 3. Circular reference detection
const circular = { name: 'cycle' };
circular.self = circular;
assert.strictEqual(inspect(circular), "{ name: 'cycle', self: [Circular] }", 'inspect must detect circular references and print [Circular]');

// 4. Built-ins: RegExp, Date, Error
assert.strictEqual(inspect(/^abc$/i), '/^abc$/i', 'inspect must format RegExp literals');
const testError = new Error('loupe test error');
assert.ok(inspect(testError).includes('Error: loupe test error'), 'inspect must format Error objects with message');

// 5. Options: truncate and colors
const longText = 'a very long string that should be truncated by loupe';
const truncated = inspect(longText, { truncate: 15 });
assert.ok(truncated.length <= 15, 'truncate option must limit string length');
assert.ok(truncated.includes('…'), 'truncated string must contain ellipsis');

const colored = inspect(123, { colors: true });
assert.ok(colored.includes('\x1B['), 'colors option must apply ANSI escape codes');

// 6. Custom inspect symbol
class Box {
  constructor(val) {
    this.val = val;
  }
  [custom]() {
    return `<Box: ${this.val}>`;
  }
}
assert.strictEqual(inspect(new Box(42)), '<Box: 42>', 'inspect must use custom inspect symbol method');
assert.strictEqual(inspect(new Box(42), { customInspect: false }), 'Box{ val: 42 }', 'customInspect: false must bypass custom inspect method');

// 7. registerConstructor
class SpecialWidget {
  constructor(id) {
    this.id = id;
  }
}
const regCtorResult = registerConstructor(SpecialWidget, (val) => `Widget#${val.id}`);
assert.strictEqual(regCtorResult, true, 'registerConstructor must return true on successful registration');
assert.strictEqual(inspect(new SpecialWidget(99)), 'Widget#99', 'registered constructor inspector must format instances');

// 8. registerStringTag
class CustomTagged {
  get [Symbol.toStringTag]() {
    return 'CustomWidgetTag';
  }
}
const regTagResult = registerStringTag('CustomWidgetTag', () => '<CustomTaggedInstance>');
assert.strictEqual(regTagResult, true, 'registerStringTag must return true on successful registration');
assert.strictEqual(inspect(new CustomTagged()), '<CustomTaggedInstance>', 'registered string tag inspector must format instances');

console.log('Contract tests passed successfully.');

原始种子者

匿名