Options
All
  • Public
  • Public/Protected
  • All
Menu

Module storage/conversion/ConversionUtil

Index

Functions

cleanPreferences

  • Cleans incoming preferences to prevent unwanted behaviour. Makes sure internal types have weight 0, unless specifically requested in the preferences, and interprets empty preferences as accepting everything.

    Parameters

    Returns ValuePreferences

    A copy of the the preferences with the necessary updates.

getBestPreference

getConversionTarget

  • For a media type converter that can generate the given types, this function tries to find the type that best matches the given preferences.

    This function combines several other conversion utility functions to determine what output a converter should generate: it cleans the preferences with cleanPreferences to support empty preferences and to prevent the accidental generation of internal types, after which the best match gets found based on the weights.

    Parameters

    Returns string | undefined

    The best match. Undefined if there is no match.

getTypeWeight

  • Tries to match the given type to the given preferences. In case there are multiple matches the most specific one will be chosen as per RFC 7231.

    Parameters

    • type: string

      Type for which the matching weight is needed.

    • preferred: ValuePreferences

      Preferences to match the type to.

    Returns number

    The corresponding weight from the preferences or 0 if there is no match.

getWeightedPreferences

isInternalContentType

  • isInternalContentType(contentType?: string): boolean
  • Checks if the given content type is an internal content type such as internal/quads. Response will be false if the input type is undefined.

    Do not use this for media ranges.

    Parameters

    • Optional contentType: string

      Type to check.

    Returns boolean

matchesMediaPreferences

matchesMediaType

  • matchesMediaType(mediaA: string, mediaB: string): boolean
  • Checks if the given two media types/ranges match each other. Takes wildcards into account.

    Parameters

    • mediaA: string

      Media type to match.

    • mediaB: string

      Media type to match.

    Returns boolean

    True if the media type patterns can match each other.