Beispiel
p-locate 5.0.0
Verifiziertes Beispiel für npm p-locate 5.0.0. Der Vertrag lief auf node 22 · linux alpine/x64 · docker und bestand: p-locate returns the first element in…
sha256:189ea518bc7989a838d12a5f129144dfcfb0bfc7654dc24ed51140ef7ff24d86
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 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-26 |
Fall
HOW- Ziel
- verify pkg:npm/p-locate@5.0.0
- Pakete
- Umgebung
- node 22.23.2
- Erstellt
- 2026-08-26T08:17:06Z
Contract
- p-locate returns the first element in iterable order satisfying an async predicate
- p-locate returns the first element satisfying a synchronous predicate
- p-locate accepts an iterable of promises and awaits each element before testing
- p-locate preserves input order by default when searching across async predicates with variable resolution times
- p-locate returns the fastest resolved match when preserveOrder is set to false
- p-locate respects the concurrency option to limit concurrent test executions
- p-locate resolves to undefined when no elements satisfy the predicate
- p-locate propagates errors when a predicate rejects
Dateien
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.js
Quelltext
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/p-locate@5.0.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/p-locate@5.0.0
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:d757a7204e9b6a8b0feb7160579934a6d71fdec6c461d411eae7dd8422137169","constraints":{"executionContext":"node"},"contract":["p-locate returns the first element in iterable order satisfying an async predicate","p-locate returns the first element satisfying a synchronous predicate","p-locate accepts an iterable of promises and awaits each element before testing","p-locate preserves input order by default when searching across async predicates with variable resolution times","p-locate returns the fastest resolved match when preserveOrder is set to false","p-locate respects the concurrency option to limit concurrent test executions","p-locate resolves to undefined when no elements satisfy the predicate","p-locate propagates errors when a predicate rejects"],"goal":"verify pkg:npm/p-locate@5.0.0","kind":"HOW","packages":["pkg:npm/p-locate@5.0.0"],"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/p-locate@5.0.0"],"schemaVersion":1,"subject":"pkg:npm/p-locate@5.0.0","verifierAdapter":"node-typescript@1"}
{
"name": "p-locate-sample",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "p-locate-sample",
"version": "1.0.0",
"dependencies": {
"p-locate": "5.0.0"
}
},
"node_modules/p-limit": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz",
"integrity": "sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==",
"license": "MIT",
"dependencies": {
"yocto-queue": "^0.1.0"
},
"engines": {
"node": ">=10"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/p-locate": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/p-locate/-/p-locate-5.0.0.tgz",
"integrity": "sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw==",
"license": "MIT",
"dependencies": {
"p-limit": "^3.0.2"
},
"engines": {
"node": ">=10"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/yocto-queue": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz",
"integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==",
"license": "MIT",
"engines": {
"node": ">=10"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
}
}
}
{
"name": "p-locate-sample",
"version": "1.0.0",
"dependencies": {
"p-locate": "5.0.0"
}
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/p-locate@5.0.0",
"kind": "HOW",
"packages": [
"pkg:npm/p-locate@5.0.0"
]
}
'use strict';
const pLocate = require('p-locate');
/**
* Finds the first element in an iterable that satisfies an asynchronous or synchronous tester.
*
* @template T
* @param {Iterable<T | Promise<T>>} iterable - An iterable of values or promises.
* @param {(element: T) => (boolean | Promise<boolean>)} tester - Predicate function returning boolean or Promise<boolean>.
* @param {object} [options] - Options for pLocate.
* @param {number} [options.concurrency] - Concurrency limit for tester executions.
* @param {boolean} [options.preserveOrder] - Whether to preserve input order.
* @returns {Promise<T | undefined>} The first matching element, or undefined.
*/
async function findFirst(iterable, tester, options) {
return pLocate(iterable, tester, options);
}
/**
* Finds the first element with a concurrency limit.
*
* @template T
* @param {Iterable<T | Promise<T>>} iterable - An iterable of values or promises.
* @param {(element: T) => (boolean | Promise<boolean>)} tester - Predicate function.
* @param {number} concurrency - Max concurrent tests.
* @returns {Promise<T | undefined>} The first matching element.
*/
async function findWithConcurrency(iterable, tester, concurrency) {
return pLocate(iterable, tester, { concurrency });
}
/**
* Finds the fastest resolving matching element without preserving input order.
*
* @template T
* @param {Iterable<T | Promise<T>>} iterable - An iterable of values or promises.
* @param {(element: T) => (boolean | Promise<boolean>)} tester - Predicate function.
* @returns {Promise<T | undefined>} The fastest resolved matching element.
*/
async function findFastestMatch(iterable, tester) {
return pLocate(iterable, tester, { preserveOrder: false });
}
module.exports = {
findFirst,
findWithConcurrency,
findFastestMatch,
};
'use strict';
const assert = require('node:assert/strict');
const {
findFirst,
findWithConcurrency,
findFastestMatch,
} = require('../src/index.js');
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
async function main() {
// Contract 1: p-locate returns the first element in iterable order satisfying an async predicate
{
const items = ['apple', 'banana', 'blueberry', 'cherry'];
const result = await findFirst(items, async (item) => {
await delay(5);
return item.startsWith('b');
});
assert.strictEqual(result, 'banana');
}
// Contract 2: p-locate returns the first element satisfying a synchronous predicate
{
const numbers = [10, 25, 30, 45];
const result = await findFirst(numbers, (num) => num > 20);
assert.strictEqual(result, 25);
}
// Contract 3: p-locate accepts an iterable of promises and awaits each element before testing
{
const promiseItems = [
Promise.resolve('alpha'),
delay(10).then(() => 'beta'),
Promise.resolve('gamma'),
];
const result = await findFirst(promiseItems, async (item) => item === 'beta');
assert.strictEqual(result, 'beta');
}
// Contract 4: p-locate preserves input order by default when searching across async predicates with variable resolution times
{
const items = ['slow-first', 'fast-second'];
const result = await findFirst(items, async (item) => {
if (item === 'slow-first') {
await delay(50);
return true;
}
if (item === 'fast-second') {
await delay(5);
return true;
}
return false;
});
assert.strictEqual(result, 'slow-first');
}
// Contract 5: p-locate returns the fastest resolved match when preserveOrder is set to false
{
const items = ['slow-match', 'fast-match'];
const result = await findFastestMatch(items, async (item) => {
if (item === 'slow-match') {
await delay(60);
return true;
}
if (item === 'fast-match') {
await delay(10);
return true;
}
return false;
});
assert.strictEqual(result, 'fast-match');
}
// Contract 6: p-locate respects the concurrency option to limit concurrent test executions
{
const items = [1, 2, 3, 4, 5, 6];
let activeTests = 0;
let maxConcurrent = 0;
const result = await findWithConcurrency(
items,
async (num) => {
activeTests++;
maxConcurrent = Math.max(maxConcurrent, activeTests);
await delay(15);
activeTests--;
return num === 5;
},
2
);
assert.strictEqual(result, 5);
assert.strictEqual(maxConcurrent <= 2, true);
assert.strictEqual(maxConcurrent >= 1, true);
}
// Contract 7: p-locate resolves to undefined when no elements satisfy the predicate
{
const items = ['one', 'two', 'three'];
const result = await findFirst(items, (item) => item === 'four');
assert.strictEqual(result, undefined);
const emptyResult = await findFirst([], () => true);
assert.strictEqual(emptyResult, undefined);
}
// Contract 8: p-locate propagates errors when a predicate rejects
{
const items = ['valid', 'error-trigger'];
let caughtError = null;
try {
await findFirst(items, async (item) => {
if (item === 'error-trigger') {
throw new Error('Predicate failed execution');
}
return false;
});
} catch (err) {
caughtError = err;
}
assert.notStrictEqual(caughtError, null);
assert.strictEqual(caughtError.message, 'Predicate failed execution');
}
console.log('All p-locate contracts verified successfully.');
}
main().catch((err) => {
console.error('Contract test failed:', err);
process.exit(1);
});
Ursprungs-Seeder
anonym