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

typemate

v0.7.1

Published

A little JavaScript module that fixes your typesetting Edit

Downloads

2,336

Readme

TypeMate

TypeMate is a little JavaScript module that fixes your typesetting woes automatically. Right now it only fixes orphans, but the plan is to add more filters in the future that fix other typesetting issues such as line-length.

Getting started

Install it as a dependancy with npm:

npm install typemate

Then import it:

import TypeMate from 'typemate';

At its most basic level, we create TypeMate instance and it'll look for all of the <p> elements on your page.

const typeMateInstance = new TypeMate();

// Run it
typeMateInstance.apply();

You can also pass it a parent element to work with. This is really useful if you only want TypeMate to focus on a particular element, such as an article.

Take this markup sample:

<article id="content">
    <p>Etiam porta sem malesuada magna mollis euismod.</p>
</article>

We can target that particular article's content like so:

const articleElement = document.getElementById('content');
const typeMateInstance = new TypeMate(articleElement);

// Run it
typeMateInstance.apply();

Now, only that <p> element within article#content will be affected by TypeMate.

Settings

You can pass an object of settings as the second parameter when you construct TypeMate. Using the instantiation example from above, we'll add some settings like so:

const articleElement = document.getElementById('content');
const typeMateInstance = new TypeMate(articleElement, { selector: 'h2, p' });

// Run it
typeMateInstance.apply();

That settings object now allows <h2> elements within article#content to be processed by TypeMate.

Settings reference

| Property | Type | Description | Default Value | | ------------- | ------ | ---------------------------------------- | ----------------------------------- | | minWords | Number | The minimum amount of words that have to be present in an element's content before TypeMate will process it | 4 | | selector | String | The selector string that's passed to querySelectorAll | 'p' | | ignoreClass | String | The CSS class that can be added to an element to mark itself as ignorable to TypeMate | 'js⁠-⁠typemate__ignore' | | ignoreExistingSpaceChars | Boolean | Determine if elements should be ignored if they already contain an &nbsp; character | false |

Codepen example

Check out an example of TypeMate over at CodePen: https://codepen.io/hankchizljaw/project/full/ZgpRNy

Running tests

Tests are defined as simple test cases in tests.json.

Each test case can define:

| Key | Type | Description | Default Value | | ---------- | ------- | --------------------------------------- | ------------- | | parent | String | selector of the parent element to use | undefined | | settings | Object | settings object | null | | init | String | initial HTML to test against | | | apply | String | expected HTML after apply() is called | this.init | | reset | String | expected HTML after reset() is called | this.init |

Using NPM

npm i
npm run test

Using Yarn

yarn
yarn test

Made with ❤️ by HankChizlJaw and friends.