Options
All
  • Public
  • Public/Protected
  • All
Menu

Module storage/conversion/ConversionUtil

Index

Functions

hasMatchingMediaTypes

  • hasMatchingMediaTypes(preferredTypes?: Record<string, number>, availableTypes?: Record<string, number>): boolean
  • Determines whether any available type satisfies the preferences.

    throws

    BadRequestHttpError If the type preferences are undefined or if there are duplicate preferences.

    Parameters

    • Optional preferredTypes: Record<string, number>

      Preferences for output type.

    • Optional availableTypes: Record<string, number>

      Media types to compare to the preferences.

    Returns boolean

    Whether there is at least one preference match.

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.

matchingMediaTypes

  • matchingMediaTypes(preferredTypes?: Record<string, number>, availableTypes?: Record<string, number>): string[]
  • Filters media types based on the given preferences. Based on RFC 7231 - Content negotiation. Will add a default internal/*;q=0 to the preferences to prevent accidental use of internal types. Since more specific media ranges override less specific ones, this will be ignored if there is a specific internal type preference.

    This should be called even if there are no preferredTypes since this also filters out internal types.

    throws

    BadRequestHttpError If the type preferences are undefined or if there are duplicate preferences.

    Parameters

    • preferredTypes: Record<string, number> = ...

      Preferences for output type.

    • availableTypes: Record<string, number> = ...

      Media types to compare to the preferences.

    Returns string[]

    The weighted and filtered list of matching types.

supportsMediaTypeConversion

  • supportsMediaTypeConversion(inputType?: string, outputTypes?: Record<string, number>, convertorIn?: Record<string, number>, convertorOut?: Record<string, number>): void
  • Determines whether the given conversion request is supported, given the available content type conversions:

    • Checks if there is a content type for the input.
    • Checks if the input type is supported by the parser.
    • Checks if the parser can produce one of the preferred output types. Throws an error with details if conversion is not possible.

    Parameters

    • inputType: string = 'unknown'

      Actual input type.

    • outputTypes: Record<string, number> = ...

      Acceptable output types.

    • convertorIn: Record<string, number> = ...

      Media types that can be parsed by the converter.

    • convertorOut: Record<string, number> = ...

      Media types that can be produced by the converter.

    Returns void