UNPKG

sc4

Version:

A command line utility for automating SimCity 4 modding tasks & modifying savegames

26 lines (25 loc) 789 B
// # hex-prompt.js import input from '@inquirer/input'; // # hex(opts) // Helper function for requesting a single hexadecimal number as input, with // validation. export async function hex(opts) { return +await input({ validate(input) { if (!input.startsWith('0x')) { return 'Please input a valid hexadecimal number (prefixed with 0x)'; } let nr = +input; if (Number.isNaN(nr)) { return 'Please input a valid hexadecimal number (prefixed with 0x)'; } return true; }, ...opts, default: typeof opts.default === 'number' ? stringify(opts.default) : undefined, }); } // # stringify(nr) function stringify(nr) { return `0x${nr.toString(16)}`; }