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

@joinbox/tableofcontents

v1.1.8

Published

Table of contents component

Downloads

32

Readme

Table of Contents

Table of contents component that

  • displays any elements that match an arbitrary selector
  • supports templating
  • scrolls smoothly
  • adds anchor links if desired

Polyfills

Example

<h1 class="toc">Table of Contents</h1>
<table-of-contents-component
    data-chapters-selector="h1:not(.toc)"
    data-template-selector="template"
    data-template-content-selector=".text"
    data-template-link-selector="a"
>
    <ul>
        <template>
            <li>
                <a href="#">
                    <span>Go to</span>
                    <span class="text"></span>
                </a>
            </li>
        </template>
    </ul>
</table-of-contents-component>'

<h1>First Title</h1>
<p>Some long content …</p>
<h1>Second title</h1>
<p>Some long content …</p>

<script type="module" src="@joinbox/tableofcontents/TableOfContentsElement.js"></script>

Components

TableOfContentsElement

Exposed Element

<table-of-contents-component></table-of-contents-component>

Attributes

  • data-chapters-selector: CSS selector for all contents that should be displayed in the table of contents. All matching element's textContent will be added to the toc.
  • data-template-selector: CSS selector for the template within the <table-of-contents-component>. Use a <template> tag that is not visible in the browser. All contents will be appended to the parent of this element. It is important, that this element only contains one direct descendant (where the click event listener will be added to).
  • data-template-content-selector: CSS selector for an element within the element that matches data-template-selector. Its textContent will be replaced with the textContent of a content element (see data-chapters-selector).
  • data-template-link-selector (optional): CSS selector for an element within the element that matches data-template-selector. If provided, an id will be added to the corresponding content element (if it does not already exist) and a matching href (anchor link) will be added to the table of contents entry.
  • data-offset-value (optional): Number that will be used as scroll offset. If it is set and valid, data-offset-selector will be ignored.
  • data-offset-selector (optional): CSS selector for an element whose height will be used as scroll offset. Helpful if there is e.g. a sticky menu at the top of the screen to prevent elements from scrolling behind it. data-offset-value precedes data-offset-selector.
  • data-update-event-name: Name of an event that, if fired on window, will update the contents of the table of contents.