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

pilotjs

v2.17.0

Published

Multifunction JavaScript router.

Downloads

37

Readme

Pilot v2

Multifunctional JavaScript router solves the problem of routing your application, providing full control over the route.

Get started

const router = Pilot.create({
	'#route-id': {
    url: '/:type(/:detail)?', // route pattern
    model: {
      user: (req) => fetch(`/api/${req.params.type}`).then(r => r.json()),
    },
		onroute(/**Pilot.Request*/req) {
      console.log(this.model.user);
		}
	}
});

// Запускаем перехват ссылок и history api
router.listenFrom(document, {autoStart: true});

// Где-то в коде
router.go('#route-id').then(() => ...);
router.getUrl('#route-id', {type: 'user'}); // '/user';
router.route.getUrl({type: 'user'}); // '/user';
router.route.getUrl({type: 'user', detail: 123}); // '/user/123';

API

  • create(stitemap: Object): Pilot
  • URL([url: string[, base: string]]) — see Native URL and
    • parse(url: string)
    • toMatcher(pattern: string|RegExp)
    • #properties
      • protocol: string
      • protocolSeparator: string
      • credhost: string
      • cred: string
      • username: string
      • password: string
      • host: string
      • hostname: string
      • port: string
      • origin: string
      • path: string or pathname
      • segment1: string
      • segment2: string
      • search: string
      • query: object
      • params: object
      • hash: string
    • #methods
      • addToQuery(add: object|string|null)
      • removeFromQuery(remove: string[])
      • setQuery(add: object|string|null[, remove: string[])
  • queryString
    • parse(value: string): object
    • stringify(query: object): string

Pilot lifecycle

beforeroute

  • req:Pilot.Request

route

  • req:Pilot.Request
  • route:Pilot.Route

routefail

  • req:Pilot.Request
  • route:Pilot.Route
  • error:Error

routeend

  • req:Pilot.Request
  • route:Pilot.Route

Pilot methods and properties

model:Object

List of all models


request:Pilot.Request

Current Request.


activeUrl:URL

Active/Current URL.


route:Pilot.Route

Current route.


getUrl(id[, params[, query]]):string

  • id:string — route id
  • params:object — route parametrs (optional)
  • query:object|inherit — route GET-query parametrs (optional)

go(id[, params[, query[, details]]]):Promise

  • id:string — route id
  • params:object — route parameters (optional)
  • query:object|inherit — route GET-query parameters (optional)
  • details:object - route navigation details (options)

nav(url[, details]):Promise

  • url:string
  • details:object - route navigation details (options)

reload():Promise

Emits beforereload and reload events. if a handler to beforereload returns false, does not perform actual reload and returns a resolved promise instead.


Pilot.Route methods and properties

model:Object

Local models (inherit global models).


init()

Protected method.


getUrl([params, [query]]):string

  • params:Object (optional)
  • query:object|inherit — route GET-query parametrs (optional)

is(id):boolean

id:string — route id or space-separated list


Pilot.Loader

const modelLoader = new Pilot.Loader({
  user: ({params:{id}}) => fetch(`/api/user/${id}`).then(r => r.json()),
  status: () => fetch(`/api/status`).then(r => r.json()),
}, {
  // неважно сколько раз вызвать `fetch`,
  // если уже есть запрос на сервер, новый не последует
  persist: true,

  // Обработку данных загруженной модели
  processingModel(modelName, modelData, req, models) {
    return {...modelData, pathed: true}; // or Promise
  },

  // Обработка ошибки при загрузки модели
  processingModelError(modelName, error, req, models) {
    return Promise.resolve({defaultData: 123}); // или undefined для reject
  },

  // Финальная обработка полученных данных
  processing(req, models) {
    return {...models, patched: true};
  },
});

// Используем `modelLoader`
const router = Pilot.create({
  model: modelLoader,
});

// Где-то в коде
modelLoader.fetch().then(model => {
  console.log(model.user);
  console.log(model.status);
});