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

@real-router/validation-plugin

v0.1.1

Published

Route validation plugin with type guards and parameter validation

Downloads

133

Readme

@real-router/validation-plugin

npm npm downloads bundle size License: MIT

Runtime validation plugin for Real-Router. Activates descriptive type errors and argument checks across all router operations.

Installation

npm install @real-router/validation-plugin

Peer dependency: @real-router/core

Quick Start

import { createRouter } from "@real-router/core";
import { validationPlugin } from "@real-router/validation-plugin";

const router = createRouter(routes);

// Register before start()
router.usePlugin(validationPlugin());

await router.start();

That's it. From this point on, every router call validates its arguments and throws a descriptive TypeError or RouterError on bad input.

What It Does

Without this plugin, core has structural guards (constructor, plugin registration, dispose) and two invariant guards (subscribe — deferred crash hint, navigateToNotFound — silent corruption prevention). No argument validation for navigation methods. With this plugin, you get the full DX layer:

  • Descriptive error messages with method names and received values
  • Argument shape checks for every public API call
  • forwardTo target existence, param compatibility, and cycle detection
  • Decoder/encoder async detection (sync required for matchPath/buildPath)
  • Dependency store structure validation
  • Limits consistency checks

The plugin also runs a retrospective pass at registration time, validating routes and dependencies that were added before usePlugin() was called.

Note on Crash Guards

Core's crash guards always run, regardless of whether this plugin is installed. They prevent the router from crashing on null or completely wrong types. This plugin adds the descriptive error layer on top. You don't need this plugin for crash prevention in production.

API Reference

validationPlugin()

function validationPlugin(): PluginFactory;

Returns a PluginFactory to pass to router.usePlugin(). Takes no arguments.

Throws RouterError("VALIDATION_PLUGIN_AFTER_START") if the router is already active. Always register before router.start().

// Correct
router.usePlugin(validationPlugin());
await router.start();

// Throws VALIDATION_PLUGIN_AFTER_START
await router.start();
router.usePlugin(validationPlugin()); // too late

RouterValidator type

import type { RouterValidator } from "@real-router/validation-plugin";

The full validator interface that core calls into. Re-exported from @real-router/core/validation. Useful if you're building a custom validator or testing validator functions directly.

Retrospective Validation

When you register the plugin, it immediately validates the current state of the router before start() runs. This catches problems in routes or dependencies that were added before usePlugin():

const router = createRouter([
  { name: "home", path: "/" },
  { name: "home", path: "/duplicate" }, // duplicate name — caught retrospectively
]);

router.usePlugin(validationPlugin()); // throws here

If the retrospective pass fails, the plugin rolls back cleanly. The router is left without validation active, and the error propagates to your code.

What Gets Validated

| Namespace | Validated operations | | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | | Routes | buildPath, matchPath, isActiveRoute, shouldUpdateNode, addRoute, removeRoute, updateRoute, forwardTo targets and cycles | | Options | limits object shape, individual limit values | | Dependencies | setDependency args, dependency name format, full store structure | | Plugins | Plugin count vs maxPlugins limit, addInterceptor args (method enum + function type) | | Lifecycle | Guard/hook handler type, count vs maxLifecycleHandlers | | Navigation | navigate args, navigateToDefault args, NavigationOptions shape, params validation (navigate, buildPath, canNavigateTo), start path validation | | State | makeState args, areStatesEqual args | | Event bus | Event name format, listener args | | Retrospective | Existing route tree integrity, forwardTo consistency, decoder/encoder types, dependency store structure, limits consistency |

Error Messages

All errors from this plugin use a [router.METHOD] prefix so you can immediately tell which call failed.

[router.navigate] Invalid route name: expected string, got number
[router.navigate] params must be a plain object, got string
[router.start] path must start with "/", got "users/profile"
[router.addInterceptor] Invalid method: "intercept". Must be one of: start, buildPath, forwardState
[router.usePlugin] Plugin limit exceeded (50). Current: 50, Attempting to add: 1.

Error types:

  • TypeError — wrong argument type or shape (navigate(42), addInterceptor("x", "notAFn"))
  • ReferenceError — resource not found (getDependency("missing"), updateRoute("nonexistent", ...))
  • RangeError — limit exceeded (usePlugin() past maxPlugins, addActivateGuard() past maxLifecycleHandlers)

Retrospective validation errors use [validation-plugin] prefix instead, since no specific method was called:

[validation-plugin] validateExistingRoutes: duplicate route name "home"

Related Packages

| Package | Description | | ---------------------------------------------------------------------------------------- | -------------------------------------------- | | @real-router/core | Core router (required peer dependency) | | @real-router/logger-plugin | Development logging with transition tracking | | @real-router/browser-plugin | Browser History API integration |

Contributing

See contributing guidelines for development setup and PR process.

License

MIT © Oleg Ivanov