@unikue/ts-lang-utils
    Preparing search index...

    Function formatBytes

    Utilities for file

    David Hsing

    • Formats the given bytes into a human-readable file size string

      Parameters

      • Optionalbytes: number | null

        the number of bytes to format (base-1024)

      • precision: number = 2

        the number of decimal places to keep (defaults to 2)

      Returns string | undefined

      the formatted size string, e.g. "1.5 KB" or "2.3 MB", or undefined if bytes is absent

      David Hsing

      formatBytes(0);               // "0 B"
      formatBytes(512); // "512 B"
      formatBytes(1536); // "1.5 KB"
      formatBytes(1048576); // "1 MB"
      formatBytes(1610612736); // "1.5 GB"
      formatBytes(1649267441664); // "1.5 TB"
      formatBytes(-1); // "0 B"
      formatBytes(Infinity); // "0 B"
      formatBytes(); // undefined
      formatBytes(undefined); // undefined
      formatBytes(null); // undefined