jj
    Preparing search index...

    Function fetchText

    • Fetches a file and returns its contents as string.

      Parameters

      • url: string | URL

        The file location.

      • mime: string = 'text/*'

        The HTTP Request Accept header. Defaults to 'text/*'.

      Returns Promise<string>

      The file contents as a string.

      This is a wrapper around the native fetch API that handles the response status check and text extraction. It sets the Accept header based on the provided mime type.

      const text = await fetchText('https://example.com/data.txt')
      

      If mime is not a string.

      If the fetch fails or the response status is not OK (200-299).