UNPKG

num-beauty

Version:

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

1 lines 632 B
import{round}from"./services/rounding.service";import{applyMask,getMask}from"./services/mask.service";import{abbreviateNumber}from"./services/abbreviation.service";import{formatNumber}from"./services/formatting.service";import{formatCurrency}from"./services/currency.service";export function beautify(r,e={}){const{locale:i="en-US",decimals:o=2,abbreviated:a=!1,stripZeros:t=!1,roundingMode:s="HALF_UP",mask:m}=e;if(m){let e;return e=m.includes("#")?m:getMask(i,m)||m,applyMask(r,e)}const c=round(r,o,s),n=formatNumber(c,o,i,t);return a?abbreviateNumber(r,n,i):n}export{round,applyMask,formatNumber,abbreviateNumber,formatCurrency};