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

hurdler

v4.0.1

Published

Hurdler makes nested UI interactions simple to manage via URL hash.

Downloads

39

Readme

Hurdler

NPM version Github issues Github stars

Hurdler makes nested UI interactions simple to manage via URL hash.

  • ES6 source with efficient transpilation in mind.
  • Less than 1 KB compressed.
  • IE 11 and modern browser support.
  • MIT license.

How it works

  1. A sprint is triggered manually or automatically when the URL hash changes with a valid target.
  2. Hurdler sprints up the DOM from the target finding ancestor elements that match hurdles.
  3. Jump callbacks run in top-down DOM order. Often components such as overlays need to be activated before descendants.

Lingo | Meaning :----- | :-------------------------------------------------------------------- Target | A DOM element targeted via ID in the URL hash; the sprint start line. Sprint | A sprint up the DOM, looking for hurdles from the target. Hurdle | A test and stuff to do when a DOM element passes. Jump | A hurdle that was found in a sprint.

Benefits

When components such as modals and slideshows are navigated via URL hash:

  • Controls are simple hash links; semantic with no click events to manage.
  • Native browser back and forward controls navigate the UI.
  • Component controls such as slideshow next buttons can be right-clicked and opened in a new tab, etc.
  • Intuitively copy the URL to bookmark or share any part of the page.

With Hurdler:

  • Even deeply nested pieces of content can be accessed by a short, single segment URL hash (e.g. #/pricing). Aside from looking nicer and being easier to tweet than multi-segment approaches (e.g. #/section/overview/slide/pricing), changing structure, components or content is less likely to break existing links.
  • Components define their own hurdles; no centralized routes to setup.
  • Dynamically inserting or moving components around is no problem; every sprint is a fresh search for hurdles to jump.

Setup

Install Hurdler in your project as an NPM dependency:

npm install hurdler --save

Import it at the beginning of your app:

import Hurdler from 'hurdler'

Initialize Hurdler:

const hurdler = new Hurdler()

Setup hurdles:

hurdler.addHurdle({
  test: element => {
    return element.tagName === 'SECTION'
  },
  onJump: element => {
    console.log('Jumped a section', element)
  }
})

Run a first sprint, after DOM ready:

hurdler.sprint()

API

Hurdler

Creates a new Hurdler session. There should only be one instance per window.

Parameters

  • $0 Object (optional, default {})

    • $0.hashPrefix [String] String between URL hash symbol and target element ID to denote Hurdler links. Prevents auto scroll. (optional, default '/')
    • $0.onSprintBefore [function] Runs before each sprint.
    • $0.onSprintAfter [function] Runs after each sprint.
    • $0.hurdles [Array<Hurdle>] List of hurdles. (optional, default [])

Examples

const hurdler = new Hurdler({
  hashPrefix: '!/'
})

target

The current URL hash target element, or null if nonexistent.

Examples

console.log(hurdler.target)

addHurdle

Adds a hurdle.

Parameters

Examples

hurdler.addHurdle({
  test: element => {
    return element.tagName === 'SECTION'
  },
  onJump: element => {
    console.log('Jumped a section', element)
  }
})

validateHash

Checks a provided URL hash matches the configured format.

Parameters

  • hash string A URL hash to validate.

Examples

hurdler.validateHash(anExampleLinkElement.hash)

Returns boolean URL hash validity.

setTarget

Sets the URL hash target element, triggering a sprint.

Parameters

Examples

hurdler.setTarget(anExampleElement)

clearTarget

Clears the window URL hash if a given element is targeted, or if the URL hash matches the configured Hurdler format.

Parameters

  • element [HTMLElement] Element with an ID that you do not want targeted.

Examples

hurdler.clearTarget(anExampleElement)

sprint

Jumps hurdles and runs callbacks for the current URL hash. Use after all hurdles have been added and the document is ready. Triggered automatically by URL hash changes.

Examples

hurdler.sprint()

Hurdle

An object holding a test and callbacks for when a DOM element passes.

Properties

  • test function Accepts an element and returns a boolean if it matches the hurdle.
  • onJump [function] Runs when the hurdle is jumped.

Examples

{
  test: element => {
    return element.tagName === 'SECTION'
  },
  onJump: element => {
    console.log('Jumped a section', element)
  }
}