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

@kennethormandy/font-to-width

v0.5.0

Published

Font-To-Width is a small JavaScript routine which fits text to the width of an element using multiple font styles of different widths.

Downloads

18

Readme

Font-To-Width FTW

Font-To-Width is a small JavaScript routine which fits text to the width of an element using multiple font styles of different widths.

Originally by Chris Lewis & Nick Sherman, this version has been modified by Kenneth Ormandy to remove the dependency on jQuery.

Install

To install the module through npm, run the following command:

npm install --save @kennethormandy/font-to-width

Then, within your project, require Font to Width:

var FontToWidth = require('@kennethormandy/font-to-width')

Or, if you’re using ES6/2015/whatever:

import FontToWidth from '@kennethormandy/font-to-width'

var els = document.querySelectorAll('.js-ftw')

var ftw = new FontToWidth({
  elements: els,
  fonts: [
    { fontFamily: 'Hardware Regular' },
    { fontFamily: 'Hardware Condensed' },
    { fontFamily: 'Hardware Compressed' }
  ]
})

Alternatively, you can include the font-to-width file in your build process manually, or even reference the file directly:

<script src="https://cdn.rawgit.com/kennethormandy/font-to-width/master/font-to-width.js"></script>

Note you’ll probably want to replace master with a specific version number if you take this approach

Usage

<div class="js-ftw">Text To Fit</div>
<script>
new FontToWidth({
  fonts: [
    'Font Family Name String',
    {
      fontFamily: 'Complete CSS Spec',
      fontWeight: 'normal',
      fontStyle: 'italic'
    },
    // …
  ],
  elements: '.js-ftw' // CSS selector or node list
})
</script>

Notes

  • ~~jQuery is required and must be present in the page before any FTW instances are created~~ The jQuery dependency has been removed from this version.
  • Multiple FontToWidth instances can be created using different font lists and elements.
  • Elements can be anything that is display: block or inline-block
  • If no fonts are specified, behaviour reverts to a simple scale-to-width system

Options

All options are optional.

Name | Default | Description ----------------|---------------------------------------|---------------------------------------------------------------------------------- fonts | | A list of font-family names or sets of CSS style parameters. If empty, existing fonts are scaled to fit elements | ".ftw, .font-to-width, .fonttowidth" | A CSS selector or jQuery object specifying which elements should apply FTW minLetterSpace | -0.04 | A very small, probably negative number indicating degree of allowed tightening minFontSize | 1.0 | Allow scaling of font-size to this ratio of original maxFontSize | 1.0 | Allow scaling of font-size to this ratio of original preferredFit | "tight" | Whether to prefer "tight" or "loose" letterspacing preferredSize | "large" | Whether to prefer "large" or "small" font-size

History

  • 2016-05-29

    • Adds option to pass node list to elements
  • 2016-05-28

  • Removed jQuery dependency

  • Exported for module systems (Browserify, Webpack, etc.)

  • 2015-03-04

  • Added no-fonts scale-to-width behaviour

  • 2015-02-28

  • Added ability to specify complete CSS spec for each font style

  • Added min/maxFontSize, preferredFit/Size options

  • Added demo.html for usage hints

  • Support hyphenated-type or camelCaseType options

  • Bugfixes and safer coding style

  • 2014-03-31 Initial release

  • Only option is 'min-letter-space'

  • Fitting errs on the side of tight spacing

License

The MIT License (MIT)

Copyright © 2016 Kenneth Ormandy Copyright © 2014–2015 Chris Lewis and Nick Sherman