UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 1.59 kB
import{t as expectDefined}from"./expect-DkJCbmLj.mjs"; //!packages/normalization-core/src/format.ts const BYTE_SIZE_UNITS=[`byte`,`kilo`,`mega`,`giga`,`tera`];const BYTE_SIZE_STYLES={iec:{base:1024,labels:[`B`,`KiB`,`MiB`,`GiB`,`TiB`]},"legacy-binary":{base:1024,labels:[`B`,`KB`,`MB`,`GB`,`TB`]}};function bucketRelativeTimeMs(e){const t=Math.round(e/1e3);if(t<60)return{value:t,unit:`second`};const n=Math.round(e/6e4);if(n<60)return{value:n,unit:`minute`};const r=Math.round(e/36e5);return r<48?{value:r,unit:`hour`}:{value:Math.round(e/864e5),unit:`day`}}function formatByteSize(e,t){const{base:n,labels:r}=BYTE_SIZE_STYLES[t.style];const i=BYTE_SIZE_UNITS.indexOf(t.maxUnit);let a=0;let o=e;while(o>=n&&a<i){o/=n;a+=1}for(;;){const e=expectDefined(BYTE_SIZE_UNITS[a],`byte-size unit`);const s=expectDefined(r[a],`byte-size label`);const c=typeof t.fractionDigits===`function`?t.fractionDigits(o,e):t.fractionDigits;if(c===null)return`${o}${t.separator}${s}`;const l=t.floorUnits?.includes(e)?Math.floor(o*10**c)/10**c:o;if(a<i&&Number(l.toFixed(c))>=n){o/=n;a+=1;continue}return`${l.toFixed(c)}${t.separator}${s}`}}function formatCompactTokenCount(e,t={}){if(e<1e3)return String(Math.round(e));const trim=e=>t.trimTrailingZero?e.replace(/\.0$/,``):e;if(t.maxUnit===`billion`&&e>=1e9)return`${trim((e/1e9).toFixed(1))}B`;if(e<1e6){const n=(e/1e3).toFixed(t.thousandsPrecision??1);if(Number(n)<1e3)return`${trim(n)}${t.thousandsSuffix??`k`}`}return`${trim((e/1e6).toFixed(1))}${t.millionsSuffix??`m`}`}export{formatByteSize as n,formatCompactTokenCount as r,bucketRelativeTimeMs as t};