{"library":"rdotjson","title":"Android String Resource XML Parser","description":"rdotjson is a Node.js library dedicated to parsing Android String Resource XML files (e.g., `strings.xml`) into a structured JavaScript object. It mirrors Android's `R` class access patterns, organizing resources under keys like `R.string`, `R.array`, `R.bool`, `R.color`, `R.dimen`, and `R.integer`. The library supports conversion of these resources into native JavaScript primitives or an object-wrapped format via `objectMode`. The current stable version is 2.0.0, and it maintains an active release cadence, as indicated by ongoing GitHub activity. Its key differentiators include extensive configuration options for handling XML comments, excluding specific keys with wildcards, preserving raw XML, and offering integrated formatters for JSON and CSV output. A robust command-line interface is also provided for direct file processing, making it suitable for build pipelines. It is designed for Node.js environments running version 18.17 or newer.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install rdotjson"],"cli":{"name":"rdotjson","version":null}},"imports":["import rdotjson from 'rdotjson';","const rdotjson = require('rdotjson');","import rdotjson from 'rdotjson'; const jsonFormatter = rdotjson.format('json');"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { promises as fs } from \"fs\";\nimport rdotjson from \"rdotjson\";\nimport path from 'path';\n\n// Create a dummy strings.xml for demonstration\nconst xmlContent = `\n<resources>\n    <string name=\"app_name\">MyAwesomeApp</string>\n    <string name=\"action_settings\">Settings</string>\n    <bool name=\"feature_enabled\">true</bool>\n    <integer name=\"max_items\">10</integer>\n    <string-array name=\"planets\">\n        <item>Mercury</item>\n        <item>Venus</item>\n        <item>Earth</item>\n    </string-array>\n</resources>\n`;\nconst xmlPath = path.join(process.cwd(), 'strings.xml');\nawait fs.writeFile(xmlPath, xmlContent);\n\nasync function parseAndroidResources() {\n  try {\n    const xml = await fs.readFile(xmlPath, 'utf8');\n    const R = await rdotjson(xml, { comment: 'pre' });\n\n    console.log(`App Name: ${R.string.app_name}`); // Expected: MyAwesomeApp\n    console.log(`Feature Enabled: ${R.bool.feature_enabled}`); // Expected: true\n    console.log(`Max Items: ${R.integer.max_items}`); // Expected: 10\n    console.log(`First Planet: ${R.array.planets[0]}`); // Expected: Mercury\n\n    const jsonFormatter = rdotjson.format('json');\n    const jsonOutput = jsonFormatter(R, { space: 2 });\n    console.log('\\nJSON Output:\\n', jsonOutput);\n  } catch (error) {\n    console.error('Error parsing resources:', error);\n  } finally {\n    // Clean up the dummy file\n    await fs.unlink(xmlPath);\n  }\n}\n\nparseAndroidResources();","lang":"javascript","description":"Demonstrates parsing an Android `strings.xml` file, accessing parsed values, and using the JSON formatter. Includes setup and teardown for a runnable example.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}