or run

tessl search
Log in

Version

Files

tile.json

task.mdevals/scenario-10/

Configuration Merger

Build a utility function that merges multiple configuration objects with varying availability into a single cohesive configuration. The system should handle cases where some configuration sources might be unavailable or undefined while preserving valid configuration data.

Requirements

Your task is to implement a configuration merger that:

  1. Accepts multiple configuration objects as arguments
  2. Merges all provided configuration objects into a single unified configuration
  3. Gracefully handles missing or undefined configuration sources
  4. Returns a single merged configuration object containing all valid settings
  5. Preserves deeply nested configuration properties across all sources

The merger should be resilient to sparse inputs (where some configuration sources may be undefined or null) and ensure that only valid configuration data is included in the final result.

Example Scenarios

  • When merging configurations where some sources are undefined, only defined sources should contribute to the result
  • Nested configuration properties should be preserved and combined from all available sources
  • The order of configuration sources matters: later sources should override earlier ones for conflicting properties
  • Empty configuration objects are valid and should be handled appropriately

Test Cases

  • Merging an empty target with undefined, a defined config { api: { key: 'test' } }, undefined, and another config { api: { timeout: 5000 } } produces { api: { key: 'test', timeout: 5000 } } @test
  • Merging configs where first source is undefined, second is { server: { port: 3000 } }, third is undefined results in { server: { port: 3000 } } @test
  • Merging three configs { db: { host: 'localhost' } }, undefined, and { db: { port: 5432 } } produces { db: { host: 'localhost', port: 5432 } } @test

Implementation

@generates

API

/**
 * Merges multiple configuration objects into a single configuration.
 * Handles undefined or null configuration sources gracefully.
 *
 * @param {...Object} configs - Configuration objects to merge
 * @returns {Object} The merged configuration object
 */
function mergeConfigs(...configs) {
  // Implementation here
}

module.exports = { mergeConfigs };

Dependencies { .dependencies }

mixin-deep { .dependency }

Provides deep object merging functionality.