or run

npx @tessl/cli init
Log in

Version

Files

tile.json

task.mdevals/scenario-3/

Configuration File Validator

Build a utility that validates configuration data stored in Apple's property list (plist) format, with specific focus on ensuring numeric configuration values are correctly typed as integers.

Requirements

Your utility should provide two main functions:

  1. Parse and validate a plist XML string containing configuration data
  2. Generate a plist XML string from a JavaScript configuration object

The utility must correctly handle integer values throughout the parsing and generation process. Configuration values that are whole numbers should be preserved as integers, not floating-point numbers.

Functionality

Parsing Configuration

When parsing a plist XML configuration file, your utility should:

  • Convert the XML string into a JavaScript object
  • Ensure integer values in the XML are correctly parsed as JavaScript numbers
  • Return the parsed configuration object

Generating Configuration

When generating a plist XML file from a configuration object, your utility should:

  • Convert a JavaScript object into plist XML format
  • Automatically detect whole numbers and represent them as integer elements in the XML
  • Distinguish between whole numbers (integers) and decimal numbers (reals)
  • Return the formatted XML string

Test Cases

  • Given a plist XML string containing an integer value <integer>42</integer>, parsing it returns the number 42 @test
  • Given a JavaScript object {port: 8080}, generating plist XML produces an integer element <integer>8080</integer> @test
  • Given a JavaScript object with both whole and decimal numbers {count: 5, ratio: 3.14}, the generated XML uses <integer>5</integer> for the whole number and <real>3.14</real> for the decimal @test

@generates

API

/**
 * Parses a plist XML string and returns the configuration as a JavaScript object.
 *
 * @param {string} xmlString - The plist XML string to parse
 * @returns {Object} The parsed configuration object
 */
function parseConfig(xmlString) {
  // IMPLEMENTATION HERE
}

/**
 * Generates a plist XML string from a configuration object.
 *
 * @param {Object} config - The configuration object to convert
 * @returns {string} The plist XML string
 */
function generateConfig(config) {
  // IMPLEMENTATION HERE
}

module.exports = {
  parseConfig,
  generateConfig
};

Dependencies { .dependencies }

plist { .dependency }

Provides Apple property list parsing and building support.