Typehug

Nonbreaking spaces for English and Polish.

Documentation

A little space makes a difference.

Try an example or edit the text to see it for yourself.

Compare short words and paragraph endings at different widths.

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
Joins highlighted

Your text stays in this browser.

6 nonbreaking spaces added

Rules All five on
Rule families

A space can be kept together by more than one rule.

What changed 6 spaces changed.

Why Typehug joined each highlighted space.

  1. I brought a notebook. We have 30 min to tu…

    • Short words Keeps listed short words with the next word as an editorial preference.
  2. I brought a notebook. We have 30 min to turn a good …

    • Short words Keeps listed short words with the next word as an editorial preference.
  3. I brought a notebook. We have 30 min to turn a good idea into a first dra…

    • Numbers and units Keeps a number with a unit from the selected language's dictionary.
  4. …ght a notebook. We have 30 min to turn a good idea into a first draft.

    • Short words Keeps listed short words with the next word as an editorial preference.
  5. …e have 30 min to turn a good idea into a first draft.

    • Short words Keeps listed short words with the next word as an editorial preference.
  6. … 30 min to turn a good idea into a first draft.

    • Paragraph endings Keeps a short final pair of words together as an editorial preference.
Inspect original text No findings

Characters and protected text already in your input.

No selected invisible characters or protected text found. Ordinary spaces and line breaks are not listed.

About these characters

Use in your app npm

The same text, language and rules.

npm install @typehug/en

Your example

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

const text = "I brought a notebook. We have 30 min to turn a good idea into a first draft.";

const result = glue(text);

Use Typehug

Install the language you need. Pass in your text.

npm install @typehug/en

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

ESM TypeScript Node.js 22+

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 and formatted text More examples

HTML

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

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

I have a 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 a 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.

Editorial rules Conventions and sources
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

Report a problem

Describe what you expected in the draft below. Review or remove any text before sharing.

GitHub issues are public. Copy this draft, then open GitHub and paste it into a new issue. A GitHub account is required.

Open GitHub