UNPKG

num-beauty

Version:

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

1 lines 1.82 kB
import{registerLocale,hasLocale,getLocale,getRegisteredLocales}from"./locales/index.js";import{round}from"./services/rounding.service.js";import{applyMask,getMask}from"./services/mask.service.js";import{abbreviateNumber}from"./services/abbreviation.service.js";import{formatNumber}from"./services/formatting.service.js";import{formatCurrency}from"./services/currency.service.js";import{formatPercentage}from"./services/percentage.service.js";import{Num,num}from"./fluent.js";import{toAccessibleString}from"./services/accessibility.service.js";import{unbeautify}from"./services/parsing.service.js";import{beautifyToParts}from"./services/parts.service.js";import{generateSmartTicks}from"./services/charts.service.js";import{formatTabular}from"./services/tabular.service.js";import{getChartJsCallback,getRechartsFormatter}from"./services/adapters.service.js";import{formatBytes as formatBytesFn}from"./services/units.service.js";import{formatDuration as formatDurationFn}from"./services/duration.service.js";export*from"./services/units.service.js";export*from"./services/duration.service.js";export function beautify(e,r={}){const{locale:s="en-US",decimals:t=2,abbreviated:a=!1,stripZeros:i=!1,roundingMode:o="HALF_UP",mask:c,currency:m}=r;if(m)return formatCurrency(e,s,{currency:m,decimals:t,stripZeros:i});if(c){let r;return r=c.includes("#")?c:getMask(s,c)||c,applyMask("bigint"==typeof e?Number(e):e,r)}const n=round(e,t,o),f=formatNumber(n,t,s,i);return a?abbreviateNumber(e,f,s):f}export{round,applyMask,formatNumber,registerLocale,hasLocale,getLocale,getRegisteredLocales,abbreviateNumber,formatCurrency,toAccessibleString,unbeautify,formatPercentage,formatBytesFn as formatBytes,formatDurationFn as formatDuration,beautifyToParts,generateSmartTicks,formatTabular,getChartJsCallback,getRechartsFormatter,Num,num};