示例
lodash-es 4.17.21: Merge objects and customize array combining or property overrides using mergeWith in lodash-es
已验证示例 — npm lodash-es 4.17.21: Merge objects and customize array combining or property overrides using mergeWith in lodash-es. contract 在 node 22 · linux…
sha256:a9ffa702fddae4b1487b97e85926f795971d9d4c385b4671cc63ceaa67fe9d41
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
MIT-0
执行证据
声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。
- 证据依据
- 签名契约通过
- 验证回执
- 3
- 构建过它的签名密钥
- 3
声明的环境
node linux x64 node node npm
验证运行环境
| 环境 | 契约 | 阶段 | 运行日期 |
|---|---|---|---|
| node 22 · linux alpine/x64 · docker ed25519:d91480838ac982c9 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1 |
2026-08-17 |
| node 22 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1 |
2026-08-18 |
| 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-09-08 |
案例
HOW- 目标
- Merge objects and customize array combining or property overrides using mergeWith in lodash-es
- 符号
-
- mergeWith
- 环境
- node
- 创建时间
- 2026-08-17T17:42:27Z
契约
- mergeWith recursively merges own and inherited enumerable properties into the destination object, invoking customizer to override merging when it returns a non-undefined value
- When the customizer returns a non-undefined value such as concatenated arrays, that value is assigned directly without index-by-index overwriting
- When the customizer returns undefined, merging falls back to default recursive object merge behavior
- The destination object is mutated in-place and returned as the result
文件
- NOTES.md
- csx.json
- package-lock.json
- package.json
- test/contract.mjs
源代码
# lodash-es mergeWith Behavior
## Prior Network Results
A network search for `lodash-es` identified three existing samples:
- `sha256:34cdce816c4cd61633bf96402353c523980e492ac8b4d3769edb37f0a8a43e23` (`template` and `fromPairs` modular imports)
- `sha256:43f3bc2be8285279f7a9bb2036657d7f073481c0850139a3347863ae20766b3c` (nested path unset and prototype hardening)
- `sha256:a43406c2cb7a7a820569e638a3f025694c0eddfd843f544a9ade4a5f9b27c47d` (direct subpath ESM imports with explicit extensions)
This contract focuses on a distinct behavior: custom recursive merging with `mergeWith`.
## Pinned Version
- `lodash-es`: `4.17.21` (the current stable release of the 4.x major series).
## Observed Behavior
1. `mergeWith(object, ...sources, customizer)` recursively traverses own and inherited enumerable properties of source objects into the destination object.
2. The `customizer` function receives `(objValue, srcValue, key, object, source, stack)`.
3. When the customizer returns a non-`undefined` value (e.g. concatenating arrays via `objValue.concat(srcValue)`), that returned value is directly assigned to the target property, bypassing standard index-by-index array overwrite.
4. When the customizer returns `undefined`, merging falls back to default recursive object merging.
5. The destination object is mutated in-place and returned.
{"case":{"caseId":"case:sha256:1d6121c68c32b07d4209fdf32f7a5d4b2b6b5689e543b9f328a7a752dd64fd6b","contract":["mergeWith recursively merges own and inherited enumerable properties into the destination object, invoking customizer to override merging when it returns a non-undefined value","When the customizer returns a non-undefined value such as concatenated arrays, that value is assigned directly without index-by-index overwriting","When the customizer returns undefined, merging falls back to default recursive object merge behavior","The destination object is mutated in-place and returned as the result"],"goal":"Merge objects and customize array combining or property overrides using mergeWith in lodash-es","kind":"HOW","packages":["pkg:npm/lodash-es@4.17.21"],"schemaVersion":1,"symbols":["mergeWith"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","ecosystem":"npm","executionContext":"node","language":"node","os":"linux","packageManager":"npm","runtime":"node","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/lodash-es@4.17.21"],"schemaVersion":1,"symbols":["mergeWith"],"verifierAdapter":"node-typescript@1"}
{
"name": "npm-lodash-es-version-depth",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "npm-lodash-es-version-depth",
"version": "1.0.0",
"license": "ISC",
"dependencies": {
"lodash-es": "4.17.21"
}
},
"node_modules/lodash-es": {
"version": "4.17.21",
"resolved": "https://registry.npmjs.org/lodash-es/-/lodash-es-4.17.21.tgz",
"integrity": "sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw==",
"license": "MIT"
}
}
}
{
"name": "npm-lodash-es-version-depth",
"version": "1.0.0",
"type": "module",
"scripts": {
"test": "node test/contract.mjs"
},
"dependencies": {
"lodash-es": "4.17.21"
}
}
import assert from 'node:assert/strict';
import { mergeWith } from 'lodash-es';
// 1. Customizer returning a value overrides default merging (e.g. array concatenation)
const targetA = { tags: ['admin', 'staff'], meta: { depth: 1 } };
const sourceA = { tags: ['editor'], meta: { active: true } };
const resultA = mergeWith(targetA, sourceA, (objValue, srcValue) => {
if (Array.isArray(objValue)) {
return objValue.concat(srcValue);
}
});
assert.deepStrictEqual(resultA.tags, ['admin', 'staff', 'editor']);
assert.deepStrictEqual(resultA.meta, { depth: 1, active: true });
assert.strictEqual(resultA, targetA);
// 2. Customizer returning undefined falls back to default recursive merge
const targetB = { settings: { retries: 3, timeout: 5000 } };
const sourceB = { settings: { timeout: 10000, debug: true } };
const resultB = mergeWith(targetB, sourceB, () => undefined);
assert.deepStrictEqual(resultB.settings, { retries: 3, timeout: 10000, debug: true });
// 3. Customizer receives key and source objects for conditional merges
const targetC = { count: 10, label: 'old' };
const sourceC = { count: 5, label: 'new' };
const resultC = mergeWith(targetC, sourceC, (objValue, srcValue, key) => {
if (key === 'count') {
return objValue + srcValue;
}
});
assert.strictEqual(resultC.count, 15);
assert.strictEqual(resultC.label, 'new');