Herb JavaScript Bindings
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:
npm add @herb-tools/browserpnpm add @herb-tools/browseryarn add @herb-tools/browserbun add @herb-tools/browserImporting in Your Project
Import the Herb object into your project:
import { Herb } from "@herb-tools/browser"
await Herb.load()
Herb.parse("content")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:
npm add @herb-tools/nodepnpm add @herb-tools/nodeyarn add @herb-tools/nodebun add @herb-tools/nodeImporting in Your Project
Import the Herb object into your project:
import { Herb } from "@herb-tools/node"
await Herb.load()
Herb.parse("content")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:
npm i https://pkg.pr.new/@herb-tools/core@{commit}pnpm add https://pkg.pr.new/@herb-tools/core@{commit}yarn add https://pkg.pr.new/@herb-tools/core@{commit}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:
npx https://pkg.pr.new/@herb-tools/linter@{commit} template.html.erbnpx https://pkg.pr.new/@herb-tools/formatter@{commit} template.html.erbnpx 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.