JSLab feature notes: one docs page, explained. Today: The jslab CLI.
JSLab is a JavaScript & TypeScript scratchpad for macOS, which makes it a GUI app. But a lot of the code you want to try starts in a terminal: a file in a repo, the output of another command, a one-liner. jslab is a small command-line tool that gets it into a tab.
Install it
Choose Help → Install jslab Command…. JSLab links its own binary into ~/.local/bin/jslab. If that folder isn't on your PATH, the message gives you the line to add to your shell profile:
export PATH="$HOME/.local/bin:$PATH" Once it's installed, the same menu item reads Uninstall jslab Command….
Open files
jslab notes.ts Each file opens in a new tab. The tab's language comes from the extension, or from your settings.
Pipe code in, and run it
- reads code from stdin. --run runs it as soon as it opens:
echo 'console.log(new Date())' | jslab --run - Without --run, the code only opens. For -, the tab's working directory defaults to your terminal's current folder, so relative paths in the piped code resolve where you are.
The options
jslab [file ...] Open files in new tabs jslab - Read code from stdin into a new tab jslab --run [file|-] Open and run immediately --runtime bun|browser|browser-node --lang ts|js|tsx|jsx --cwd <dir> --title <title> jslab --version | --help browser-node is the Browser & Node APIs runtime. So opening a component in a browser tab, in the current folder, is:
jslab --runtime browser --cwd . app.tsx Two I use
# Last week's version of a file, in its own tab git show HEAD~5:src/format.ts | jslab --lang ts - # Try a snippet you just copied from a README pbpaste | jslab --run - Code from stdin has no file extension, so pass --lang when it's TypeScript. pbpaste prints the macOS clipboard, so the second line runs whatever you copied. Read it before you pipe it.
How it works
If JSLab isn't running, jslab starts it and waits up to 10 seconds for it to be ready. Each call then sends one request over a local socket, jslab.sock, in JSLab's data folder.
JSLab launches Nov 15. The full page: https://js-lab.app/docs/reference/cli