2024-09-23 21:44:43 +02:00
|
|
|
import { Address4, Address6 } from "ip-address"
|
|
|
|
|
|
|
|
|
|
export function ipToBigInt(ip) {
|
|
|
|
|
// Check if it's an IPv4 address
|
|
|
|
|
if (ip.includes(".")) {
|
|
|
|
|
const addr = new Address4(ip)
|
2025-10-12 15:20:38 +02:00
|
|
|
return addr.bigInt()
|
2024-09-23 21:44:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Otherwise, assume it's an IPv6 address
|
|
|
|
|
const addr = new Address6(ip)
|
2025-10-12 15:20:38 +02:00
|
|
|
return addr.bigInt()
|
2024-09-23 21:44:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function humanFileSize(size) {
|
|
|
|
|
const sizes = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]
|
|
|
|
|
if (size === 0) return "0B"
|
|
|
|
|
const i = parseInt(Math.floor(Math.log(size) / Math.log(1024)))
|
|
|
|
|
return Math.round(size / Math.pow(1024, i), 2) + sizes[i]
|
|
|
|
|
}
|