or run

npx @tessl/cli init
Log in

Version

Files

tile.json

task.mdevals/scenario-6/

Configuration Sanitizer

Build a configuration file sanitizer that processes application settings by removing unset values while preserving explicitly null values. The sanitizer should convert between JavaScript objects and XML format while maintaining the semantic distinction between missing values and intentionally null values.

Requirements

Your implementation should:

  1. Accept a JavaScript object containing configuration settings where properties can be strings, numbers, booleans, null, or undefined
  2. Build an XML representation that:
    • Omits properties with undefined values entirely
    • Preserves properties with null values explicitly
  3. Parse XML back into JavaScript objects, correctly distinguishing between:
    • Properties that were explicitly set to null
    • Properties with empty values

Test Cases

  • Building {name: "app", version: undefined} produces XML without a version property @test
  • Building {name: "app", version: null} produces XML with an explicit null element for version @test
  • Building {host: "localhost", port: undefined, timeout: null} correctly omits port and preserves timeout as null @test
  • Parsing XML containing a null element returns an object with that property set to null @test

Implementation

@generates

API

/**
 * Sanitizes a configuration object by converting it to XML format.
 * Undefined values are omitted, null values are explicitly marked.
 *
 * @param {Object} config - Configuration object to sanitize
 * @returns {string} XML representation of the configuration
 */
function sanitize(config) {
  // IMPLEMENTATION HERE
}

/**
 * Restores a configuration object from its XML representation.
 * Null markers are converted to null, missing values become empty strings.
 *
 * @param {string} xml - XML string to parse
 * @returns {Object} Configuration object
 */
function restore(xml) {
  // IMPLEMENTATION HERE
}

module.exports = {
  sanitize,
  restore
};

Dependencies { .dependencies }

plist { .dependency }

Provides XML property list parsing and building with proper null/undefined semantics.

@satisfied-by