サンプル
wrappy 1.0.2: wrappy
検証済みサンプル — npm wrappy 1.0.2: wrappy. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました: wrappy returns a wrapper generator function when passed a…
sha256:fe88c89d35d48a347a6dcaeb0bb8ca0058a40c22fd24b3d754a9d7a8cc669ea9
このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。
合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。
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/wrappy@1.0.2
- パッケージ
- シンボル
-
- wrappy
- 作成日
- 2026-08-18T18:16:16Z
コントラクト
- wrappy returns a wrapper generator function when passed a wrapper function
- wrappy immediately wraps a target callback when passed both wrapper and target
- wrappy copies own enumerable properties from wrapper function to generated wrapper
- wrappy copies own enumerable properties from target callback to the returned wrapped function
- wrappy does not copy properties if returned function is identical to target callback
- wrappy preserves receiver and arguments forwarding to wrapper function
- wrappy throws TypeError with need wrapper function when first argument is not a function
- wrapFunction helper provides wrapper generator and immediate wrapping interfaces
ファイル
- PROMPT.md
- csx.json
- index.mjs
- package-lock.json
- package.json
- spec.json
- test/contract.mjs
ソース
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/wrappy@1.0.2
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/wrappy@1.0.2
Demonstrate these symbols/APIs:
- wrappy
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:975d92c4a134441a71709898631e648d603e08c40c7f9ab2d934213faf640d01","contract":["wrappy returns a wrapper generator function when passed a wrapper function","wrappy immediately wraps a target callback when passed both wrapper and target","wrappy copies own enumerable properties from wrapper function to generated wrapper","wrappy copies own enumerable properties from target callback to the returned wrapped function","wrappy does not copy properties if returned function is identical to target callback","wrappy preserves receiver and arguments forwarding to wrapper function","wrappy throws TypeError with need wrapper function when first argument is not a function","wrapFunction helper provides wrapper generator and immediate wrapping interfaces"],"goal":"verify pkg:npm/wrappy@1.0.2","kind":"HOW","packages":["pkg:npm/wrappy@1.0.2"],"schemaVersion":1,"symbols":["wrappy"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","ecosystem":"npm","os":"windows","osVersionBucket":"11","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/wrappy@1.0.2"],"schemaVersion":1,"symbols":["wrappy"],"verifierAdapter":"node-typescript@1"}
import wrappy from 'wrappy';
/**
* Wraps a transformation function so that it can be applied to a callback
* while preserving callback identity, properties, prototype, and name.
*
* @param {Function} fn - The wrapper function.
* @param {Function} [cb] - Optional target callback to wrap immediately.
* @returns {Function} The wrapped function or wrapper generator.
*/
export function wrapFunction(fn, cb) {
if (cb !== undefined) {
return wrappy(fn, cb);
}
return wrappy(fn);
}
export default wrappy;
{
"name": "sample",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample",
"version": "1.0.0",
"dependencies": {
"wrappy": "1.0.2"
}
},
"node_modules/wrappy": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==",
"license": "ISC"
}
}
}
{
"name": "sample",
"version": "1.0.0",
"type": "module",
"dependencies": {
"wrappy": "1.0.2"
}
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/wrappy@1.0.2",
"kind": "HOW",
"packages": [
"pkg:npm/wrappy@1.0.2"
],
"symbols": [
"wrappy"
]
}
import assert from 'node:assert/strict';
import wrappy from 'wrappy';
import { wrapFunction } from '../index.mjs';
// Case 1: wrappy returns a wrapper generator function when passed a wrapper function
{
const makeMultiplier = wrappy((cb) => {
return function (...args) {
return cb(...args) * 2;
};
});
assert.equal(typeof makeMultiplier, 'function', 'wrappy(fn) should return a wrapper generator function');
const add = (a, b) => a + b;
const wrappedAdd = makeMultiplier(add);
assert.equal(typeof wrappedAdd, 'function', 'wrapper generator should return a function');
assert.equal(wrappedAdd(2, 3), 10, 'wrapped function should apply transformation: (2 + 3) * 2 = 10');
}
// Case 2: wrappy immediately wraps a target callback when passed both wrapper and target
{
function prependHello(cb) {
return function (name) {
return `Hello, ${cb(name)}`;
};
}
function getTarget(name) {
return name.toUpperCase();
}
const greeted = wrappy(prependHello, getTarget);
assert.equal(typeof greeted, 'function', 'wrappy(fn, cb) should return wrapped callback');
assert.equal(greeted('world'), 'Hello, WORLD', 'wrappy(fn, cb) should immediately wrap the callback');
}
// Case 3: wrappy copies own enumerable properties from wrapper function to generated wrapper
{
function myWrapper(cb) {
return function (...args) {
return cb(...args);
};
}
myWrapper.customMetadata = 'wrapper-v1';
myWrapper.version = 42;
const generator = wrappy(myWrapper);
assert.equal(generator.customMetadata, 'wrapper-v1', 'wrapper generator should inherit wrapper custom properties');
assert.equal(generator.version, 42, 'wrapper generator should inherit wrapper version property');
}
// Case 4: wrappy copies own enumerable properties from target callback to the returned wrapped function
{
const once = wrappy((cb) => {
let called = false;
let result;
return function (...args) {
if (called) return result;
called = true;
result = cb.apply(this, args);
return result;
};
});
function originalWorker(x) {
return x * 3;
}
originalWorker.role = 'worker';
originalWorker.taskCount = 5;
const wrappedWorker = once(originalWorker);
assert.equal(wrappedWorker.role, 'worker', 'wrapped function should inherit callback own property role');
assert.equal(wrappedWorker.taskCount, 5, 'wrapped function should inherit callback own property taskCount');
assert.equal(wrappedWorker(4), 12, 'first call should compute 4 * 3 = 12');
assert.equal(wrappedWorker(10), 12, 'subsequent calls should return cached result 12');
}
// Case 5: wrappy does not copy properties if returned function is identical to target callback
{
const identityWrapper = wrappy((cb) => cb);
function noop() {}
noop.flag = true;
const result = identityWrapper(noop);
assert.equal(result, noop, 'identity wrapper returns the original callback unchanged');
}
// Case 6: wrappy preserves receiver and arguments forwarding to wrapper function
{
function withContext(cb) {
return function (...args) {
return `${this.prefix}: ${cb.apply(this, args)}`;
};
}
const wrapWithCtx = wrappy(withContext);
const formatter = wrapWithCtx(function (val) {
return val + this.suffix;
});
const context = { prefix: 'PRE', suffix: 'POST' };
const res = formatter.call(context, 'DATA');
assert.equal(res, 'PRE: DATAPOST', 'this context and arguments should be preserved');
}
// Case 7: wrappy throws TypeError with need wrapper function when first argument is not a function
{
assert.throws(
() => {
wrappy(null);
},
{
name: 'TypeError',
message: 'need wrapper function'
},
'wrappy(null) should throw TypeError with message "need wrapper function"'
);
assert.throws(
() => {
wrappy('not-a-function');
},
{
name: 'TypeError',
message: 'need wrapper function'
},
'wrappy non-function should throw TypeError'
);
}
// Case 8: wrapFunction helper provides wrapper generator and immediate wrapping interfaces
{
const helperGen = wrapFunction((cb) => (x) => cb(x) + 1);
const inc = helperGen((x) => x * 10);
assert.equal(inc(5), 51, 'wrapFunction with 1 arg should act as wrapper generator');
const direct = wrapFunction((cb) => (x) => cb(x) - 1, (x) => x * 2);
assert.equal(direct(5), 9, 'wrapFunction with 2 args should immediately wrap callback');
}
console.log('PASS: all wrappy contract assertions passed');
オリジンシーダー
匿名