You are implementing a single JavaScript function.
Write ONLY the function with its body. Keep it to 5-15 lines.
Use modern JS: const, arrow functions, async/await where appropriate.
Use require() for Node.js built-in modules if needed.
Do not call undefined helper functions — use only built-in or well-known npm modules.
Output ONLY the code in a single code fence. No explanations before or after.