A Neovim plugin that provides an interactive JavaScript/TypeScript playground buffer. Perfect for quickly testing snippets of JS/TS code directly inside Neovim.
Install the plugin using your favorite package manager. Here's an example for lazy.nvim:
{
"barspielberg/jsplayground.nvim",
cmd = "JSPlayground",
opts = {},
}You can customize the plugin behavior by passing your own options. Below are the default settings:
{
file_name = "playground.js", -- The default file name for the playground
cmd = { "node" }, -- The command used to execute the code
console = {
screen_ratio = 0.25, -- Ratio of the buffer for console output
},
marks = {
inline_prefix = "// ", -- Prefix for inline marks
},
}If you prefer not to display a console output:
{
opts = {
console = false,
},
}To remove inline marks:
{
opts = {
marks = false,
},
}For TypeScript support, simply adjust the file name and command:
{
opts = {
file_name = "playground.ts",
cmd = { "npx", "ts-node" }, -- Uses ts-node for TypeScript execution
},
}To create a new JavaScript/TypeScript playground, run:
:JSPlayground
This command opens a buffer where you can write your code. Once you save the buffer, the code will automatically execute, and the results will be displayed.
To detach the execution listener from the buffer, run the command :JSPlayground again.
- bun support
- deno support
- console colors support
