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

@neoncitylights/html-walker

v0.0.0

Published

TypeScript library to make walking through the DOM easier

Downloads

4

Readme

@neoncitylights/html-walker

License: MIT GitHub deployments Node.js workflow

This library provides some utilities for walking through specific HTML elements and turning into machine-readable data.

Install

npm install @neoncitylights/html-walker

Documentation

Auto-generated API documentation is available.

API Reference

Walker functions

  • fn: # walkDescriptionList.walkDescriptionList<K, V>(element, termCallback, detailsCallback): Map<K, V>source
  • fn: # walkTable.walkTable(table): TableRow[][]source

Walker helper utilities

  • T: # walkTable.TableBodiessource
  • T: # walkTable.TableRowsource
  • fn: # walkTable.collectProperties(table): string[] • source
  • fn: # walkTable.collectTableBodies(table): TableBodiessource
  • fn: # walkTable.collectRows(table): TableRowsource

Table utilities

  • fn: # tableUtils.isTableRelatedElement(element): booleansource
  • fn: # tableUtils.getTableCaption(element): stringsource
  • fn: # tableUtils.getClosestParentTableElement(element): HTMLTableElement|undefiendsource
  • fn: # tableUtils.getClosestParentTableElementFromRow(row): HTMLTableElementsource

Usage

import { walkDescriptionList, walkTable } from '@neoncitylights/html-walker';

// walking through a description list
let descListElement = document.querySelector('dl#my-description-list') as HTMLDListElement;
let descList = walkDescriptionList(
	descListElement,
	(term) => term.textContent,
	(details) => details.textContent);

// walking through a table
let timezonesTable = document.querySelector('table') as HTMLTableElement;
let timezones = walkTable(timezonesTable);

Full examples

Walking through a description list (<dl>)

<dl id="prefs">
	<div>
		<dt>Extensions</dt>
		<dd>Remove, install, and change settings of extensions</dd>
	</div>
	<div>
		<dt>Site activity</dt>
		<dd>Learn how visitors are using your site</dd>
	</div>
	<div>
		<dt>Layout and appearance</dt>
		<dd>Change how your site appears to viewers</dd>
	</div>
	<div>
		<dt>Privacy</dt>
		<dd>Decide who is able to access your site</dd>
	</div>
	<div>
		<dt>Security and storage</dt>
		<dd>Backup, update, and protect your site</dd>
	</div>
</dl>
import { walkDescriptionList } from '@neoncitylights/html-walker';

const prefsElement = document.getElementById('prefs') as HTMLDListElement;
const prefs = walkDescriptionList(prefsElement,
	(term) => term.textContent,
	(details) => details.textContent);
{
	"Extensions": "Remove, install, and change settings of extensions",
	"Site activity": "Learn how visitors are using your site",
	"Layout and appearance": "Change how your site appears to viewers",
	"Privacy": "Decide who is able to access your site",
	"Security and storage": "Backup, update, and protect your site."
}

Walking through a table (<table>)

<table class="wikitable" id="timezone-examples">
	<thead>
		<tr>
			<th>Name</th>
			<th>Explanation</th>
		</tr>
	</thead>
	<tbody>
		<tr>
			<td><a href="/wiki/America/Costa_Rica">America/Costa_Rica</a></td>
			<td>name of country used because the name of the largest city (and capital city) <a href="/wiki/San_Jos%C3%A9,_Costa_Rica" >San José</a> is <a href="/wiki/San_Jos%C3%A9_(disambiguation)#Places">ambiguous</a></td>
		</tr>
		<tr>
			<td><a href="/wiki/America/New_York">America/New_York</a></td>
			<td>Space replaced with underscore</td>
		</tr>
		<tr>
			<td><a href="/wiki/Asia/Kolkata">Asia/Kolkata</a></td>
			<td>name of city of <a href="/wiki/Kolkata">Kolkata</a> used, because it was the most populous city in the zone at the time the zone was set up, though this is no longer true<sup><a href="#cite_note-17">[17]</a></sup></td>
		</tr>
		<tr>
			<td><a href="/wiki/Asia/Sakhalin">Asia/Sakhalin</a></td>
			<td>name of island used, because largest city, <a href="/wiki/Yuzhno-Sakhalinsk">Yuzhno-Sakhalinsk</a>, has more than 14 characters</td>
		</tr>
		<tr>
			<td><a href="/wiki/America/Bahia_Banderas">America/Bahia_Banderas</a></td>
			<td>"de" removed from <a href="/wiki/Bahia_de_Banderas">Bahia de Banderas</a>, because correct name has more than 14 characters</td>
		</tr>
		<tr>
			<td><a href="/wiki/Antarctica/DumontDUrville">Antarctica/DumontDUrville</a></td>
			<td>the apostrophe is removed. The space would normally be replaced with "_", but the name would then exceed 14 characters.</td>
		</tr>
	</tbody>
</table>
import { walkTable } from '@neoncitylights/html-walker';

let timezoneTableElement = document.getElementById('timezone-examples') as HTMLTableElement;
let timezoneExamples = walkTable(timezoneTableElement);
[
	[
		{
			"Name": "America/Costa_Rica",
			"Explanation": "name of country used because the name of the largest city (and capital city) San José is ambiguous"
		},
		{
			"Name": "America/New_York",
			"Explanation": "Space replaced with underscore"
		},
		{
			"Name": "Asia/Kolkata",
			"Explanation": "name of city of Kolkata used, because it was the most populous city in the zone at the time the zone was set up, though this is no longer true[17]"
		},
		{
			"Name": "Asia/Sakhalin",
			"Explanation": "name of island used, because largest city, Yuzhno-Sakhalinsk, has more than 14 characters"
		},
		{
			"Name": "America/Bahia_Banderas",
			"Explanation": "de removed from Bahia de Banderas, because correct name has more than 14 characters"
		},
		{
			"Name": "Antarctica/DumontDUrville",
			"Explanation": "the apostrophe is removed. The space would normally be replaced with \"_\", but the name would then exceed 14 characters."
		}
	]
]

License

This library is licensed under the MIT License.