# harfbuzzjs

> Minimal version of HarfBuzz for JavaScript use

Latest version **1.6.1** (published 2026-08-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install harfbuzzjs
pnpm add harfbuzzjs
yarn add harfbuzzjs
bun add harfbuzzjs
```

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 1.6.1 |
| Published | 2026-08-31 |
| First published | 2019-04-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 1.2 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 286 |
| Maintainers | ebraminio, khaledhosny |
| Keywords | harfbuzz, opentype, truetype, ttf, otf, graphics, complex scripts, typography, font rendering, font, fonts, emoji |

## Links

- npm: https://www.npmjs.com/package/harfbuzzjs
- Repository: https://github.com/harfbuzz/harfbuzzjs
- Homepage: https://harfbuzz.github.io/harfbuzzjs
- Issues: https://github.com/harfbuzz/harfbuzzjs/issues
- npm.io page: https://npm.io/package/harfbuzzjs

## Alternatives

- [d3-force-3d](https://npm.io/package/d3-force-3d.md) — 1.0M weekly downloads
- [ng2-charts](https://npm.io/package/ng2-charts.md) — 486.8K weekly downloads
- [@arcgis/core](https://npm.io/package/@arcgis/core.md) — 257.8K weekly downloads
- [react-sparklines](https://npm.io/package/react-sparklines.md) — 249.3K weekly downloads
- [react-native-gifted-charts](https://npm.io/package/react-native-gifted-charts.md) — 182.3K weekly downloads

## Recent versions

- 1.6.1 (latest) — 2026-08-31
- 1.6.0 — 2026-08-09
- 1.5.0 — 2026-07-31
- 1.4.1 — 2026-07-31
- 1.4.0 — 2026-06-15
- 1.3.0 — 2026-06-14
- 1.2.1 — 2026-06-03
- 1.2.0 — 2026-05-17
- 1.1.0 — 2026-05-13
- 1.0.0 — 2026-05-11
- 1.0.0-beta.2 — 2026-05-07
- 1.0.0-beta.1 — 2026-04-27
- 0.10.3 — 2026-04-01
- 0.10.2 — 2026-03-30
- 0.10.1 — 2026-03-19
- … 40 more at https://npm.io/package/harfbuzzjs/versions

## README

# harfbuzzjs

<div align="center">
  <p><img src="logo.png" alt="harfbuzzjs Logo" width="256" align="center"/></p>

  [![Build](https://github.com/harfbuzz/harfbuzzjs/actions/workflows/build.yml/badge.svg)](https://github.com/harfbuzz/harfbuzzjs/actions/workflows/build.yml)
  [![NPM Version](https://img.shields.io/npm/v/harfbuzzjs)](https://www.npmjs.com/package/harfbuzzjs)
</div>

Providing [HarfBuzz](https://github.com/harfbuzz/harfbuzz) shaping
library for client/server side JavaScript projects.

See the demo [here](https://harfbuzz.github.io/harfbuzzjs/demo/).

## Download

From the repo's [releases](https://github.com/harfbuzz/harfbuzzjs/releases), or npm:

```
npm install harfbuzzjs
```

## Migrating from v0.x

The v1 release introduced several API-breaking changes. See [MIGRATING](MIGRATING.md) for migrating from v0.x.

## Usage examples

```js
import * as hb from "harfbuzzjs";

// Load data from a font file:
const response = await fetch("font.ttf");
const arrayBuffer = await response.arrayBuffer();

// Create a HarfBuzz font object from the data:
const blob = new hb.Blob(arrayBuffer);
const face = new hb.Face(blob);
const font = new hb.Font(face);

// Shape text in a HarfBuzz buffer with the font:
const buffer = new hb.Buffer();
buffer.addText("abc");
buffer.guessSegmentProperties();
hb.shape(font, buffer);

// Enumerate the resulted glyphs in the buffer:
const infos = buffer.getGlyphInfos();
const positions = buffer.getGlyphPositions();
for (const [index, glyph] of infos.entries()) {
  const gid = glyph.codepoint; // Glyph ID despite the property name
  console.log(
    font.glyphToPath(gid), // SVG path
    positions[index], // xAdvance, yAdvance, xOffset, yOffset
  );
}
```

### Alternative browser example

See [examples/harfbuzz.example.html](examples/harfbuzz.example.html). To quickly run it in a browser:

```
npx http-server -o /examples/harfbuzz.example.html
```

### Node.js example

See [examples/harfbuzz.example.node.js](examples/harfbuzz.example.node.js).

## Development

### Building

First install [emscripten](https://emscripten.org), then:

```
make
```

### Testing

```
make test
```

## Need more of the library?

harfbuzzjs uses a stripped-down version of Harfbuzz generated by compiling Harfbuzz with `-DHB_TINY`. This may mean that some functions you need are not available. Look at `src/harfbuzz-config.hh` in the Harfbuzz source directory to see what has been removed. For example, `HB_TINY` defines `HB_LEAN` which (amongst other things) defines `HB_NO_OT_GLYPH_NAMES`. If, for example, you really need to get at the glyph names:

1. First, undefine the macro in question, by adding e.g. `#undef HB_NO_OT_GLYPH_NAMES` to `config-override.h`.
2. Next, export any function that you need by adding a line to `harfbuzz.symbols`; in this case `_hb_ot_get_glyph_name`.
3. Now the function will be exported through the WASM object, but you need to add TypeScript to bridge to it - in this case, handling the memory allocation of the `char *` parameter `name` and marshalling it to a JavaScript string. The best way to do this is to look at the source files in `src/` for functions which use similar signatures.

If you have extended harfbuzzjs in ways that you think others will also benefit from, please raise a pull request. If there are parts of Harfbuzz that you need but the instructions above don't work, describe what you are trying to do in an issue.

## Using the library in a bigger emscripten project?
See [harfbuzz port inside emscripten](https://github.com/emscripten-core/emscripten/blob/master/tools/ports/harfbuzz.py)
and [emscripten-ports/HarfBuzz](https://github.com/emscripten-ports/HarfBuzz), basically all you need is to use
`-s USE_HARFBUZZ=1` in your build.

## binaryen

Optionally you can install `binaryen` and use `wasm-opt` like:

```
wasm-opt -Oz harfbuzz.wasm -o harfbuzz.wasm
```

`binaryen` also provides `wasm-dis` which can be used for,

```
wasm-dis harfbuzz.wasm | grep export
wasm-dis harfbuzz.wasm | grep import
```

with that you can check if the built wasm file only exports things you need and
doesn't need to import anything, as usual with wasm files built here.

---
_Source: https://npm.io/package/harfbuzzjs · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
