Promptly is a focused Node.js utility for handling command-line input and user interaction. Currently stable at version 3.2.0, it provides a robust `prompt` function with extensive options for input validation, default values, silent input (e.g., for passwords), character replacement, and custom input/output streams. It supports retry logic for failed validations by default and offers timeout functionality. While the release cadence isn't explicitly stated in the provided documentation, its stable 3.x version and continued maintenance on GitHub suggest a steady, albeit perhaps slower, evolution. Its key differentiators lie in its comprehensive validation system with custom error messages and automatic retries, as well as fine-grained control over I/O streams and timeouts, making it suitable for building interactive CLI tools where user input quality is critical. It is primarily used in Node.js environments for CLI applications.
npm install promptlyVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates basic prompting, input validation with custom error messages, and silent input for sensitive information like passwords, utilizing async/await for clarity.
Set `retry: false` in the options object: `promptly.prompt('Message: ', { validator, retry: false })`.Wrap calls with `timeout` in a `try/catch` block to handle the `Error('timed out')`. Alternatively, set `useDefaultOnTimeout: true` to return the `default` value if a timeout occurs: `promptly.prompt('Message: ', { timeout: 3000, default: 'Guest', useDefaultOnTimeout: true })`.Ensure your validator function explicitly throws an `Error` instance or a string message when validation fails, e.g., `throw new Error('Validation failed');`.Handle the `Error('timed out')` within a `try/catch` block or set `useDefaultOnTimeout: true` in the options if a default value should be used instead of throwing an error.If `promptly` does not provide an official ESM export for direct `import`, you might need to use a dynamic `import()` or adjust your project to use CommonJS modules where `promptly` is needed. For `promptly`, stick to `const promptly = require('promptly');` in CommonJS contexts.The user input needs to satisfy the conditions of the validator. If `retry` is `true` (default), simply re-enter valid input. If `retry` is `false`, the error must be caught and handled in a `try/catch` block.
No dependency data recorded yet.