CodeSampleX

示例

call-bind-apply-helpers 1.0.2

已验证示例 — npm call-bind-apply-helpers 1.0.2. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: callBind binds a function call with receiver and prepends…

sha256:071451cca1e5eee666101d425994b0966aebbf182e77714289205b3883485e43

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 MIT-0

执行证据

声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。

证据依据
签名契约通过
验证回执
1
构建过它的签名密钥
1
声明的环境 windows 11 x64 npm

验证运行环境

环境 契约 阶段 运行日期
node 22 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1
2026-08-19

案例

HOW
目标
verify pkg:npm/call-bind-apply-helpers@1.0.2
包
创建时间
2026-08-18T18:07:12Z

契约

  1. callBind binds a function call with receiver and prepends receiver on subsequent calls
  2. callBind with fixed receiver binds thisArg permanently
  3. callBind with fixed receiver and bound arguments partially applies arguments
  4. callBind throws TypeError when passed empty arguments or non-function
  5. actualApply invokes a target function with thisArg and args array
  6. applyBind creates an apply-based bound caller
  7. functionCall and functionApply reference intrinsic Function prototypes
  8. wrapper bindHelper matches direct callBind behavior

文件

  • PROMPT.md
  • csx.json
  • index.mjs
  • package-lock.json
  • package.json
  • spec.json
  • 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/call-bind-apply-helpers@1.0.2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/call-bind-apply-helpers@1.0.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:4794c6896c8c00964451734084506ea41ac9a8679ca657c07071e83c3391c59d","contract":["callBind binds a function call with receiver and prepends receiver on subsequent calls","callBind with fixed receiver binds thisArg permanently","callBind with fixed receiver and bound arguments partially applies arguments","callBind throws TypeError when passed empty arguments or non-function","actualApply invokes a target function with thisArg and args array","applyBind creates an apply-based bound caller","functionCall and functionApply reference intrinsic Function prototypes","wrapper bindHelper matches direct callBind behavior"],"goal":"verify pkg:npm/call-bind-apply-helpers@1.0.2","kind":"HOW","packages":["pkg:npm/call-bind-apply-helpers@1.0.2"],"schemaVersion":1},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","ecosystem":"npm","os":"windows","osVersionBucket":"11","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/call-bind-apply-helpers@1.0.2"],"schemaVersion":1,"verifierAdapter":"node-typescript@1"}
index.mjs
import callBind from 'call-bind-apply-helpers';

/**
 * Binds a function call with the provided receiver and optional initial arguments.
 * @param {Function} fn - The target function to bind.
 * @param {*} [thisArg] - Optional fixed receiver.
 * @param {...*} [args] - Initial arguments to bind.
 * @returns {Function} Bound caller function.
 */
export function bindHelper(fn, thisArg, ...args) {
  if (arguments.length === 1) {
    return callBind([fn]);
  }
  return callBind([fn, thisArg, ...args]);
}

export default callBind;
package-lock.json
{
  "name": "sample",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample",
      "version": "1.0.0",
      "dependencies": {
        "call-bind-apply-helpers": "1.0.2"
      }
    },
    "node_modules/call-bind-apply-helpers": {
      "version": "1.0.2",
      "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz",
      "integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==",
      "license": "MIT",
      "dependencies": {
        "es-errors": "^1.3.0",
        "function-bind": "^1.1.2"
      },
      "engines": {
        "node": ">= 0.4"
      }
    },
    "node_modules/es-errors": {
      "version": "1.3.0",
      "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz",
      "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.4"
      }
    },
    "node_modules/function-bind": {
      "version": "1.1.2",
      "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
      "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==",
      "license": "MIT",
      "funding": {
        "url": "https://github.com/sponsors/ljharb"
      }
    }
  }
}
package.json
{
  "name": "sample",
  "version": "1.0.0",
  "type": "module",
  "dependencies": {
    "call-bind-apply-helpers": "1.0.2"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/call-bind-apply-helpers@1.0.2",
  "kind": "HOW",
  "packages": [
    "pkg:npm/call-bind-apply-helpers@1.0.2"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import callBind from 'call-bind-apply-helpers';
import actualApply from 'call-bind-apply-helpers/actualApply';
import applyBind from 'call-bind-apply-helpers/applyBind';
import functionCall from 'call-bind-apply-helpers/functionCall';
import functionApply from 'call-bind-apply-helpers/functionApply';
import reflectApply from 'call-bind-apply-helpers/reflectApply';
import { bindHelper } from '../index.mjs';

// Case 1: callBind binds a function call with receiver and prepends receiver on subsequent calls
{
  function sum(a, b) {
    return (this ? this.base : 0) + a + b;
  }

  const boundSum = callBind([sum]);
  const ctx = { base: 10 };
  const result = boundSum(ctx, 2, 3);
  assert.equal(result, 15, 'boundSum should invoke sum with ctx as thisArg');
}

// Case 2: callBind with fixed receiver binds thisArg permanently
{
  function getGreeting(name) {
    return `${this.prefix}, ${name}!`;
  }

  const context = { prefix: 'Hello' };
  const greet = callBind([getGreeting, context]);
  assert.equal(greet('World'), 'Hello, World!', 'greet should use bound context');
}

// Case 3: callBind with fixed receiver and bound arguments partially applies arguments
{
  function compute(a, b, c) {
    return (this.factor * a) + b - c;
  }

  const ctx = { factor: 2 };
  const boundCompute = callBind([compute, ctx, 5]);
  assert.equal(boundCompute(3, 1), 12, 'should compute (2 * 5) + 3 - 1 = 12');
}

// Case 4: callBind throws TypeError when passed empty arguments or non-function
{
  assert.throws(
    () => {
      callBind([]);
    },
    TypeError,
    'callBind with empty array should throw TypeError'
  );

  assert.throws(
    () => {
      callBind(['not-a-function']);
    },
    TypeError,
    'callBind with non-function should throw TypeError'
  );
}

// Case 5: actualApply invokes a target function with thisArg and args array
{
  function multiply(x, y) {
    return this.scale * x * y;
  }

  const ctx = { scale: 3 };
  const res = actualApply(multiply, ctx, [4, 5]);
  assert.equal(res, 60, 'actualApply should apply arguments with context');
}

// Case 6: applyBind creates an apply-based bound caller
{
  function joinItems(sep) {
    return this.items.join(sep);
  }

  const caller = applyBind(joinItems);
  const context = { items: ['a', 'b', 'c'] };
  assert.equal(caller(context, [', ']), 'a, b, c', 'applyBind caller should invoke function with apply signature');
}

// Case 7: functionCall and functionApply reference intrinsic Function prototypes
{
  assert.equal(functionCall, Function.prototype.call, 'functionCall should be Function.prototype.call');
  assert.equal(functionApply, Function.prototype.apply, 'functionApply should be Function.prototype.apply');
  if (typeof reflectApply === 'function') {
    assert.equal(reflectApply, Reflect.apply, 'reflectApply should be Reflect.apply');
  }
}

// Case 8: wrapper bindHelper matches direct callBind behavior
{
  function format(suffix) {
    return `${this.name}:${suffix}`;
  }

  const helperWithReceiver = bindHelper(format, { name: 'item' });
  assert.equal(helperWithReceiver('ok'), 'item:ok', 'bindHelper with receiver should match callBind behavior');

  const helperUnbound = bindHelper(format);
  assert.equal(helperUnbound({ name: 'custom' }, 'val'), 'custom:val', 'bindHelper without receiver should match callBind behavior');
}

console.log('PASS: all call-bind-apply-helpers contract assertions passed');

原始种子者

匿名