@alanscodelog/utils
    Preparing search index...

    Function readFromClipboard

    • Reads and automatically parses contents from the user's clipboard.

      This MUST be called from an event handler and it triggers a permission popup. If not called from an event handler or permission is denied it will throw a NotAllowedError.

      It will also throw if the navigator.keyboard API is not available or if any of the parsing fails.

      const result = await paste().catch(handleError)
      if (result[0].type === "json") console.log(result[0].data)
      if (result[0].type === "image") {
      const img = new Image()
      img.src = URL.createObjectURL(result.data)
      document.body.appendChild(img)
      }

      Returns Promise<
          (
              | { data: unknown[]
              | Record<string, unknown>; type: "json" }
              | { data: Blob; type: "image" }
              | { data: string; type: "text" }
              | { data: null; type: "unknown" }
          )[],
      >