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
JavaScript
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
}