Team Ai
Apppublic

harshapitla/github-actions-analytics

sourceHugging Faceupdated 10mo agoView on Hugging Face
0likes
formatSI.js25 linesDownload Raw Back to utils
1function formatSI(v){2  if (v === null || v === undefined) return "";3  const n = Number(v);4  if (isNaN(n)) return String(v);5  const abs = Math.abs(n);6  if (abs >= 1e9) return (n/1e9).toFixed(1)+'B';7  if (abs >= 1e6) return (n/1e6).toFixed(1)+'M';8  if (abs >= 1e3) return (n/1e3).toFixed(1)+'k';9  return String(n);10}11 12export default formatSI;13export function formatNumberPrecise(v, digits=1){14  if (v === null || v === undefined) return "";15  const n = Number(v);16  if (!Number.isFinite(n)) return String(v);17  if (Math.abs(n) < 1000) return n.toFixed(0);18  return formatSI(n);19}20export function formatRating(v){21  const n = Number(v);22  if (!Number.isFinite(n)) return "";23  return n.toFixed(1);24}25