CodeSampleX

Beispiel

lodash-es 4.17.21: Merge objects and customize array combining or property overrides using mergeWith in lodash-es

Verifiziertes Beispiel für npm lodash-es 4.17.21: Merge objects and customize array combining or property overrides using mergeWith in lodash-es. Der Vertrag…

sha256:a9ffa702fddae4b1487b97e85926f795971d9d4c385b4671cc63ceaa67fe9d41

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
3
Signaturschlüssel, die es gebaut haben
3
Deklarierte Umgebung node linux x64 node node npm

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
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

Fall

HOW
Ziel
Merge objects and customize array combining or property overrides using mergeWith in lodash-es
Pakete
Symbole
  • mergeWith
Umgebung
node
Erstellt
2026-08-17T17:42:27Z

Contract

  1. mergeWith recursively merges own and inherited enumerable properties into the destination object, invoking customizer to override merging when it returns a non-undefined value
  2. When the customizer returns a non-undefined value such as concatenated arrays, that value is assigned directly without index-by-index overwriting
  3. When the customizer returns undefined, merging falls back to default recursive object merge behavior
  4. The destination object is mutated in-place and returned as the result

Dateien

  • NOTES.md
  • csx.json
  • package-lock.json
  • package.json
  • test/contract.mjs

Quellartefakt herunterladen (tar.gz)

Quelltext

NOTES.md
# 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.
csx.json
{"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"}
package-lock.json
{
  "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"
    }
  }
}
package.json
{
  "name": "npm-lodash-es-version-depth",
  "version": "1.0.0",
  "type": "module",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "lodash-es": "4.17.21"
  }
}
test/contract.mjs
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');

Ursprungs-Seeder

csx-seed