or run

tessl search
Log in

Version

Files

tile.json

task.mdevals/scenario-2/

Configuration Manager

Build a simple configuration file manager that stores and updates application settings in JSON format.

@generates

Requirements

Create a module that provides functionality to:

  1. Save configuration settings to a JSON file
  2. Handle different data types (strings, numbers, booleans, objects)
  3. Support overwriting existing configuration files
  4. Provide both synchronous and asynchronous save operations
  5. Handle encoding properly for text data

Your implementation should handle edge cases such as invalid data and file write errors appropriately.

API

/**
 * Saves configuration data to a file synchronously
 * @param {string} filePath - Path where the configuration file should be saved
 * @param {Object} config - Configuration object to save
 * @throws {Error} If config is not an object or if file write fails
 */
function saveConfigSync(filePath, config) {}

/**
 * Saves configuration data to a file asynchronously
 * @param {string} filePath - Path where the configuration file should be saved
 * @param {Object} config - Configuration object to save
 * @param {Function} callback - Callback function (err)
 */
function saveConfigAsync(filePath, config, callback) {}

module.exports = { saveConfigSync, saveConfigAsync };

Test Cases

  • Saving a simple configuration object with string and number values synchronously writes the correct JSON to the file @test
  • Saving a nested configuration object with multiple data types writes properly formatted JSON @test
  • Saving configuration asynchronously invokes the callback after the file is written @test
  • Attempting to save a non-object value (like a string or number) throws an error @test

Dependencies { .dependencies }

metro-memory-fs { .dependency }

Provides an in-memory filesystem implementation for writing and managing configuration files.