Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/niksy/babel-plugin-transform-globalthis
Babel plugin for transforming `globalThis`.
https://github.com/niksy/babel-plugin-transform-globalthis
Last synced: about 2 months ago
JSON representation
Babel plugin for transforming `globalThis`.
- Host: GitHub
- URL: https://github.com/niksy/babel-plugin-transform-globalthis
- Owner: niksy
- License: mit
- Created: 2020-12-13T16:12:33.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2021-05-26T11:29:00.000Z (over 3 years ago)
- Last Synced: 2024-10-18T04:05:06.156Z (2 months ago)
- Language: JavaScript
- Size: 10.7 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# babel-plugin-transform-globalthis
[![Build Status][ci-img]][ci]
Babel plugin for transforming
[`globalThis`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis).## Install
```sh
npm install babel-plugin-transform-globalthis --save-dev
```## Usage
Use it via available [plugin activation options][babel-plugins].
For `.babelrc` file:
```json
{
"plugins": ["babel-plugin-transform-globalthis"]
}
```Then, in your code:
```js
/* Before */globalThis.becky;
/* After */
// Ommited for simplicity - here goes `globalThis` ponyfill
var _globalThis = {};_globalThis.becky;
```Check test fixtures ([actual](test/fixtures/all.js) and
[expected](test/fixtures/all.expected.js)) for more examples.## Acknowledgments
- [A horrifying `globalThis` polyfill in universal JavaScript](https://mathiasbynens.be/notes/globalthis)
by [@mathias](https://twitter.com/mathias)
- [`@ungap/global-this`](https://github.com/ungap/global-this) by
[@WebReflection](https://twitter.com/WebReflection)## License
MIT © [Ivan Nikolić](http://ivannikolic.com)
[ci]: https://travis-ci.com/niksy/babel-plugin-transform-globalthis
[ci-img]: https://travis-ci.com/niksy/babel-plugin-transform-globalthis.svg?branch=master
[babel-plugins]: http://babeljs.io/docs/plugins/