npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@vettvangur/hyphen

v1.2.0

Published

Vettvangur | Responsive language-aware hyphenation

Readme

@vettvangur/hyphen

Responsive, language-aware hyphenation for headlines: long words are hyphenated only when they cannot fit on a line by themselves.

  • initHyphenation (vanilla JS) measures elements in the browser and inserts soft hyphens.
  • Hyphenate (React, @vettvangur/hyphen/react) renders the hyphenation on the server and the client alike, and leaves the line breaking to the browser's layout.

Install

pnpm add @vettvangur/hyphen [email protected]

Vanilla JS

import { initHyphenation } from '@vettvangur/hyphen'

Whole page (default — targets elements with a headline class):

await initHyphenation()

Custom classes:

await initHyphenation(document, { classes: ['my-heading', 'display-text'] })

Each token matches exact class names and prefixes — headline matches both headline and headline-xl.

Scoped to a subtree:

await initHyphenation(someElement)

React

Use the Hyphenate component from @vettvangur/hyphen/react instead of initHyphenation. initHyphenation writes textContent straight into the DOM, which breaks elements React renders.

pnpm add @vettvangur/hyphen [email protected]

react (18 or later) is an optional peer dependency — install it if the project does not already have it.

Usage

import { Hyphenate } from '@vettvangur/hyphen/react'

export default function Hero({ title }) {
  return (
    <h1 className="headline">
      <Hyphenate lang="is">{title}</Hyphenate>
    </h1>
  )
}

| Prop | | |------|---| | children | Plain text to hyphenate. | | lang | is (or is-IS, …) for Icelandic; anything else is English. Defaults to en. Pass the page's locale. |

How it works

Hyphenate inserts soft hyphens into every word that has hyphenation points and wraps each of those words in an inline-block <span>:

  • A word that fits on a line moves to the next line whole, like any other word. Its soft hyphens are never used.
  • A word wider than the line is capped at the line width (max-width: 100%), and the browser breaks it at the soft hyphens.

The browser's own layout makes that decision, at any width, so nothing is measured and nothing runs after load. Resizing and web fonts finishing loading are handled by the browser.

Server and client

The output depends only on children and lang, so the server and the client render the same markup:

  • Works in React Server Components and in client components — no 'use client', hooks or effects.
  • The server HTML already contains the final hyphenation. Hydration matches and nothing changes on screen after the page loads.

The hyphenation patterns are imported statically, because rendering is synchronous. In a server component they stay on the server. In a client component they ship to the browser: about 16 kB gzipped for Icelandic and 22 kB for English (both are imported).

Next.js App Router

Render it straight from a server component:

import { Hyphenate } from '@vettvangur/hyphen/react'

export default async function Page({ params }) {
  const { locale } = await params
  const page = await getPage(locale)

  return (
    <h1 className="headline">
      <Hyphenate lang={locale}>{page.title}</Hyphenate>
    </h1>
  )
}

Layout differences from initHyphenation

A word that has to break takes the full line width, so the text before it ends its line and the text after it starts on a new one. At a narrow width Ný Hæstaréttarlögmannsstofa er hér renders as:

Ný
Hæstaréttarlög-
mannsstofa
er hér

where initHyphenation would put mannsstofa er hér on one line. This only happens when a word cannot fit on a line by itself.

Rich text

Hyphenate takes a plain string. For headings with markup, wrap each text run:

<h1 className="headline">
  <Hyphenate lang="is">{lead}</Hyphenate> <em><Hyphenate lang="is">{emphasis}</Hyphenate></em>
</h1>

Words without hyphenation points

A word the patterns cannot hyphenate is left as plain text and can overflow a narrow line. Give headlines a fallback:

.headline {
  overflow-wrap: break-word;
}

Do not mix with initHyphenation

initHyphenation() on document targets every headline element on the page, including ones React renders. Use either Hyphenate or initHyphenation, not both on the same elements.

Language

Icelandic (is) and English are supported; anything that is not Icelandic is hyphenated as English.

  • initHyphenation detects the language from the nearest [lang] ancestor attribute or <html lang>.
  • Hyphenate takes it as the lang prop, because the server has no DOM to read it from.

CSS classes

initHyphenation marks the elements it processes:

| Class | When added | |-------|-----------| | js-hyphen-manual | Soft hyphens (&shy;) were inserted into a word | | js-hyphen-emergency | A word couldn't be hyphenated — overflow fallback should be applied |

Example CSS:

.js-hyphen-emergency {
  overflow-wrap: break-word;
}

Auto re-runs

When initHyphenation is called with document as the root, it automatically re-runs on:

  • Window resize (debounced 150 ms)
  • Font load events (document.fonts)