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 🙏

© 2025 – Pkg Stats / Ryan Hefner

optical-aligned-text

v0.6.5

Published

React.js component to align first letters of a new line visually to its left «text box side» (optical alignment)

Readme

Optical Aligned Text Teaser

Typography matters. Even on the web. This is a react component for all typography nerds, who wants to have more control over texts on websites and web apps.

Example

Edit optical-aligned-text-example

Install

yarn add optical-aligned-text
# or
npm install optical-aligned-text

Usage

Just use the component like this:

import React from "react";
import OpticalAlignedText from "optical-aligned-text";


const rules = [
    {
        name: "W", // just to find rules faster
        test: /^\n?W/, // regex to test if a word starts with `W` 
        offset: -0.25 // `ch` (character) units
    }, {
        name: "Quotes",
        test: /^\n?([»«„“])/,
        offset: -0.9
    }
];

export default () => 
  <OpticalAlignedText rules={ rules }>
    <section className="container">
      <h1>Willy Wonka!</h1>
      <p>«What the hell is going on here?»</p>
      <p>
        This is a normal aligned text. Can you see <br/>
        the difference to the paragraph above (left text box side)?
      </p>
    </section>
  </OpticalAlignedText>;

Documentation

Properties

The OpticalAlignedText component offers the following properties:

rules • required

Description: Array of objects to define the optical alignment behaviours of each word.

Each rule object should be structured like this:

{
  name: "W" // optional – the name of that rule. Believe me, you will need it in bigger projects!
  test: /^\n?W/, // required – regex to test on every found word in the text
  offset: -0.9 // required – «margin-left» adjustment value, unit: "ch" (x-character width)
}

affectedTags • optional

Default: ["h1", "h2", "h3", "h4", "h5", "h6", "p", "em"]
Description: Html tags that should be checked.

debug • optional

Default: false Description: Renders the affected words with a background-color. Aligned words are colored red, idle words are colored blue.

debugAlignedWordBackground • optional

Default: "#ff9169" Description: Color for the affected words background in debug mode.

debugIdleWordBackground • optional

Default: "#d0f4ff" Description: Color for the idle words background in debug mode.

Feel free to contribute!

Please feel free to develop this plugin together 🥳!

ToDos

  • [ ] Write tests
  • [ ] Add support for rtl text
  • [ ] Improve performance. It isn’t that bad, but it could be better!
  • [ ] Fix multiline word breaks when using &shy; html entities
  • [ ] Fix component rerenders. Currently it’s not supported to rerender the children of <OpticalAlignedText> component
  • [x] Main functionality