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

fitext

v1.4.4

Published

Resizes text elements proportionally to fit any element

Downloads

48

Readme

Fitext is a module which adapts the textual elements so that they are always contained in their parents without ever exceeding whatever the parent height and width. This lightweight library using no-one dependency. You can find a playable demo here.

Table of contents

  1. Installation
  2. Getting Started
  3. Example
  4. Using a CDN
  5. Options
  6. Performance Checklist
  7. Contributors
  8. License

Installation

$ npm install --save fitext
$ yarn add fitext

Getting Started

HTML :

<body>
    <div class="fit-this-text">
        <h1>Resize your window</h1>
        <h2>Play with responsive 💡</h2>
        <p>Insert a huge lorem ipsum text !</p>
    </div>
</body>

ES6 Modules :

import fitext from 'fitext'

fitext(true);

No-module :

<script src='dist/fitext.min.js' defer></script>
<script>
    window.addEventListener('DOMContentLoaded', function() {
        fitext(true);
    });
</script>

Example

import fitext from 'fitext'


const EVENTS = ['DOMContentLoaded', 'resize']

EVENTS.forEach( e => window.addEventListener( e, fitext ) )
//OR
EVENTS.forEach( e => window.addEventListener( e, () => fitext(true, .25) ) )

In the previous example, we listen to all event that can makes overflow texts from their containers, we prevent all break cases by executing the fitext function.

Using a CDN

  • Minified version :

    • https://cdn.jsdelivr.net/npm/fitext@latest/dist/fitext.umd.js
    • https://cdn.jsdelivr.net/npm/fitext@latest/dist/fitext.cjs.js
    • https://cdn.jsdelivr.net/npm/fitext@latest/dist/fitext.esm.js
  • Original version :

    • https://cdn.jsdelivr.net/npm/fitext@latest/src/fitext.js
  • For specific files or enhanced configuration you can go here.

Options

You can pass options in fitext. Allowed values are as follows :

|Name|Type|Default|Description| |:--:|:---:|:-----:|:---------| |wideable|{ Boolean }|false|Enables the font-size enlarger. More| |stagger|{ Float }|1|Change stagger value. More|

- wideable :

This option enlarges the font size above the font size established before executing the `fitext` function.
The default behavior of this options limits the font-size to the font-size established before the function execution.

- stagger :

This option increments or decrements the current font-size by the number of pixels desired.
The smaller the value, the beautiful the change but may cause performance issues.

Performance Checklist

Good to know : Fitext is a very lightweight module : Less than 1 kB !

To increase fitext performances :

  • Try to use relative font-size wherever possible.
  • If you targeting a parent element all child are already taken in account, don't execute a fitext function on them.
  • Try to avoid get too much containers into the fittable elements.
  • Don't use a CSS font-size transition, prefer stagger option usage.

Contributors

License

This project is under ISC License.