JSPM

cloudflare-workers-unfurl

0.0.8
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4273
  • Score
    100M100P100Q133603F
  • License MIT

Unfurl urls in cloudflare workers using HTMLRewriter

Package Exports

  • cloudflare-workers-unfurl
  • cloudflare-workers-unfurl/unfurl.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (cloudflare-workers-unfurl) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

cloudflare-workers-unfurl

A tiny utility to get basic information about a URL on Cloudflare Workers using the built-in HTMLRewriter API.

Usage

npm install cloudflare-workers-unfurl

There are two exports: unfurl and handleUnfurlRequest.

unfurl is the main function that does the work. It takes a URL and returns a promise that resolves to an object with the following properties:

  • title: The title of the page
  • description: The description of the page
  • image: The URL of the social image
  • favicon: The URL of the favicon
import { unfurl } from "cloudflare-workers-unfurl";

const result = await unfurl("https://example.com");

result.title; // 'Example Domain'

handleUnfurlRequest is a function that takes a Request object and returns a promise that resolves to a Response object. It uses unfurl to get the information about the URL in the url query parameter of the request and returns it as JSON.

import { AutoRouter } from "itty-router";
import { handleUnfurlRequest } from "cloudflare-workers-unfurl";

const router = AutoRouter();

router.get("/unfurl", handleUnfurlRequest);

export default router;

License

MIT