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 🙏

© 2024 – Pkg Stats / Ryan Hefner

microtypejs

v1.0.0

Published

A JavaScript package that implements LaTeX-like text justification, hyphenation, and other micro-typographic adjustments. The name of course is borrowed from the [microtype LaTeX package](https://eu.mirrors.cicku.me/ctan/macros/latex/contrib/microtype/mic

Downloads

7

Readme

microtype

A JavaScript package that implements LaTeX-like text justification, hyphenation, and other micro-typographic adjustments. The name of course is borrowed from the microtype LaTeX package.

Usage

The package can be installed via npm, and imported as an ES module:

npm install microtypejs
import microtype from "microtypejs";

Or loaded directly via a CDN:

<script src="https://unpkg.com/microtypejs/dist/microtype.js"></script>

Once the package is loaded, the most basic usage is just to call the microtype function with an array of elements you want to format.

At present, the elements you want to format must contain nothing but text. Paragraphs containing inline elements are not supported. This is something I want to improve in the future.

microtype({
  elements: document.querySelectorAll("p")
});

More on other configuration options below.

Options

The full list of available options and their defaults are as follows:

type MicrotypeOptions = {
  elements: HTMLElement[];
  maxSpaceShrink: number;
  maxSpaceGrow: number;
  maxTrackingShrink: number;
  maxTrackingGrow: number;
  protrusion: { [key: string]: number };
  hyphenate: boolean;
  showFrame: boolean;
};

const defaultOptions: MicrotypeOptions = {
  elements: [], // The array of elements to format
  maxSpaceShrink: 0.15, // How much space characters can shrink (em)
  maxSpaceGrow: 0.25, // How much space characters can grow (em)
  maxTrackingShrink: 0.01, // How much letter spacing can shrink (em)
  maxTrackingGrow: 0.01, // How much letter spacing can grow (em)
  protrusion: {
    // How much certain characters may protrude from the right margin (em)
    ",": 0.1,
    ".": 0.15,
    "!": 0.1,
    "-": 0.2,
  },
  hyphenate: true, // Whether or not words may hyphenate across lines
  showFrame: false, // Whether or not to show the target frame for formatted elements (for debugging)
};

Demo

TODO