UNPKG

num-beauty

Version:

An ultra lightweight module for formatting numbers into human-friendly strings

1 lines 393 B
export function generateSmartTicks(t,e,o=10){if(t===e)return[t];const n=niceNum(e-t,!1),r=niceNum(n/(o-1),!0),c=Math.floor(t/r)*r,i=Math.ceil(e/r)*r,u=[],a=r/1e3;for(let t=c;t<=i+a;t+=r)u.push(Number(t.toPrecision(12)));return u}function niceNum(t,round){const e=Math.floor(Math.log10(t)),o=t/Math.pow(10,e);let n;return n=round?o<1.5?1:o<3?2:o<7?5:10:o<=1?1:o<=2?2:o<=5?5:10,n*Math.pow(10,e)}