@offirmo/globalthis-ponyfill
TypeScript icon, indicating that this package has built-in type declarations

4.0.0 • Public • Published

globalThis ponyfill
Offirmo’s quality seal

npm badge dependencies badge bundle size badge license badge maintenance status badge

This is a trivial TypeScript-compatible globalThis ponyfill.

  • very small minzipped size
  • NO dependencies
  • doesn't alter the environment (ponyfill)
  • compatible with node & browser

Usage

import { getGlobalThis } from '@offirmo/globalthis-ponyfill'

// typed access
declare global {
	var foo: number
}
const globalThis = getGlobalThis()
globalThis.foo = 42

// untyped access
const globalThis = getGlobalThis<any>()
globalThis.bar = 42

Rationale

Credits

YES I had a look at ljharb/globalThis 's implementation (MIT) and started my implementation from it! Thanks a lot and all credits due!

About the proposed implementation here: https://mathiasbynens.be/notes/globalthis we can't use it: it creates a polyfill, not a ponyfill. However I took a line from the "naive implementation".

Dependencies (0)

    Dev Dependencies (5)

    Package Sidebar

    Install

    npm i @offirmo/globalthis-ponyfill

    Weekly Downloads

    5

    Version

    4.0.0

    License

    Unlicense

    Unpacked Size

    18.5 kB

    Total Files

    20

    Last publish

    Collaborators

    • offirmo