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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@taurien/fittext

v1.0.1

Published

Vanilla TypeScript port of FitText - makes font sizes flexible

Readme

FitText.js (TypeScript)

A vanilla TypeScript port of the original FitText.js - makes font sizes flexible and responsive.

Credits

This project is a TypeScript port of the original FitText.js by @davatron5000. All credit for the original concept and implementation goes to the original authors.

Installation

npm install @taurien/fittext

Or with GitHub Packages:

npm install @taurien/fittext --registry=https://npm.pkg.github.com

Usage

import { fitText } from "@taurien/fittext";

// Using an element reference
const element = document.getElementById("responsive-headline");
const controller = fitText(element, {
  compressor: 1,
  minFontSize: 12,
  maxFontSize: 100,
});

// Or using a selector
fitText("#responsive-headline", {
  compressor: 1.2,
});

// Manually trigger resize
controller.resizer();

// Clean up when done
controller.destroy();

Usage with React (TSX)

Basic Usage with useRef and useEffect

import React, { useEffect, useRef } from "react";
import { fitText, FitTextController } from "@taurien/fittext";

function ResponsiveHeadline() {
  const headlineRef = useRef<HTMLHeadingElement>(null);
  const controllerRef = useRef<FitTextController | null>(null);

  useEffect(() => {
    if (headlineRef.current) {
      controllerRef.current = fitText(headlineRef.current, {
        compressor: 1.2,
        minFontSize: 20,
        maxFontSize: 100,
      });
    }

    // Cleanup on unmount
    return () => {
      controllerRef.current?.destroy();
    };
  }, []);

  return <h1 ref={headlineRef}>Your Responsive Headline</h1>;
}

Custom Hook (Reusable)

import { useEffect, useRef, RefObject } from "react";
import { fitText, FitTextOptions, FitTextController } from "@taurien/fittext";

function useFitText<T extends HTMLElement>(
  options?: FitTextOptions
): RefObject<T> {
  const elementRef = useRef<T>(null);
  const controllerRef = useRef<FitTextController | null>(null);

  useEffect(() => {
    if (elementRef.current) {
      controllerRef.current = fitText(elementRef.current, options);
    }

    return () => {
      controllerRef.current?.destroy();
    };
  }, [options]);

  return elementRef;
}

// Usage:
function MyComponent() {
  const headlineRef = useFitText<HTMLHeadingElement>({
    compressor: 1,
    minFontSize: 16,
    maxFontSize: 80,
  });

  return <h1 ref={headlineRef}>Responsive Text</h1>;
}

Wrapper Component

import React, { useEffect, useRef, ReactNode } from "react";
import { fitText, FitTextOptions, FitTextController } from "@taurien/fittext";

interface FitTextComponentProps extends FitTextOptions {
  children: ReactNode;
  className?: string;
  as?: keyof JSX.IntrinsicElements;
}

function FitTextComponent({
  children,
  className,
  as: Tag = "div",
  compressor,
  minFontSize,
  maxFontSize,
}: FitTextComponentProps) {
  const elementRef = useRef<HTMLElement>(null);

  useEffect(() => {
    if (elementRef.current) {
      const controller = fitText(elementRef.current, {
        compressor,
        minFontSize,
        maxFontSize,
      });

      return () => controller.destroy();
    }
  }, [compressor, minFontSize, maxFontSize]);

  return (
    <Tag ref={elementRef} className={className}>
      {children}
    </Tag>
  );
}

// Usage:
function App() {
  return (
    <FitTextComponent
      as="h1"
      compressor={1.5}
      minFontSize={20}
      maxFontSize={100}
      className="hero-title"
    >
      My Responsive Headline
    </FitTextComponent>
  );
}

API

fitText(element, options)

Parameters:

  • element: HTMLElement | string - DOM element or CSS selector
  • options: FitTextOptions (optional)
    • compressor: number - Controls resize aggressiveness (default: 1)
    • minFontSize: number - Minimum font size in pixels (default: no limit)
    • maxFontSize: number - Maximum font size in pixels (default: no limit)

Returns: FitTextController

  • resizer(): Manually trigger a resize calculation
  • destroy(): Remove event listeners and stop automatic resizing

License

MIT