Herb JavaScript Bindings | Herb
Herb provides official JavaScript bindings as NPM packages, published under the @herb-tools organization. These packages are available for installation via npmjs.org using any package manager of your choice.
Herb supports both browser and Node.js environments with separate packages, ensuring optimized compatibility for each platform.
Installation
Browser usage
Installing the NPM Package
To use Herb in a browser environment, install the @herb-tools/browser package:
shell
npm add @herb-tools/browsershell
pnpm add @herb-tools/browsershell
yarn add @herb-tools/browsershell
bun add @herb-tools/browserImporting in Your Project
Import the Herb object into your project:
js
import { Herb } from "@herb-tools/browser"
await Herb.load()
Herb.parse("content")js
import { Herb } from "@herb-tools/browser"
Herb.load().then(() => {
Herb.parse("content")
})You are now ready to parse HTML+ERB in the browser using JavaScript.
Node.js usage
Installing the NPM Package
To use Herb in a Node.js environment, install the @herb-tools/node package:
shell
npm add @herb-tools/nodeshell
pnpm add @herb-tools/nodeshell
yarn add @herb-tools/nodeshell
bun add @herb-tools/nodeImporting in Your Project
Import the Herb object into your project:
js
import { Herb } from "@herb-tools/node"
await Herb.load()
Herb.parse("content")js
import { Herb } from "@herb-tools/node"
Herb.load().then(() => {
Herb.parse("content")
})You are now ready to parse HTML+ERB in Node.js.
Using Unreleased Commits
Each commit on the main branch and pull requests with approved reviews are published to pkg.pr.new. You can install preview packages directly from commits or PRs:
shell
npm i https://pkg.pr.new/@herb-tools/core@{commit}shell
pnpm add https://pkg.pr.new/@herb-tools/core@{commit}shell
yarn add https://pkg.pr.new/@herb-tools/core@{commit}shell
bun add https://pkg.pr.new/@herb-tools/core@{commit}Replace {commit} with the short commit SHA (e.g., 0d2eabe) or branch name (e.g., main).
Running CLI Tools from Previews
You can also run CLI tools directly from preview releases without installing:
shell
npx https://pkg.pr.new/@herb-tools/linter@{commit} template.html.erbshell
npx https://pkg.pr.new/@herb-tools/formatter@{commit} template.html.erbshell
npx https://pkg.pr.new/@herb-tools/language-server@{commit} --stdioThis is perfect for testing bug fixes or new features before they're officially released!
Getting Started
Regardless of whether you imported Herb from @herb-tools/browser or @herb-tools/node, the API remains the same for both packages.