CLI Alerts

raw JSON →
2.0.0 verified Thu Apr 23 auth: no javascript

cli-alerts is a lightweight, cross-platform utility for Node.js command-line interfaces, designed to display formatted alerts with colored text and symbolic icons. It supports various alert types including success, info, warning, and error, ensuring consistent visual feedback across macOS, Linux, and Windows terminals. The current stable version is 2.0.0. While not following a strict time-based release cadence, the project maintains an active development status with periodic improvements and bug fixes. Its key differentiators include its simplicity, minimal dependencies, and direct focus on enhancing the user experience of CLI tools by providing clear, visually distinct messages without complex configurations, making it an excellent choice for developers looking to add immediate, actionable feedback to their scripts and applications.

error Error [ERR_REQUIRE_ESM]: require() of ES Module ... not supported
cause Attempting to `require()` an ESM-only module in a CommonJS context, or vice-versa, without proper configuration or transpilation.
fix
If your project is ESM, change const alert = require('cli-alerts'); to import alert from 'cli-alerts';. If your project is CommonJS, ensure cli-alerts itself is not an ESM-only package that's incompatible, or use a tool like ts-node or esm package for better interoperability.
error TypeError: alert is not a function
cause Incorrect import statement (e.g., named import `{ alert }` instead of default import `alert`), or attempting to call `alert` on a non-function.
fix
Verify your import statement matches the module's export style. For cli-alerts, in ESM, use import alert from 'cli-alerts'; (default import). In CommonJS, use const alert = require('cli-alerts');.
breaking The package moved to v2.0.0, indicating potential breaking changes according to semantic versioning. While specific details were not provided in the readily available documentation, users upgrading from v1.x should review the changelog for any API alterations.
fix Consult the project's official changelog (changelog.md within the repository) for a detailed list of breaking changes and migration steps before upgrading.
gotcha When using ESM in a Node.js project, ensure your `package.json` specifies `"type": "module"` or use `.mjs` file extensions. Mixing CommonJS `require()` with ESM `import` in the same file can lead to `ERR_REQUIRE_ESM` errors.
fix For ESM projects, use `import alert from 'cli-alerts';`. For CommonJS projects, stick to `const alert = require('cli-alerts');`. If you encounter `ERR_REQUIRE_ESM`, refactor your module imports to be consistent or ensure your environment supports interoperability (e.g., Node.js >=14 with appropriate flags or transpilation).
npm install cli-alerts
yarn add cli-alerts
pnpm add cli-alerts

Demonstrates how to import and use the 'alert' function for various message types with TypeScript.

import alert from 'cli-alerts';

type AlertOptions = {
  type: 'success' | 'info' | 'warning' | 'error';
  msg: string;
  name?: string;
};

const showAlert = (options: AlertOptions) => {
  alert(options);
};

// Example usage:
console.log('\n--- CLI Alerts Examples ---');
showAlert({ type: 'success', msg: 'Operation completed successfully!' });
showAlert({ type: 'info', msg: 'Checking for updates...' });
showAlert({ type: 'warning', msg: 'Configuration file missing, using defaults.', name: 'CONFIG' });
showAlert({ type: 'error', msg: 'Failed to connect to the server. Please try again.' });
console.log('--- End Examples ---\n');

// To run this: 
// 1. npm install cli-alerts
// 2. Save as 'app.ts'
// 3. npx ts-node app.ts