Options
All
  • Public
  • Public/Protected
  • All
Menu

A Bytes object represent an amount of bytes.

Hierarchy

  • Bytes

Index

Constructors

Methods

  • Returns a copy of this Bytes object having the specified amount added to its value.

    Parameters

    • bytes: string | number | Bytes

      value to add

    Returns Bytes

  • Converts the current bytes value to a given unit.

    Parameters

    Returns number

  • isValid(): boolean
  • Return whether or not the Bytes object is valid.

    Returns boolean

  • Returns a copy of this Bytes object having the specified amount subtracted from its value.

    Parameters

    • bytes: string | number | Bytes

      value to subtract

    Returns Bytes

  • Returns a string representation of the Bytes object using binary (i.e. IEC) units.

    Parameters

    Returns string

  • Returns a string representation of the Bytes object using a format specifier. Its verbs syntax is greatly inspired by C's printf.

    Verbs:

    %b   bytes
    %g   gigabytes
    %G   gibibytes
    %k   kilobytes
    %K   kibibytes
    %m   megabytes
    %M   mebibytes
    %p   petabytes
    %P   pebibytes
    %t   terabytes
    %T   tebibytes
    %v   decimal unit that best matches to the value (SI)
    %V   binary unit that best matches to the value (IEC)
    

    Width can be specified by a decimal number preceding the verb and the digits precision by another decimal number directly following the width, separated by a period. Both are optional and defaults will apply when omitted.

    Examples:

    %g      width: default   digits: default
    %4g     width: 4         digits: default
    %4.g    width: 4         digits: 0
    %4.2g   width: 4         digits: 2
    %.2g    width: default   digits: 2
    

    Extra modifiers are supported to alter the output format, they must precede the width and digits precision numbers.

    Modifiers:

    +   always print the numeric value sign
    !   use short form (no space, no suffix)
    

    Parameters

    Returns string

  • Returns a string representation of the Bytes object according to provided formatting options.

    Parameters

    Returns string

  • valueOf(): number
  • Returns the current bytes value.

    Returns number

  • fromBytes(value: number): Bytes
  • Create a new Bytes object from a numeric value.

    Parameters

    • value: number

      bytes value

    Returns Bytes

  • Create a new Bytes object from an input string.

    Parameters

    • text: string

      text to parse

    • Optional opts: ParseOpts

      parsing options

    Returns Bytes

  • isBytes(obj: unknown): obj is Bytes
  • Return whether or not the given object is a Bytes one.

    Parameters

    • obj: unknown

      object to inspect

    Returns obj is Bytes