MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / unitConvert

Function unitConvert

speedtest/speedtest.ts:354–376  ·  view source on GitHub ↗
(
  bytes: number,
  isBytes: boolean = false
)

Source from the content-addressed store, hash-verified

352 let value = bytes;
353 let unitIndex = 0;
354
355 const units = isBytes
356 ? ["B", "KB", "MB", "GB", "TB"]
357 : ["bps", "Kbps", "Mbps", "Gbps", "Tbps"];
358
359 if (!isBytes) {
360 value *= 8; // Convert bytes to bits
361 }
362
363 while (value >= power && unitIndex < units.length - 1) {
364 value /= power;
365 unitIndex++;
366 }
367
368 return `${Math.round(value * 100) / 100}${units[unitIndex]}`;
369}
370
371async function getIpApi(ip: string): Promise<{
372 asInfo: string;
373 ccName: string;
374 ccCode: string;
375 ccFlag: string;
376 ccLink: string;
377}> {
378 try {
379 const response = await axios.get(

Callers 1

speedtestFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected