Packages
@edge-runtime/ponyfill

Edge Runtime Ponyfill

The @edge-runtime/ponyfill package helps to have the Edge Runtime APIs available in your environment:

  • When running on Edge Runtime, no polyfills will be loaded, and the native implementations will be used.
  • When running on Node.js runtimes, this package will load the polyfills from @edge-runtime/primitives.

Note this is just necessary if you want to run the same code across different environments.

Installation

npm install @edge-runtime/ponyfill

This package includes built-in TypeScript support.

Usage

Rather than use APIs from the global scope:

const data = new TextEncoder().encode('Hello, world')
const digest = await crypto.subtle.digest('SHA-256', content)

Load them from the package instead:

import { crypto, TextEncoder } from '@edge-runtime/ponyfill'
 
const data = new TextEncoder().encode('Hello, world')
const digest = await crypto.subtle.digest('SHA-256', content)

Any Edge Runtime API is available.