CodeSampleX

サンプル

@sinonjs/commons 3.0.1

検証済みサンプル — npm @sinonjs/commons 3.0.1. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました: typeOf returns lowercase type name for JavaScript values…

sha256:05dc1edbde1ad5d98c31d3578a977a17d84210af24a8ef793ea5db3f98066a41

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 MIT-0

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
1
ビルドした署名鍵
1
宣言された環境 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

検証実行環境

環境 コントラクト ステージ 実行日
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-27

ケース

HOW
ゴール
verify pkg:npm/%40sinonjs/commons@3.0.1
パッケージ
環境
node 22.23.2
作成日
2026-08-27T14:32:28Z

コントラクト

  1. typeOf returns lowercase type name for JavaScript values including primitives, arrays, dates, maps, sets, and objects
  2. className returns constructor name for objects and null when constructor is absent or null prototype
  3. functionName returns the identifier name of named and assigned function declarations
  4. every returns true when all elements in an array, Set, or Map satisfy predicate and false otherwise
  5. valueToString converts primitives, objects, and nullish values to string representations
  6. prototypes provides safe uncurried methods on array, string, and object prototypes
  7. calledInOrder returns true when spy instances are executed in sequential order
  8. orderByFirstCall sorts an array of spy objects chronologically by their first invocation callId

ファイル

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • test/contract.js

ソースアーティファクトをダウンロード (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/%40sinonjs/commons@3.0.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40sinonjs/commons@3.0.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:fa4d7b0d7c2366b8df5a71d91c44c08c893392557117390f01a72aed8338f34f","contract":["typeOf returns lowercase type name for JavaScript values including primitives, arrays, dates, maps, sets, and objects","className returns constructor name for objects and null when constructor is absent or null prototype","functionName returns the identifier name of named and assigned function declarations","every returns true when all elements in an array, Set, or Map satisfy predicate and false otherwise","valueToString converts primitives, objects, and nullish values to string representations","prototypes provides safe uncurried methods on array, string, and object prototypes","calledInOrder returns true when spy instances are executed in sequential order","orderByFirstCall sorts an array of spy objects chronologically by their first invocation callId"],"goal":"verify pkg:npm/%40sinonjs/commons@3.0.1","kind":"HOW","packages":["pkg:npm/%40sinonjs/commons@3.0.1"],"schemaVersion":1},"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/%40sinonjs/commons@3.0.1"],"schemaVersion":1,"subject":"pkg:npm/%40sinonjs/commons@3.0.1","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-sinonjs-commons",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-sinonjs-commons",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "@sinonjs/commons": "3.0.1"
      }
    },
    "node_modules/@sinonjs/commons": {
      "version": "3.0.1",
      "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-3.0.1.tgz",
      "integrity": "sha512-K3mCHKQ9sVh8o1C9cxkwxaOmXoAMlDxC1mYyHrjqOWEcBjYr76t96zL2zlj5dUGZ3HSw240X1qgH3Mjf1yJWpQ==",
      "license": "BSD-3-Clause",
      "dependencies": {
        "type-detect": "4.0.8"
      }
    },
    "node_modules/type-detect": {
      "version": "4.0.8",
      "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz",
      "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==",
      "license": "MIT",
      "engines": {
        "node": ">=4"
      }
    }
  }
}
package.json
{
  "name": "sample-sinonjs-commons",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification sample for @sinonjs/commons",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "@sinonjs/commons": "3.0.1"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/%40sinonjs/commons@3.0.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40sinonjs/commons@3.0.1"
  ]
}
src/index.js
'use strict';

const commons = require('@sinonjs/commons');

/**
 * Inspects a value using @sinonjs/commons utilities.
 * @param {*} value
 * @returns {object}
 */
function inspectValue(value) {
  return {
    type: commons.typeOf(value),
    className: typeof value === 'object' && value !== null ? commons.className(value) : null,
    stringRepresentation: commons.valueToString(value)
  };
}

/**
 * Validates that all items in a collection satisfy a predicate.
 * @param {Array|Set|Map} collection
 * @param {Function} predicate
 * @returns {boolean}
 */
function validateAll(collection, predicate) {
  return commons.every(collection, predicate);
}

module.exports = {
  commons,
  inspectValue,
  validateAll
};
test/contract.js
'use strict';

const assert = require('assert');
const commons = require('@sinonjs/commons');
const { inspectValue, validateAll } = require('../src/index.js');

// 1. typeOf returns lowercase type name for JavaScript values including primitives, arrays, dates, maps, sets, and objects
{
  assert.strictEqual(commons.typeOf(null), 'null');
  assert.strictEqual(commons.typeOf(undefined), 'undefined');
  assert.strictEqual(commons.typeOf('sample text'), 'string');
  assert.strictEqual(commons.typeOf(42), 'number');
  assert.strictEqual(commons.typeOf(true), 'boolean');
  assert.strictEqual(commons.typeOf([]), 'array');
  assert.strictEqual(commons.typeOf({}), 'object');
  assert.strictEqual(commons.typeOf(new Date()), 'date');
  assert.strictEqual(commons.typeOf(new Map()), 'map');
  assert.strictEqual(commons.typeOf(new Set()), 'set');
  assert.strictEqual(commons.typeOf(/pattern/i), 'regexp');
  assert.strictEqual(commons.typeOf(() => {}), 'function');

  const inspected = inspectValue(new Date());
  assert.strictEqual(inspected.type, 'date');
}

