@prompt-or-die/core
v1.0.0
Published
A utility package for prompting users with critical decisions - exit on denial
Downloads
3
Maintainers
Readme
@prompt-or-die/core
A utility package for prompting users with critical decisions. If the user doesn't confirm with the expected input, the process exits immediately.
Perfect for deployment scripts, database migrations, file deletions, and other critical operations where user confirmation is mandatory.
Installation
npm install @prompt-or-die/coreQuick Start
const { promptOrDie } = require('@prompt-or-die/core');
// Basic usage - exits if user doesn't type "yes"
promptOrDie('Are you sure you want to delete all files?');
// Custom confirmation text
promptOrDie('Type "DELETE" to proceed with deletion', 'DELETE');
// With callback for post-confirmation actions
promptOrDie('Continue with deployment?', 'yes', () => {
console.log('Starting deployment...');
// Your critical code here
});API Reference
promptOrDie(message, confirmText, callback)
Prompts the user and exits the process if they don't provide exact confirmation.
- message (string): The message to display to the user
- confirmText (string, optional): The text user must type to confirm (default: 'yes')
- callback (function, optional): Function to execute after confirmation
Example:
promptOrDie('Delete production database?', 'CONFIRM DELETE', () => {
// This only runs if user types "CONFIRM DELETE"
deleteDatabase();
});confirm(message, confirmText)
Promise-based version that resolves on confirmation or exits on denial.
- message (string): The message to display to the user
- confirmText (string, optional): The text user must type to confirm (default: 'yes')
- Returns: Promise - Always resolves to true (exits process if false)
Example:
async function deploy() {
await confirm('Deploy to production?');
console.log('Deploying...');
// Deployment code here
}promptOrDieSync(message, confirmText)
Synchronous version (requires readline-sync as dependency).
- message (string): The message to display to the user
- confirmText (string, optional): The text user must type to confirm (default: 'yes')
Example:
// Install readline-sync first: npm install readline-sync
promptOrDieSync('Proceed with migration?');
console.log('User confirmed, continuing...');Use Cases
- 🚀 Deployment confirmations - Prevent accidental production deployments
- 🗄️ Database migrations - Ensure critical schema changes are intentional
- 🗑️ File deletions - Confirm before removing important files
- 🔄 Environment switches - Verify before switching to production
- ⚠️ Critical operations - Any irreversible action requiring explicit consent
Behavior
- ✅ Confirmed: If user types the exact confirmation text (case-insensitive), execution continues
- ❌ Denied: If user types anything else, presses Enter without input, or provides wrong text, the process exits with code 1
Why Use This?
Traditional prompts often accept "y", "Y", "yes", or just Enter. This can lead to accidental confirmations. @prompt-or-die/core requires exact text matches, making accidental confirmations nearly impossible.
Security Note
This package is designed for interactive scripts and should not be used in production servers or automated environments where user input isn't available.
Contributing
Issues and pull requests are welcome! Visit our GitHub repository.
License
ISC License - see LICENSE file for details.
⚠️ Remember: This package will exit your process immediately if the user doesn't confirm. Use it wisely!
