UNPKG

customizable-toast-notification

Version:

A lightweight, zero-dependency toast notification library for modern JavaScript applications with production-grade reliability and comprehensive system mechanisms

67 lines (58 loc) β€’ 2.02 kB
try { if ( process.env.CI || process.env.NODE_ENV === "prod" || process.env.NODE_ENV === "production" ) { process.exit(0); } else { showMessage(5); } function showMessage(count) { const width = process.stdout.columns || 80; const boxWidth = 60; const spinnerFrames = ["|", "/", "-", "\\"]; let i = 0; const stripAnsi = (text) => text.replace(/\x1b\[[0-9;]*m/g, ""); const pad = (text) => " ".repeat(Math.max(boxWidth - stripAnsi(text).length, 0)); const center = (text) => " ".repeat( Math.max(Math.floor((width - stripAnsi(text).length) / 2), 0) ) + text; const lines = [ count === 5 ? "🎯Thanks for sticking with it!\nThis is the final message. πŸš€" : `πŸ“¦Thanks for using this package!`, "πŸ“˜ In README.md - More professional", "πŸ‘¨β€πŸ’» Author **Priyanshu Patel** -", "🀝 Open to collaboration & teamwork", "πŸ’Ό Looking for exciting dev opportunities.", "πŸ”— Contact: priyanshu.alt191@gmail.com", "πŸš€ Built different. Stay creative.", ]; const spinner = setInterval(() => { process.stdout.write( `\r⏳ Finalizing install ${spinnerFrames[i++ % spinnerFrames.length]} ` ); }, 100); setTimeout(() => { clearInterval(spinner); process.stdout.write("\r".padEnd(40, " ") + "\r"); // Clear spinner line console.log( "\n" + center(`\x1b[36m\x1b[1mβ•”${"═".repeat(boxWidth)}β•—\x1b[0m`) ); lines.forEach((line) => { line.split("\n").forEach((sub) => { console.log( center(`\x1b[36mβ•‘ \x1b[0m${sub}${pad(sub)}\x1b[36m β•‘\x1b[0m`) ); }); }); console.log(center(`\x1b[36mβ•š${"═".repeat(boxWidth)}╝\x1b[0m`) + "\n"); process.exit(0); // βœ… Exit only after message shown }, 300); } } catch (error) { process.exit(0); // Exit silently }