// 2. className returns constructor name for objects and null when constructor is absent or null prototype
{
  assert.strictEqual(commons.className({}), 'Object');
  assert.strictEqual(commons.className([]), 'Array');
  assert.strictEqual(commons.className(new Date()), 'Date');
  assert.strictEqual(commons.className(new Map()), 'Map');
  assert.strictEqual(commons.className(new Set()), 'Set');
  assert.strictEqual(commons.className(Object.create(null)), null);

  class CustomService {}
  assert.strictEqual(commons.className(new CustomService()), 'CustomService');

  const inspected = inspectValue(new CustomService());
  assert.strictEqual(inspected.className, 'CustomService');
}

// 3. functionName returns the identifier name of named and assigned function declarations
{
  function declaredFunction() {}
  assert.strictEqual(commons.functionName(declaredFunction), 'declaredFunction');

  const namedExpression = function computeTotal() {};
  assert.strictEqual(commons.functionName(namedExpression), 'computeTotal');

  const assignedAnonymous = function () {};
  assert.strictEqual(commons.functionName(assignedAnonymous), 'assignedAnonymous');
}

// 4. every returns true when all elements in an array, Set, or Map satisfy predicate and false otherwise
{
  assert.strictEqual(commons.every([2, 4, 6], (x) => x % 2 === 0), true);
  assert.strictEqual(commons.every([2, 3, 6], (x) => x % 2 === 0), false);

  const set = new Set([10, 20, 30]);
  assert.strictEqual(commons.every(set, (x) => x >= 10), true);
  assert.strictEqual(commons.every(set, (x) => x > 15), false);

  const map = new Map([
    ['k1', 100],
    ['k2', 200]
  ]);
  assert.strictEqual(commons.every(map, (val) => val >= 100), true);
  assert.strictEqual(commons.every(map, (val) => val > 150), false);

  assert.strictEqual(validateAll([1, 2, 3], (x) => x > 0), true);
  assert.strictEqual(validateAll([1, -2, 3], (x) => x > 0), false);
}

// 5. valueToString converts primitives, objects, and nullish values to string representations
{
  assert.strictEqual(commons.valueToString('sample string'), 'sample string');
  assert.strictEqual(commons.valueToString(12345), '12345');
  assert.strictEqual(commons.valueToString(true), 'true');
  assert.strictEqual(commons.valueToString(null), 'null');
  assert.strictEqual(commons.valueToString(undefined), 'undefined');
  assert.strictEqual(commons.valueToString([1, 2, 3]), '1,2,3');

  const customObj = {
    toString() {
      return 'custom-string-output';
    }
  };
  assert.strictEqual(commons.valueToString(customObj), 'custom-string-output');

  const inspected = inspectValue(customObj);
  assert.strictEqual(inspected.stringRepresentation, 'custom-string-output');
}

// 6. prototypes provides safe uncurried methods on array, string, and object prototypes
{
  const testArray = [10, 20, 30, 40];
  assert.deepStrictEqual(commons.prototypes.array.slice(testArray, 1, 3), [20, 30]);
  assert.strictEqual(commons.prototypes.array.includes(testArray, 20), true);
  assert.strictEqual(commons.prototypes.array.includes(testArray, 99), false);

  assert.strictEqual(commons.prototypes.string.trim('   padded content   '), 'padded content');
  assert.strictEqual(commons.prototypes.string.startsWith('prefix-suffix', 'prefix'), true);
  assert.strictEqual(commons.prototypes.string.indexOf('abcdef', 'cd'), 2);

  const testObj = { prop: 'value' };
  assert.strictEqual(commons.prototypes.object.hasOwnProperty(testObj, 'prop'), true);
  assert.strictEqual(commons.prototypes.object.hasOwnProperty(testObj, 'missing'), false);
}

// 7. calledInOrder returns true when spy instances are executed in sequential order
{
  let sequence = 0;
  function createTestSpy(id) {
    return {
      id,
      callCount: 0,
      callOrder: [],
      call() {
        this.callCount++;
        this.callOrder.push(++sequence);
      },
      calledBefore(other) {
        if (this.callCount === 0 || other.callCount === 0) return false;
        return this.callOrder[0] < other.callOrder[0];
      }
    };
  }

  const spyFirst = createTestSpy('spyFirst');
  const spySecond = createTestSpy('spySecond');
  const spyThird = createTestSpy('spyThird');

  spyFirst.call();
  spySecond.call();
  spyThird.call();

  assert.strictEqual(commons.calledInOrder([spyFirst, spySecond, spyThird]), true);
  assert.strictEqual(commons.calledInOrder([spySecond, spyFirst, spyThird]), false);
  assert.strictEqual(commons.calledInOrder(spyFirst, spySecond, spyThird), true);
  assert.strictEqual(commons.calledInOrder(spyThird, spySecond, spyFirst), false);
}

// 8. orderByFirstCall sorts an array of spy objects chronologically by their first invocation callId
{
  const proxyA = {
    getCall(index) {
      return index === 0 ? { callId: 300 } : null;
    }
  };
  const proxyB = {
    getCall(index) {
      return index === 0 ? { callId: 100 } : null;
    }
  };
  const proxyC = {
    getCall(index) {
      return index === 0 ? { callId: 200 } : null;
    }
  };

  const sorted = commons.orderByFirstCall([proxyA, proxyB, proxyC]);
  assert.deepStrictEqual(sorted, [proxyB, proxyC, proxyA]);
}

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

オリジンシーダー

匿名