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

ts-toc

v0.1.3

Published

`TableOfContents` is a JavaScript library that generates a table of contents based on the headings in a given HTML element. It allows you to easily create a hierarchical structure of the document's headings and provides an automatically generated table of

Downloads

4

Readme

TableOfContents

TableOfContents is a JavaScript library that generates a table of contents based on the headings in a given HTML element. It allows you to easily create a hierarchical structure of the document's headings and provides an automatically generated table of contents for navigation.

Installation

You can install TableOfContents via npm:

npm install ts-toc

Usage

To use TableOfContents, follow these steps:

  1. Import the TableOfContents class:

    import { TableOfContents } from 'ts-toc';
  2. Create an instance of TableOfContents by passing the target element and optional configuration options:

    const toc = new TableOfContents({
      el: document.getElementById('content'), // Target element for generating the table of contents
      attributes: ['h1', 'h2', 'h3', 'h4'], // Array of heading tags to include in the table of contents
      ulClassName: 'appendix' // Optional class name for the generated unordered list
    });
  3. Call the init() method to generate and append the table of contents to the document:

    toc.init();
  4. Customize the table of contents appearance using CSS as desired.

Example

Here's a basic example of using TableOfContents:

<body>
  <div id="content">
    <h1 id="header1">Header 1</h1>
    <h2 id="header2">Header 2</h2>
    <h3 id="header3">Header 3</h3>
    <h2 id="header4">Header 4</h2>
  </div>

  <script type="module">
    import { TableOfContents } from 'ts-toc';

    const toc = new TableOfContents({
      el: document.getElementById('content')
    });

    toc.init();
  </script>
</body>

This will generate a table of contents based on the headings (h1, h2, h3, h4) within the #content element.

Options

The TableOfContents constructor accepts an options object with the following properties:

  • el (required): The target element for generating the table of contents. Must be an HTML element.
  • attributes (optional): An array of heading tags to include in the table of contents. Defaults to ['h1', 'h2', 'h3', 'h4'].
  • ulClassName (optional): The class name to be added to the generated unordered list element. Defaults to 'appendix'.

License

This project is licensed under the MIT License.

Issues

If you encounter any issues or have suggestions, please open an issue.

Credits

TableOfContents is developed and maintained by Ahmad Ahandani.