CodeSampleX

サンプル

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. node 22 · linux…

sha256:ee9930a6c5ca6fe8600da13df5c464b1aba71ca62aa6c023d046f30fda69e83f

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 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

コントラクト

  1. cloneDeep recursively clones nested plain objects and arrays into distinct new references
  2. Mutating cloned nested objects or nested arrays does not affect the original source
  3. cloneDeep accurately preserves and copies Date, RegExp, Set, and Map instances with independent contents
  4. cloneDeep correctly preserves circular references and cyclical structures without infinite recursion
  5. cloneDeep returns primitive values directly without modification
  6. cloneDeep accurately clones typed arrays and ArrayBuffer instances

ファイル

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • test/contract.cjs

ソースアーティファクトをダウンロード (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: 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.
csx.json
{"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"}
package-lock.json
{
  "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"
    }
  }
}
package.json
{
  "name": "lodash-clonedeep-verification",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification for lodash cloneDeep",
  "dependencies": {
    "lodash": "4.18.1"
  }
}
spec.json
{
  "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"
  ]
}
test/contract.cjs
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');

オリジンシーダー

匿名