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

@riadh-adrani/dom-router

v0.0.7

Published

Router for the DOM

Downloads

19

Readme

dom-router CI/CD npm

A web-based router that is framework agnostic.


Install

add to your project using :

npm i @riadh-adrani/dom-router

Router class

create a router object that manages and react to location/history changes.

constructor

new Router<T>(RouterConfig<T>);

will throw if base is invalid; does not start with /.

unload

unload router and perform need actions.

processPath

process current path and return a boolean that indicates if an update should happen or not.

navigate

navigate to the given destination and perform necessary updates if needed.

getElementByDepth

get element at a given depth or undefined otherwise.

getPath

get current path, stripped out of base.

getParams

get closest route params.

getSearchParams

get current route search query params.

toHref

transform a destination route to a valid href string or undefined otherwise.

Helpers

isUrlNavigatable

check if url is valid as a relative path

function isUrlNavigatable(url: string): boolean;

Types

RouterType

enum RouterType {
  Browser = 'browser',
  Hash = 'hash',
}

RouterConfig

interface RouterConfig<T = unknown> {
  /** array of routes that will be considered by the router */
  routes: Array<RawRoute<T>>;
  /** handler that will run each time the url changes */
  onChanged: () => void;
  /** router type, ``Browser`` by default */
  type?: RouterType;
  /** router base, should start with `/` */
  base?: string;
  /** define if the router should scroll the document body to the top */
  correctScrolling?: boolean;
  /** function that will transform a title, useful for setting title prefix and suffixes */
  transformTitle?: (title?: string) => string;
}

IndexRawRoute

interface IndexRawRoute<T = unknown> {
  path: '';
  name?: string;
  element?: T;
  title?: string;
}

CatchRawRoute

interface CatchRawRoute<T = unknown> {
  path: '*';
  title?: string;
  element?: T;
}

PathRawRoute

interface PathRawRoute<T = unknown> {
  path: string;
  name?: string;
  element?: T;
  title?: string;
  children?: Array<RawRoute<T>>;
}

LayoutRawRoute

interface LayoutRawRoute<T = unknown> {
  element: T;
  children?: Array<RawRoute<T>>;
}

RawRoute

type RawRoute<T = unknown> =
  | LayoutRawRoute<T>
  | IndexRawRoute<T>
  | CatchRawRoute<T>
  | PathRawRoute<T>;

DestinationOptions

interface DestinationOptions {
  replace?: boolean;
}

PathDestinationRequest

type PathDestinationRequest = string;

RelativeDestinationRequest

type RelativeDestinationRequest = number;

NamedDestinationRequest

interface NamedDestinationRequest {
  name: string;
  query?: Record<string, string | number>;
  params?: Record<string, string>;
  hash?: string;
}

DestinationRequest

type DestinationRequest =
  | NamedDestinationRequest
  | PathDestinationRequest
  | RelativeDestinationRequest;