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

quicktoc

v2.1.3

Published

Automatic table of contents generator

Downloads

176

Readme

QuickTOC

A simple script that uses the headings in the content of a page and automatically generates a table of contents with styling.

You can see an example image of a generated TOC in this example image.

Setup and Usage

First, install the package.

npm install quicktoc
# or
pnpm add quicktoc

You can initialize the TOC without any parameters.

new QuickTOC().init();

By default, the script looks for an element with the ID "page-contents" to get the headings and an element with the ID "toc" to place the table of contents.

If you want to use elements with custom IDs, you can pass the parameters as shown below:

new QuickTOC().init({
  includeH1: true,                  // includeH1?: boolean;
  pageContentsId: "page-contents",  // pageContentsId?: string;
  tocSectionId: "toc",              // tocSectionId?: string;
});

Options

  • includeH1: By default, the script uses h2, h3, and h4 elements while generating the TOC and reserves h1 element for the page title. To include h1 in the TOC, just set the first parameter to true.

  • pageContentsId: By default, the script looks for an element with the ID "page-contents" to get the headings. You can pass a custom element ID as the second parameter to use headings from that element.

  • tocSectionId: By default, the script looks for an element with the ID "toc" to place the table of contents. You can pass a custom element ID as the third parameter to place the TOC in that element.

Styling

To use the default stylings, you can just install the quicktoc.css file, which contains the default styles for the TOC, and import it.

@import url("/path/to/quicktoc.css"); /* css */
import "/path/to/quicktoc.css"; // typescript
<link rel="stylesheet" href="/path/to/quicktoc.css" /> <!-- html -->

Custom Styling

You can change appearance of the main list by adding styles to the container where the script places the list. Container and sublists have these classes as default:

#toc {}
#toc ul {}
#toc ul li {}
#toc ul li a {}

.toc-sublist {} /* for h2 */
.toc-doublesublist {} /* for h3 */
.toc-triplesublist {} /* for h4 */

When you exclude h1 tags, all the sublists go up one heading level.

.toc-sublist {} /* for h3 */
.toc-doublesublist {} /* for h4 */

/* this class is not used when h1 is not included */
.toc-triplesublist {}