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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@eydun/table-sorter

v1.3.0

Published

A js sorter for HTML tables

Downloads

148

Readme

@eydun/table-sorter

A lightweight, dependency-free ES module that adds sortable behavior to HTML tables.

Features

  • No dependencies (pure JavaScript)
  • Single-column sorting by click
  • Multi-column sorting with Shift+click
  • Numeric, text, and date sorting
  • Optional explicit date parsing with data-sort-dateformat
  • Optional explicit type selection with data-sort-type
  • Persistent sort state per table via localStorage
  • Keyboard support (Tab + Enter / Space)

Installation

Install from npm:

npm install @eydun/table-sorter

Or copy src/table-sorter.js into your project.

Quick Start

<table id="myTable">
  <thead>
    <tr>
      <th data-sort>Name</th>
      <th data-sort>Age</th>
      <th data-sort>City</th>
    </tr>
  </thead>
  <tbody>
    <tr><td>Alice</td><td>30</td><td>Paris</td></tr>
    <tr><td>Bob</td><td>22</td><td>London</td></tr>
  </tbody>
</table>

<script type="module">
  import { tableSorter } from '@eydun/table-sorter';
  tableSorter('#myTable').init();
</script>

API

Entry point:

import { tableSorter } from '@eydun/table-sorter';
tableSorter(target).init();

target can be:

  • A selector string ('#myTable', '.sortable-table', 'table[data-sortable]')
  • A single <table> element
  • A NodeList / HTMLCollection
  • An array (or iterable) of selectors and/or table elements

Examples:

// Single table by id
tableSorter('#myTable').init();

// All tables by class
tableSorter('.sortable-table').init();

// Any selector
tableSorter('table[data-sortable]').init();

// Single DOM element
const tableEl = document.getElementById('myTable');
tableSorter(tableEl).init();

// Mixed multi-target init in one call
tableSorter(['#usersTable', '#ordersTable', '.team-table']).init();

HTML Attributes

  • data-sort on <th>:
    • Enables sorting for that header.
    • If empty (<th data-sort>), current column index is used.
    • If set (<th data-sort="2">), explicit column index is used.
  • data-sort on <thead>:
    • Enables sorting on all header cells in that <thead>.
  • data-no-sort on <th>:
    • Opts a column out when <thead data-sort> is used.
  • data-sort-dateformat on <th>:
    • Explicit date format for parsing values in that column.
    • Supported tokens: DD, D, MM, M, YYYY, YY.
    • Example: <th data-sort data-sort-dateformat="DD/MM/YYYY">Start</th>
  • data-sort-type on <th>:
    • Forces sorting strategy for that column.
    • Supported values: number, text, date.
    • Example: <th data-sort data-sort-type="number">Amount</th>
  • data-sorter-id on <table>:
    • Optional stable id fallback for persistence when a table has no id.

Sorting Behavior

  • Click a sortable header to sort ascending; click again to toggle descending.
  • Use Shift+click to add/toggle secondary and tertiary sort rules.
  • Sort icons are inserted automatically.
  • data-sort-type overrides auto-detection for its column.
  • If both compared values look numeric, numeric comparison is used.
  • Otherwise date comparison is attempted, then text comparison.

Accessibility

Sortable headers get:

  • tabindex="0"
  • aria-sort updates (none, ascending, descending)
  • Keyboard sorting with Enter and Space

Persistent Sort State

Sort state is stored per table id:

localStorage['sorter-sortOrders-<table-id>']

On init, the sorter restores saved state if valid. Invalid saved payloads are ignored safely.

Demo

See demo/index.html for a full example covering:

  • id-based init
  • class/multi-target init
  • data-no-sort
  • explicit index sorting
  • explicit type override with data-sort-type
  • date format sorting
  • keyboard sorting
  • persistence and invalid-state handling

Browser Support

Modern browsers:

  • Chrome
  • Firefox
  • Safari
  • Edge

(Internet Explorer is not supported.)

License

MIT. See LICENSE.