Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@astrojs/webapi

Package Overview
Dependencies
Maintainers
4
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@astrojs/webapi

Use Web APIs in Node

  • 0.0.0-cloudcannon-fix-20230306211609
  • next--cloudcannon-fix
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
17K
decreased by-51.03%
Maintainers
4
Weekly downloads
 
Created
Source

WebAPI

WebAPI lets you use Web APIs not present in Node v16 and later.

npm install @astrojs/webapi
import { polyfill } from '@astrojs/webapi'

polyfill(globalThis)

const t = new EventTarget()
const e = new CustomEvent('hello')

t.addEventListener('hello', console.log)

t.dispatchEvent(e) // logs `e` event from `t`

These APIs are combined from popular open source projects and configured to share implementation details. This allows their behavior to match browser expectations as well as reduce their combined memory footprint.

Features

Usage

You can use WebAPIs as individual exports.

import { Event, EventTarget, File, fetch, Response } from '@astrojs/webapi'

You can apply WebAPIs to an object, like globalThis.

import { polyfill } from '@astrojs/webapi'

polyfill(globalThis)

Polyfill Options

The exclude option receives a list of WebAPIs to exclude from polyfilling.

polyfill(globalThis, {
	// disables polyfills for setTimeout clearTimeout
	exclude: 'setTimeout clearTimeout',
})

The exclude option accepts shorthands to exclude multiple polyfills. These shorthands end with the plus sign (+).

polyfill(globalThis, {
	// disables polyfills for setTimeout clearTimeout
	exclude: 'Timeout+',
})
polyfill(globalThis, {
	// disables polyfills for Node, Window, Document, HTMLElement, etc.
	exclude: 'Node+',
})
polyfill(globalThis, {
	// disables polyfills for Event, EventTarget, Node, Window, Document, HTMLElement, etc.
	exclude: 'Event+',
})
ShorthandExcludes
Document+Document, HTMLDocument
Element+Element, and exclusions from HTMLElement+
Event+Event, CustomEvent, EventTarget, MediaQueryList, Window, and exclusions from Node+
EventTarget+Event, CustomEvent, EventTarget, MediaQueryList, Window, and exclusions from Node+
HTMLElement+CustomElementsRegistry, HTMLElement, HTMLBodyElement, HTMLCanvasElement, HTMLDivElement, HTMLHeadElement, HTMLHtmlElement, HTMLImageElement, HTMLStyleElement, HTMLTemplateElement, HTMLUnknownElement, Image
Node+Node, DocumentFragment, ShadowRoot, Document, HTMLDocument, and exclusions from Element+
StyleSheet+StyleSheet, CSSStyleSheet

License & Attribution

Thank you to Jon Neal for his work on the original webapi project that this package is forked from. Licensed under the CC0-1.0 License.

Code from event-target-shim is licensed under the MIT License (MIT), Copyright Toru Nagashima.

Keywords

FAQs

Package last updated on 06 Mar 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc