UNPKG

coffee-crypto-cli

Version:
27 lines (26 loc) 973 B
import chalk from 'chalk'; const ERROR = chalk.bold.red; const SUCCESS = chalk.bold.green; export const logError = (message) => { console.error(ERROR(message)); process.exit(1); }; export const logSuccess = (message) => { console.log(SUCCESS(message)); }; export const format = (price) => { const decimalPart = price.toString().split('.')[1]; // If the decimal part starts with 000, it's likely a meme coin // and we want to show more decimal places to avoid showing 0.00 const isMemeCoin = decimalPart && decimalPart.slice(0, 3) === '000'; return new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD', maximumFractionDigits: isMemeCoin ? 10 : 2 }).format(price); }; export const formatFileName = (coinName, fileExt) => { /* use unix timestamp, resolves conflict of same filenames */ const timestamp = new Date().valueOf(); return `${coinName.toLowerCase()}-${timestamp}.${fileExt}`; };