Пример
lodash 4.18.1: Deep clone complex nested objects, arrays, and custom values preserving reference independence with cloneDeep
Проверенный пример — npm lodash 4.18.1: Deep clone complex nested objects, arrays, and custom values preserving reference independence with cloneDeep.…
sha256:ee9930a6c5ca6fe8600da13df5c464b1aba71ca62aa6c023d046f30fda69e83f
Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла.
Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди.
MIT-0
Свидетельства выполнения
Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.
- Основа свидетельства
- Подписанный контракт пройден
- Квитанции проверки
- 2
- Ключи подписи, собравшие его
- 1
Заявленная среда
linux 24 · ubuntu · glibc 2.39 x64 npm
Среды запусков проверки
| Окружение | Контракт | Этапы | Запуск |
|---|---|---|---|
| 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-23 |
| node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2… |
2026-09-08 |
Кейс
HOW- Цель
- Deep clone complex nested objects, arrays, and custom values preserving reference independence with cloneDeep
- Пакеты
- Символы
-
- cloneDeep
- Создан
- 2026-08-23T05:55:59Z
Контракт
- cloneDeep recursively clones nested plain objects and arrays into distinct new references
- Mutating cloned nested objects or nested arrays does not affect the original source
- cloneDeep accurately preserves and copies Date, RegExp, Set, and Map instances with independent contents
- cloneDeep correctly preserves circular references and cyclical structures without infinite recursion
- cloneDeep returns primitive values directly without modification
- cloneDeep accurately clones typed arrays and ArrayBuffer instances
Файлы
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- test/contract.cjs
Исходный код
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: Deep clone complex nested objects, arrays, and custom values preserving reference independence with cloneDeep
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/lodash@4.18.1
Demonstrate these symbols/APIs:
- cloneDeep
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:78f8d5f54f5cd53d644e02d14a8c4ca47319fca9c5dfa8a18163c6065159543a","contract":["cloneDeep recursively clones nested plain objects and arrays into distinct new references","Mutating cloned nested objects or nested arrays does not affect the original source","cloneDeep accurately preserves and copies Date, RegExp, Set, and Map instances with independent contents","cloneDeep correctly preserves circular references and cyclical structures without infinite recursion","cloneDeep returns primitive values directly without modification","cloneDeep accurately clones typed arrays and ArrayBuffer instances"],"goal":"Deep clone complex nested objects, arrays, and custom values preserving reference independence with cloneDeep","kind":"HOW","packages":["pkg:npm/lodash@4.18.1"],"schemaVersion":1,"symbols":["cloneDeep"]},"contractCommand":["node","test/contract.cjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/lodash@4.18.1"],"schemaVersion":1,"subject":"pkg:npm/lodash@4.18.1","symbols":["cloneDeep"],"verifierAdapter":"node-typescript@1"}
{
"name": "lodash-clonedeep-verification",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "lodash-clonedeep-verification",
"version": "1.0.0",
"dependencies": {
"lodash": "4.18.1"
}
},
"node_modules/lodash": {
"version": "4.18.1",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.18.1.tgz",
"integrity": "sha512-dMInicTPVE8d1e5otfwmmjlxkZoUpiVLwyeTdUsi/Caj/gfzzblBcCE5sRHV/AsjuCmxWrte2TNGSYuCeCq+0Q==",
"license": "MIT"
}
}
}
{
"name": "lodash-clonedeep-verification",
"version": "1.0.0",
"private": true,
"description": "Clean-room verification for lodash cloneDeep",
"dependencies": {
"lodash": "4.18.1"
}
}
{
"schemaVersion": 1,
"goal": "Deep clone complex nested objects, arrays, and custom values preserving reference independence with cloneDeep",
"kind": "HOW",
"packages": [
"pkg:npm/lodash@4.18.1"
],
"symbols": [
"cloneDeep"
]
}
const assert = require('node:assert');
const { cloneDeep } = require('lodash');
// 1. cloneDeep recursively clones nested plain objects and arrays into distinct new references
const original = {
name: 'CodeSampleX',
meta: {
version: 1,
tags: ['build', 'test']
},
counts: [10, 20, [30, 40]]
};
const cloned = cloneDeep(original);
assert.deepStrictEqual(cloned, original);
assert.notStrictEqual(cloned, original);
assert.notStrictEqual(cloned.meta, original.meta);
assert.notStrictEqual(cloned.meta.tags, original.meta.tags);
assert.notStrictEqual(cloned.counts, original.counts);
assert.notStrictEqual(cloned.counts[2], original.counts[2]);
// 2. Mutating cloned nested objects or nested arrays does not affect the original source
cloned.meta.version = 2;
cloned.meta.tags.push('verify');
cloned.counts[2].push(50);
assert.strictEqual(original.meta.version, 1);
assert.deepStrictEqual(original.meta.tags, ['build', 'test']);
assert.deepStrictEqual(original.counts[2], [30, 40]);
// 3. cloneDeep accurately preserves and copies Date, RegExp, Set, and Map instances with independent contents
const date = new Date('2026-08-23T00:00:00.000Z');
const regex = /test-[a-z]+/gi;
const set = new Set(['alpha', 'beta']);
const map = new Map([['key1', { value: 100 }]]);
const complexObj = { date, regex, set, map };
const complexCloned = cloneDeep(complexObj);
assert.ok(complexCloned.date instanceof Date);
assert.strictEqual(complexCloned.date.getTime(), date.getTime());
assert.notStrictEqual(complexCloned.date, date);
assert.ok(complexCloned.regex instanceof RegExp);
assert.strictEqual(complexCloned.regex.source, regex.source);
assert.strictEqual(complexCloned.regex.flags, regex.flags);
assert.notStrictEqual(complexCloned.regex, regex);
assert.ok(complexCloned.set instanceof Set);
assert.strictEqual(complexCloned.set.size, 2);
assert.ok(complexCloned.set.has('alpha'));
assert.notStrictEqual(complexCloned.set, set);
complexCloned.set.add('gamma');
assert.strictEqual(set.has('gamma'), false);
assert.ok(complexCloned.map instanceof Map);
assert.strictEqual(complexCloned.map.size, 1);
assert.notStrictEqual(complexCloned.map, map);
assert.notStrictEqual(complexCloned.map.get('key1'), map.get('key1'));
assert.deepStrictEqual(complexCloned.map.get('key1'), { value: 100 });
// 4. cloneDeep correctly preserves circular references and cyclical structures without infinite recursion
const cyclicObj = { id: 'parent' };
cyclicObj.self = cyclicObj;
cyclicObj.child = { parent: cyclicObj };
const cyclicCloned = cloneDeep(cyclicObj);
assert.strictEqual(cyclicCloned.id, 'parent');
assert.strictEqual(cyclicCloned.self, cyclicCloned);
assert.strictEqual(cyclicCloned.child.parent, cyclicCloned);
assert.notStrictEqual(cyclicCloned, cyclicObj);
assert.notStrictEqual(cyclicCloned.child, cyclicObj.child);
// 5. cloneDeep returns primitive values directly without modification
assert.strictEqual(cloneDeep(42), 42);
assert.strictEqual(cloneDeep('sample-string'), 'sample-string');
assert.strictEqual(cloneDeep(true), true);
assert.strictEqual(cloneDeep(null), null);
assert.strictEqual(cloneDeep(undefined), undefined);
const sym = Symbol('token');
assert.strictEqual(cloneDeep(sym), sym);
// 6. cloneDeep accurately clones typed arrays and ArrayBuffer instances
const uint8 = new Uint8Array([1, 2, 3, 4]);
const clonedUint8 = cloneDeep(uint8);
assert.ok(clonedUint8 instanceof Uint8Array);
assert.deepStrictEqual(Array.from(clonedUint8), [1, 2, 3, 4]);
assert.notStrictEqual(clonedUint8, uint8);
clonedUint8[0] = 99;
assert.strictEqual(uint8[0], 1);
console.log('Contract passed');
Исходный сидер
аноним