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

squaretext

v0.2.0

Published

Lay text out so that it fits a square. Great for graph node labels.

Downloads

4

Readme

squaretext

squaretext sample

NPM version

This package takes a string of text and breaks it into lines so that it fits a square nicely. The square has width equal to height what makes it easy to place square-formatted text into shapes such as circles or stars without sacrificing readability.

The main use cases include the labels of nodes in a network visualization. The nodes usually have a round shape and textual labels in various lengths. Therefore a piece of text composed into square will fit the node nicely.

The package is designed for client-side web applications. It requires the browser to support TextMetrics Web API.

Install

> npm install squaretext

Usage

Just do a simple function call:

> import fitParagraph from 'squaretext'
> fitParagraph('Fit me inside a square!', 200, 'Arial')
HTMLElement <p style="width: 200px; padding: 0; font-size: 42.3px; line-height: 52.9px;">Fit me inside a square!</p>

API

squaretext.fitParagraph(str, width[, fontName[, fontStyle]])

Place the text into a paragraph and adjust the paragraph font size and line height so that the text flows roughly into a square shape. The font dimensions are computed based on the given font family name and style.

Parameters:

  • str: a string
  • width: an integer, the paragraph width in pixels.
  • fontName: optional string, the font family name. Names containing whitespace should be quoted, for example "Comic Sans MS". The default is sans-serif.
  • fontStyle: optional string, the font style e.g italics. Default is an empty string.

Return: HTMLElement, the paragraph element with inline styles.

Contribute

Pull requests and bug reports are highly appreciated. Please test your contribution with the following scripts:

Install build dependencies:

$ npm install

Validate your code:

$ npm run lint

Test your code:

$ npm test

License

MIT