powerlet-js
v1.0.0
Published
## Motivation
Downloads
3
Readme
powerlet-js
Motivation
Write like this:
let x!: string;
{
const now = new Date();
now.toISOString();
}
Not this:
const x = (() => {
const now = new Date();
return now.toISOString();
})();
Description
No more IIFE, no syntax sugar, no magic, no runtime overhead.
It just find the first block statement after the variable declaration, and replace the last expression in the block with the assignment to the variable.
For example, the code above will be transformed to:
let x!: string;
{
const now = new Date();
x = now.toISOString();
}
let x;
{
const now = new Date();
x = now.toISOString();
}
Installation
npm install powerlet-js
Usage
In your babel.config.json
:
{
"plugins": ["powerlet-js"]
}
Or you can use it with unplugin, for example, use in Vite:
import { defineConfig } from 'vite';
import powerlet from 'powerlet/vite';
export default defineConfig({
plugins: [
powerlet()
]
});