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

widont

v0.4.0

Published

Avoids typographical widows in strings by converting the last space/hyphens to be non-breaking

Downloads

1,061

Readme

widont

In typesetting, single words on the last line of a paragraph are commonly known as widows, and are considered bad style. widont eliminates the issue of widows by using a non-breaking space to force the last two words of a string onto the same line. If the last word contains hyphens they will be converted to the non-breaking variant instead.

Usage

var widont = require('widont')

widont('I dream of a world without widows')
// => 'I dream of a world without\u00a0widows'

widont('I like words with hyphens that stick-together')
// => 'I like words with hyphens that stick\u2011together'

widont('I get HTML entities instead', 'html')
// => 'I get HTML entities instead'

widont('I get exclamation marks', { spaces: '!!', hyphens: '??' })
// => 'I get exclamation!!marks'

In TypeScript

import * as widont from 'widont'

widont('TypeScript says hello', 'html')
// => 'TypeScript says hello'

API

widont(string, [replacements='unicode'], [minWords=3])

Replaces any number of whitespace before the last word of string with a non-breaking space, unless the last word contains hyphens in which case they will be replaced (by non-breaking hyphens) instead. Trims trailing whitespace at the end of string if present. Returns non-string inputs as-is.

The optional replacements argument specifies what characters to use as replacements. It can either be a string that maps to a set of predefined characters (unicode, html or ascii), or an object with the keys space and hyphen (both must be provided):

{
  space: '_',
  hyphen: '~'
}

A TypeError will be thrown for unknown or incomplete replacements values.

The minWords argument specifies the minimum number of words requires to be present in the string for the replacement to be applied. It defaults to 3 to avoid forcing strings only consisting of two words to be kept together, as that could lead to them overflowing.

Origins

The original widont was created by Shaun Inman. This implementation is based on the version in Kirby CMS, which extends the original by using non-breaking hyphens if the last word contains hyphens.

License

MIT