Security News
JavaScript Leaders Demand Oracle Release the JavaScript Trademark
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
@astrojs/webapi
Advanced tools
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.
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)
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+',
})
Shorthand | Excludes |
---|---|
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 |
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.
FAQs
Use Web APIs in Node
We found that @astrojs/webapi demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
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.
Security News
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.