or run

tessl search
Log in

Version

Files

tile.json

task.mdevals/scenario-3/

Configuration Merger

A utility that intelligently merges configuration objects with support for various data types.

Overview

Build a configuration merger that combines multiple configuration sources into a single configuration object. The merger should handle different data types appropriately, preserving arrays, merging nested objects, and properly handling edge cases like null values and functions.

Capabilities

Merge nested objects

  • Merges two objects with nested properties: { server: { port: 8080 } } and { server: { host: 'localhost' } } produces { server: { port: 8080, host: 'localhost' } } @test
  • Merges three configuration objects with overlapping nested properties @test

Preserve arrays

  • When merging objects containing array properties, arrays are not merged but replaced: merging { items: [1, 2] } with { items: [3, 4] } produces { items: [3, 4] } @test
  • Array properties in nested objects are preserved without modification @test

Handle special types

  • Merging objects with null values: { config: { timeout: 5000 } } merged with { config: null } produces { config: null } @test
  • Merging objects containing function properties preserves the functions @test

Handle primitives

  • When a primitive value conflicts with an object, the primitive value wins: merging { value: { nested: true } } with { value: 'string' } produces { value: 'string' } @test
  • Last value wins for overlapping primitive properties @test

Implementation

@generates

API

/**
 * Merges multiple configuration objects into a single object.
 * The first object is modified in-place and returned.
 *
 * @param {Object} target - The target object that will receive merged properties
 * @param {...Object} sources - One or more source objects to merge
 * @returns {Object} The merged target object
 */
function mergeConfig(target, ...sources) {
  // IMPLEMENTATION HERE
}

module.exports = { mergeConfig };

Dependencies { .dependencies }

mixin-deep { .dependency }

Provides deep object merging capabilities.