示例
@vitest/utils 4.1.10
已验证示例 — npm @vitest/utils 4.1.10. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: getType distinguishes JavaScript types including primitives…
sha256:8245000183204a547fda42446ae415ce52ef03b4a6444fee8d0b6248c4d44733
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
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-28 |
案例
HOW- 目标
- verify pkg:npm/%40vitest/utils@4.1.10
- 环境
- node 22.23.2
- 创建时间
- 2026-08-28T08:44:39Z
契约
- getType distinguishes JavaScript types including primitives, collections, and built-ins
- deepClone creates an independent deep copy of nested objects and arrays
- deepMerge deeply merges source object properties into target object
- createDefer creates a Promise with attached resolve and reject methods
- slash normalizes Windows backslash paths to Unix forward slashes
- toArray converts nullish values to empty arrays and wraps non-array values in single-element arrays
- isObject identifies object structures while returning false for arrays, functions, and primitives
- isPrimitive identifies JavaScript primitive values and rejects object structures
- cleanUrl strips query strings and hash fragments from URLs
- nanoid generates random identifier strings with default and custom lengths
- getSafeTimers provides access to unmocked native timer methods
- delay returns a promise that resolves after the specified duration
- diff computes differences between two values
- stringify serializes values into readable formatted strings
- processError processes error objects into structured test error representations
- unique removes duplicate primitive elements from an array
文件
- 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/%40vitest/utils@4.1.10
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/%40vitest/utils@4.1.10
Constraints:
- executionContext: node
Required runtime conditions:
- ecosystem: npm
- language: javascript
- moduleSystem: cjs
- packageManager: npm@10.9.8
- runtime: node@22.23.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.
{"case":{"caseId":"case:sha256:82aef9a632ebfc5a75c3a7c505964053666c84a7bb9bae064ad181d169f5eaa4","constraints":{"executionContext":"node"},"contract":["getType distinguishes JavaScript types including primitives, collections, and built-ins","deepClone creates an independent deep copy of nested objects and arrays","deepMerge deeply merges source object properties into target object","createDefer creates a Promise with attached resolve and reject methods","slash normalizes Windows backslash paths to Unix forward slashes","toArray converts nullish values to empty arrays and wraps non-array values in single-element arrays","isObject identifies object structures while returning false for arrays, functions, and primitives","isPrimitive identifies JavaScript primitive values and rejects object structures","cleanUrl strips query strings and hash fragments from URLs","nanoid generates random identifier strings with default and custom lengths","getSafeTimers provides access to unmocked native timer methods","delay returns a promise that resolves after the specified duration","diff computes differences between two values","stringify serializes values into readable formatted strings","processError processes error objects into structured test error representations","unique removes duplicate primitive elements from an array"],"goal":"verify pkg:npm/%40vitest/utils@4.1.10","kind":"HOW","packages":["pkg:npm/%40vitest/utils@4.1.10"],"schemaVersion":1},"contractCommand":["node","test/contract.mjs"],"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/%40vitest/utils@4.1.10"],"schemaVersion":1,"subject":"pkg:npm/%40vitest/utils@4.1.10","verifierAdapter":"node-typescript@1"}
import {
getType,
deepMerge,
deepClone,
createDefer,
slash,
toArray,
isObject,
isPrimitive,
notNullish,
cleanUrl,
nanoid,
unique
} from '@vitest/utils/helpers';
import { diff } from '@vitest/utils/diff';
import { stringify, format } from '@vitest/utils/display';
import { delay, getSafeTimers } from '@vitest/utils/timers';
import { processError } from '@vitest/utils/error';
export {
getType,
deepMerge,
deepClone,
createDefer,
slash,
toArray,
isObject,
isPrimitive,
notNullish,
cleanUrl,
nanoid,
unique,
diff,
stringify,
format,
delay,
getSafeTimers,
processError
};
export function cloneAndMerge(target, source) {
const clonedTarget = deepClone(target);
return deepMerge(clonedTarget, source);
}
export function createResolvedDefer(value) {
const deferred = createDefer();
deferred.resolve(value);
return deferred;
}
{
"name": "sample-vitest-utils",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-vitest-utils",
"version": "1.0.0",
"dependencies": {
"@vitest/utils": "4.1.10"
}
},
"node_modules/@vitest/pretty-format": {
"version": "4.1.10",
"resolved": "https://registry.npmjs.org/@vitest/pretty-format/-/pretty-format-4.1.10.tgz",
"integrity": "sha512-W1HsjSH4MXQ9YfmmhLAoIYf1HRfekQCGngeIgcei6MP5QQGWUe0gkopdZQaVCFO+JDJMrAJGwa5pRpNpvy4P8Q==",
"license": "MIT",
"dependencies": {
"tinyrainbow": "^3.1.0"
},
"funding": {
"url": "https://opencollective.com/vitest"
}
},
"node_modules/@vitest/utils": {
"version": "4.1.10",
"resolved": "https://registry.npmjs.org/@vitest/utils/-/utils-4.1.10.tgz",
"integrity": "sha512-fy9am/HWxbaGt/Sawrp90vt6Y6jQwf1RX77cz3uwoJwJVMli/e1IEwRPnMNJ7vKfPTwo0diXifkpPvwH9v7nGA==",
"license": "MIT",
"dependencies": {
"@vitest/pretty-format": "4.1.10",
"convert-source-map": "^2.0.0",
"tinyrainbow": "^3.1.0"
},
"funding": {
"url": "https://opencollective.com/vitest"
}
},
"node_modules/convert-source-map": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-2.0.0.tgz",
"integrity": "sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==",
"license": "MIT"
},
"node_modules/tinyrainbow": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/tinyrainbow/-/tinyrainbow-3.1.1.tgz",
"integrity": "sha512-yau8yJdTt989Mm0Bd/236QnzEiPf2xLLTqUZRUJOo/3CB078LSwzei343DgtJVmfJKJE3TMINY1u42SQsP6mXw==",
"license": "MIT",
"engines": {
"node": ">=14.0.0"
}
}
}
}
{
"name": "sample-vitest-utils",
"version": "1.0.0",
"description": "Clean-room verification sample for @vitest/utils",
"type": "module",
"main": "index.mjs",
"scripts": {
"test": "node test/contract.mjs"
},
"dependencies": {
"@vitest/utils": "4.1.10"
}
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/%40vitest/utils@4.1.10",
"kind": "HOW",
"packages": [
"pkg:npm/%40vitest/utils@4.1.10"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
import assert from 'node:assert/strict';
import {
getType,
deepMerge,
deepClone,
createDefer,
slash,
toArray,
isObject,
isPrimitive,
notNullish,
cleanUrl,
nanoid,
unique
} from '@vitest/utils/helpers';
import { diff } from '@vitest/utils/diff';
import { stringify, format } from '@vitest/utils/display';
import { delay, getSafeTimers } from '@vitest/utils/timers';
import { processError } from '@vitest/utils/error';
import { cloneAndMerge, createResolvedDefer } from '../index.mjs';
// 1. getType distinguishes JavaScript types including primitives, collections, and built-ins
{
assert.equal(getType(null), 'Null');
assert.equal(getType(undefined), 'Undefined');
assert.equal(getType(123), 'Number');
assert.equal(getType('test'), 'String');
assert.equal(getType(true), 'Boolean');
assert.equal(getType(Symbol('sym')), 'Symbol');
assert.equal(getType(10n), 'BigInt');
assert.equal(getType([]), 'Array');
assert.equal(getType({}), 'Object');
assert.equal(getType(/abc/), 'RegExp');
assert.equal(getType(new Set()), 'Set');
assert.equal(getType(new Map()), 'Map');
assert.equal(getType(Promise.resolve()), 'Promise');
assert.equal(getType(new Date()), 'Date');
}
// 2. deepClone creates an independent deep copy of nested objects and arrays
{
const original = {
num: 1,
nested: { str: 'alpha' },
arr: [1, { val: 2 }],
};
const copy = deepClone(original);
assert.deepEqual(copy, original);
assert.notEqual(copy, original);
assert.notEqual(copy.nested, original.nested);
assert.notEqual(copy.arr, original.arr);
assert.notEqual(copy.arr[1], original.arr[1]);
}
// 3. deepMerge deeply merges source object properties into target object
{
const target = { a: 1, nested: { b: 2, c: 3 } };
const source = { nested: { c: 4, d: 5 }, e: 6 };
const merged = deepMerge(target, source);
assert.equal(merged, target);
assert.deepEqual(target, {
a: 1,
nested: { b: 2, c: 4, d: 5 },
e: 6,
});
assert.deepEqual(source, { nested: { c: 4, d: 5 }, e: 6 });
// Test helper function cloneAndMerge
const originalObj = { x: 10, inner: { y: 20 } };
const patch = { inner: { z: 30 } };
const mergedCopy = cloneAndMerge(originalObj, patch);
assert.deepEqual(mergedCopy, { x: 10, inner: { y: 20, z: 30 } });
assert.equal(originalObj.inner.z, undefined);
}
// 4. createDefer creates a Promise with attached resolve and reject methods
{
const deferred = createDefer();
assert.ok(deferred instanceof Promise);
assert.equal(typeof deferred.resolve, 'function');
assert.equal(typeof deferred.reject, 'function');
deferred.resolve('completed');
const result = await deferred;
assert.equal(result, 'completed');
// Test helper function createResolvedDefer
const helperDefer = createResolvedDefer('fast-resolved');
const helperResult = await helperDefer;
assert.equal(helperResult, 'fast-resolved');
}
// 5. slash normalizes Windows backslash paths to Unix forward slashes
{
assert.equal(slash('foo\\bar\\baz.js'), 'foo/bar/baz.js');
assert.equal(slash('nested\\dir\\sub\\index.js'), 'nested/dir/sub/index.js');
assert.equal(slash('already/forward/slash'), 'already/forward/slash');
}
// 6. toArray converts nullish values to empty arrays and wraps non-array values in single-element arrays
{
assert.deepEqual(toArray(null), []);
assert.deepEqual(toArray(undefined), []);
assert.deepEqual(toArray('single'), ['single']);
assert.deepEqual(toArray(42), [42]);
const arr = [1, 2, 3];
assert.equal(toArray(arr), arr);
}
// 7. isObject identifies object structures while returning false for arrays, functions, and primitives
{
assert.equal(isObject({}), true);
assert.equal(isObject(Object.create(null)), true);
assert.equal(isObject(new Map()), true);
assert.equal(isObject(new Set()), true);
assert.equal(isObject([]), false);
assert.equal(isObject(() => {}), false);
assert.equal(isObject(null), false);
assert.equal(isObject(undefined), false);
assert.equal(isObject('string'), false);
assert.equal(isObject(123), false);
}
// 8. isPrimitive identifies JavaScript primitive values and rejects object structures
{
assert.equal(isPrimitive('str'), true);
assert.equal(isPrimitive(123), true);
assert.equal(isPrimitive(true), true);
assert.equal(isPrimitive(null), true);
assert.equal(isPrimitive(undefined), true);
assert.equal(isPrimitive(Symbol('s')), true);
assert.equal(isPrimitive(10n), true);
assert.equal(isPrimitive({}), false);
assert.equal(isPrimitive([]), false);
assert.equal(isPrimitive(() => {}), false);
}
// 9. cleanUrl strips query strings and hash fragments from URLs
{
assert.equal(cleanUrl('https://example.com/path?foo=bar#section'), 'https://example.com/path');
assert.equal(cleanUrl('file:///path/to/file.js?v=1'), 'file:///path/to/file.js');
}
// 10. nanoid generates random identifier strings with default and custom lengths
{
const id1 = nanoid();
const id2 = nanoid();
assert.equal(typeof id1, 'string');
assert.equal(id1.length, 21);
assert.notEqual(id1, id2);
const customId = nanoid(10);
assert.equal(typeof customId, 'string');
assert.equal(customId.length, 10);
}
// 11. getSafeTimers provides access to unmocked native timer methods
{
const timers = getSafeTimers();
assert.equal(typeof timers.setTimeout, 'function');
assert.equal(typeof timers.clearTimeout, 'function');
assert.equal(typeof timers.setInterval, 'function');
assert.equal(typeof timers.clearInterval, 'function');
}
// 12. delay returns a promise that resolves after the specified duration
{
const start = Date.now();
await delay(10);
const elapsed = Date.now() - start;
assert.ok(elapsed >= 5);
}
// 13. diff computes differences between two values
{
const diffResult = diff('hello\nworld', 'hello\nearth');
assert.equal(typeof diffResult, 'string');
assert.ok(diffResult.includes('world') || diffResult.includes('earth'));
}
// 14. stringify serializes values into readable formatted strings
{
const str = stringify({ a: 1, b: 'two' });
assert.equal(typeof str, 'string');
assert.ok(str.includes('"a": 1'));
assert.ok(str.includes('"b": "two"'));
}
// 15. processError processes error objects into structured test error representations
{
const rawErr = new Error('test failure');
const processed = processError(rawErr);
assert.equal(processed.name, 'Error');
assert.equal(processed.message, 'test failure');
assert.ok(typeof processed.stack === 'string');
}
// 16. unique removes duplicate primitive elements from an array
{
const list = [1, 2, 2, 3, 1, 4];
const uniq = unique(list);
assert.deepEqual(uniq, [1, 2, 3, 4]);
}
console.log('All @vitest/utils contract assertions passed.');
原始种子者
匿名