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/search-schema-plugin

v0.2.4

Published

Runtime search parameter validation via Standard Schema for Real-Router

Readme

@real-router/search-schema-plugin

npm npm downloads bundle size License: MIT

Validate and sanitize route search parameters at runtime using any Standard Schema V1-compatible library in Real-Router.

// Without plugin — tampered URL params reach your app unvalidated:
// User visits: /products?page=-1&limit=99999
router.getState().params; // { page: -1, limit: 99999 } — crashes pagination

// With plugin — invalid params stripped, route defaults restored automatically:
router.usePlugin(searchSchemaPlugin());
// User visits: /products?page=-1&limit=99999
router.getState().params; // { page: 1, limit: 20 } — safe defaults from defaultParams

Installation

npm install @real-router/search-schema-plugin

Peer dependency: @real-router/core

Quick Start

import { createRouter } from "@real-router/core";
import { searchSchemaPlugin } from "@real-router/search-schema-plugin";
import { z } from "zod"; // any Standard Schema V1 library — Zod 3.24+, Valibot 1.0+, ArkType

const routes = [
  {
    name: "products",
    path: "/products?page&limit&sortBy",
    defaultParams: { page: 1, limit: 20, sortBy: "price" },
    searchSchema: z.object({
      page: z.number().int().positive(),
      limit: z.number().int().min(1).max(100),
      sortBy: z.enum(["price", "name", "date"]),
    }),
  },
];

const router = createRouter(routes, {
  queryParams: { numberFormat: "auto" },
});
router.usePlugin(searchSchemaPlugin({ mode: "development" }));

Schema libraries: Any library implementing Standard Schema V1 works — Zod 3.24+, Valibot 1.0+, ArkType. Install and configure your chosen library separately; the plugin has no schema-library dependency.

TypeScript Support

Import @real-router/search-schema-plugin to enable TypeScript support for searchSchema on route definitions:

import "@real-router/search-schema-plugin"; // enables Route.searchSchema type

const routes = [
  { name: "users", path: "/users", searchSchema: z.object({ page: z.number() }) },
];

This works via module augmentation — the package extends the Route interface from @real-router/core.

Configuration

| Option | Type | Default | Description | | --------- | --------------------------------------- | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | mode | "development" \| "production" | "development" | In development mode, logs invalid params with console.error. In production mode, strips silently without logging. | | strict | boolean | false | When false, unknown params pass through alongside schema output. When true, only params present in the schema output are kept — unknown keys are removed. | | onError | (routeName, params, issues) => Params | undefined | Custom error handler. When set, overrides both mode logging and the built-in strip+merge recovery. Receives the raw validation issues; returned params are used as-is without re-validation. |

Behavior

Valid params

When schema validation succeeds, the resolved params are merged back based on strict:

// strict: false (default) — schema output merged over original, unknown keys preserved
// Original params: { page: 1, filter: "electronics", utm_source: "google" }
// Schema output:   { page: 1, filter: "electronics" }  (Zod strip mode removes unknowns)
// Result:          { page: 1, filter: "electronics", utm_source: "google" }

// strict: true — schema output used directly, unknown keys removed
// Result: { page: 1, filter: "electronics" }

Invalid params + recovery

When schema validation fails, the plugin strips only the keys with validation issues and restores their defaultParams values:

// Route defaultParams: { page: 1, sortBy: "price" }
// URL: /products?page=foo&sortBy=price
// Schema fails: page is not a valid number
// Step 1 — strip invalid: { sortBy: "price" }
// Step 2 — merge defaults: { page: 1, sortBy: "price" }  ← page restored from defaultParams
// Result: { page: 1, sortBy: "price" }

In mode: "development", a console.error is emitted with the route name and validation issues before the recovery happens.

Strict mode

router.usePlugin(searchSchemaPlugin({ strict: true }));
// Unknown params (not described in schema) are removed on every navigation

Per-route schema configuration (e.g., Zod's .passthrough() or .strip()) controls which keys appear in the schema output and effectively overrides the strict option for that route.

Use Cases

Form Validation — Pagination and Filters

const routes = [
  {
    name: "users",
    path: "/users?page&pageSize&status",
    defaultParams: { page: 1, pageSize: 25, status: "active" },
    searchSchema: z.object({
      page: z.number().int().positive(),
      pageSize: z.number().int().min(1).max(100),
      status: z.enum(["active", "inactive", "all"]),
    }),
  },
];

const router = createRouter(routes, {
  queryParams: { numberFormat: "auto" },
});
router.usePlugin(searchSchemaPlugin());
// /users?page=0&status=deleted → { page: 1, pageSize: 25, status: "active" }

Search Params with Automatic Type Coercion

const searchSchema = z.object({
  q: z.string().min(1),
  page: z.number().int().positive().default(1),
});

const routes = [{ name: "search", path: "/search?q&page", searchSchema }];

// numberFormat: "auto" handles string→number coercion at the search-params layer,
// so schemas validate already-typed values (not raw URL strings)
const router = createRouter(routes, {
  queryParams: { numberFormat: "auto" },
});
router.usePlugin(searchSchemaPlugin());

Custom Error Reporting

router.usePlugin(
  searchSchemaPlugin({
    onError: (routeName, params, issues) => {
      analytics.track("invalid_search_params", { routeName, issues });
      return {}; // empty params — let defaultParams fill in from the route
    },
  }),
);

Schema ↔ Format Coercion

The plugin validates decoded values (not raw URL strings). The coercion from URL string to typed value happens at the search-params layer, controlled by queryParams options on the router. Align your schema types with the format options:

| Schema | Required queryParams option | URL example | Plugin sees | | ---------------------- | ------------------------------------ | ---------------- | ----------------- | | z.boolean() | booleanFormat: "auto" (default) | ?compact=true | { compact: true } | | z.boolean() | booleanFormat: "empty-true" | ?compact | { compact: true } | | z.number().int() | numberFormat: "auto" (default) | ?page=2 | { page: 2 } | | z.string() | Any | ?q=hello | { q: "hello" } | | z.array(z.string()) | arrayFormat: "brackets" (or other) | ?tags[]=a&tags[]=b | { tags: ["a", "b"] } |

Gotcha — mismatched config: if schema declares z.boolean() but booleanFormat: "none" is set, the plugin receives the string "true" / "false" and Zod's z.boolean() will reject it. Fix:

  • Switch to booleanFormat: "auto" (recommended), OR
  • Use z.coerce.boolean() in the schema (accepts strings)

Same applies for numbers — use z.coerce.number() if numberFormat: "none" is set.

Recommended baseline: keep queryParams defaults (booleanFormat: "auto", numberFormat: "auto", nullFormat: "default") unless you have a specific URL aesthetic preference. Defaults align well with typical Zod/Valibot/ArkType schemas.

See @real-router/core — Params Contract for the full type-to-URL mapping.

Documentation

Full documentation: Wiki — search-schema-plugin

Related Packages

| Package | Description | | ------------------------------------------------------------------------------------------------------------ | ------------------------------------------- | | @real-router/core | Core router (required peer dependency) | | @real-router/persistent-params-plugin | Persist query parameters across navigations | | @real-router/validation-plugin | Runtime argument validation for development |

Contributing

See contributing guidelines for development setup and PR process.

License

MIT © Oleg Ivanov