Typehug

Nonbreaking spaces for English and Polish.

Documentation

Playground

Change the width to see which words stay together.

Joins are highlighted
Original

I brought a notebook. We have 30 min to turn a good idea into a first draft.

With Typehug

I brought a notebook. We have 30 min to turn a good idea into a first draft.

260 px

6 nonbreaking spaces added

Try your own text

Installation

Choose the language you need. The examples below follow your selection.

npm install @typehug/en

English rules and the shared engine. No Polish rules included.

ESM TypeScript Node.js 22+

Usage

Pass in your text. Typehug replaces selected spaces with nonbreaking spaces.

Plain text

import { glue } from "@typehug/en";

glue("I have a question.");
Output

I have a question.

Returns a string with Unicode nonbreaking spaces. Render it as text, including in React.

HTML

import { glueHtml } from "@typehug/en/html";

glueHtml("I have a <b>question</b>.");
Output

I have question.

Joins across inline formatting. Importing /html loads the parser.

Formatted runs

import { glueRuns } from "@typehug/en";

glueRuns([
  { text: "I have a " },
  { text: "question.", bold: true },
]);
Output

I have question.

Preserves formatting metadata and leaves the input objects unchanged.

Examples use English. With @typehug/all, pass { locale: "en" } or { locale: "pl" } as the second argument. HTML is parsed and serialized, so entity spellings and markup may normalize.

Rules

Five rule families, enabled by default. Each can be switched off.

Short words
English a, A, I. Polish a, i, o, u, w, z.
a word
Units
Numbers with recognized unit symbols.
30 min
Initials
Consecutive uppercase initials.
J. R.
References
Selected abbreviations and references.
Fig. 2
Endings
Short final pairs in longer paragraphs.
the end

English short-word joins and paragraph endings are editorial preferences. Typehug uses text rules, not screen measurements.

Read the rules and sources