This guide covers the API and packaging changes between v0.x and v1.x.
The package is now an ES module. WASM initialization happens at module load time via top-level await.
| v0.x | v1.x |
|---|---|
require("harfbuzzjs").then((hb) => …) |
import { Blob, Face, … } from "harfbuzzjs" |
Instead of using factory functions, we now export classes with constructors.
| v0.x | v1.x |
|---|---|
hb.createBlob(…) |
new hb.Blob(…) |
hb.createFace(…) |
new hb.Face(…) |
hb.createFont(…) |
new hb.Font(…) |
hb.createFontFuncs(…) |
new hb.FontFuncs(…) |
hb.createBuffer(…) |
new hb.Buffer(…) |
Instead of manually calling .destroy(), WASM objects are now reclaimed automatically using FinalizationRegistry. There are no longer any .destroy() methods.
Several APIs that took string codes or magic numbers now take typed enum values exported from the package.
| API | v0.x | v1.x |
|---|---|---|
Buffer.setDirection |
setDirection("ltr") |
setDirection(Direction.LTR) |
Buffer.setFlags |
["BOT", "PRODUCE_UNSAFE_TO_CONCAT"] |
BufferFlag.BOT | BufferFlag.PRODUCE_UNSAFE_TO_CONCAT |
Buffer.serialize format |
"JSON" |
BufferSerializeFormat.JSON |
Buffer.serialize flags |
["NO_GLYPH_NAMES", "NO_ADVANCES"] |
BufferSerializeFlag.NO_GLYPH_NAMES | BufferSerializeFlag.NO_ADVANCES |
Face.getGlyphClass return |
"BASE_GLYPH" |
GlyphClass.BASE_GLYPH |
shapeWithTrace stop_phase |
1 |
TracePhase.GSUB |
| v0.x | v1.x |
|---|---|
face.reference_table(tag) |
face.referenceTable(tag) |
hb.version_string() |
hb.versionString() |
GlyphPosition.x_advance |
GlyphPosition.xAdvance |
GlyphPosition.y_advance |
GlyphPosition.yAdvance |
GlyphPosition.x_offset |
GlyphPosition.xOffset |
GlyphPosition.y_offset |
GlyphPosition.yOffset |
The Buffer.json() shortcut has been removed. Use the typed accessors instead:
Buffer.getGlyphInfos()for glyph IDs, clusters, and flags.Buffer.getGlyphPositions()for advances and offsets.Buffer.getGlyphInfosAndPositions()for both combined.
When you need the raw HarfBuzz JSON output (e.g. to capture all fields including glyph names), call Buffer.serialize() with BufferSerializeFormat.JSON and JSON.parse() the result yourself.
null is no longer used anywhere in the API. Anything that previously returned, accepted, or held null now uses undefined instead.
Affected APIs:
Buffer.serializenow takes a single options object:{ font, start, end, format, flags }(all optional). The previous positional signature is gone.shapeandshapeWithTracenow takeFeature[]instead of a comma-separated string. Use the newFeatureclass (e.g.new Feature("liga", 0)orFeature.fromString("-liga")).Font.setVariationsnow takesVariation[]instead ofRecord<string, number>. Use the newVariationclass (e.g.font.setVariations([new Variation("wght", 700)])orVariation.fromString("wght=700")).Buffer.addText/Buffer.addCodePoints:itemLengthacceptsundefined(or omission), instead ofnull.Face.getFeatureNameIds: returnsundefinedon failure, instead ofnull.Font.glyphHOrigin/glyphVOrigin/glyphExtents/glyphFromName: returnundefinedon failure, instead ofnull.FontFuncs.set*Funccallbacks: returnundefinedon failure, instead ofnull.FeatureNameIdsfieldsuiLabelNameId,uiTooltipTextNameId,sampleTextNameId: are now optional