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

@commerce-atoms/urlstate

v0.0.3

Published

Schema-driven URL state management for filters, sort, and pagination

Readme

@commerce-atoms/urlstate

Pure URL state management for filters, sort, and pagination.

Purpose

Provides utilities for encoding/decoding filter state in URLs:

  • Schema-driven parsing and serialization
  • Filter primitives (toggle, range, clear)
  • Sort and pagination helpers
  • Stable URL param ordering (avoids revalidation churn)

Non-goals

This package explicitly does NOT:

  • ❌ Provide filter UI components
  • ❌ Own "how loaders should work"
  • ❌ Know about Shopify Search & Discovery config
  • ❌ Manage React state or routing
  • ❌ Include URL navigation logic

API

Schema Definition

import {defineSearchSchema} from '@commerce-atoms/urlstate/defineSearchSchema';

// Type-level schema (identity function for type inference only, no runtime validation)
const schema = defineSearchSchema({
  filters: {
    color: {type: 'multiple', param: 'color'},
    size: {type: 'single', param: 'size'},
    price: {type: 'range', param: 'price'},
  },
  sort: {
    param: 'sort',
    default: 'best-selling',
    validValues: ['best-selling', 'price-asc', 'price-desc', 'newest'], // Used for best-effort filtering in parser
  },
  pagination: {
    type: 'cursor',
    param: 'cursor',
  },
});

Parsing & Serializing

import {parseSearchState} from '@commerce-atoms/urlstate/parseSearchState';
import {serializeSearchState} from '@commerce-atoms/urlstate/serializeSearchState';

const state = parseSearchState(
  new URLSearchParams('?color=red&color=blue&size=large'),
  schema,
);
// { filters: { color: ['red', 'blue'], size: 'large' }, sort: 'best-selling' }

const params = serializeSearchState(state, schema, {
  excludeDefaults: true,
  sortParams: true,
});

Filter Operations

import {toggleFilter} from '@commerce-atoms/urlstate/filters/toggleFilter';
import {setRangeFilter} from '@commerce-atoms/urlstate/filters/setRangeFilter';
import {clearFilter} from '@commerce-atoms/urlstate/filters/clearFilter';
import {clearAllFilters} from '@commerce-atoms/urlstate/filters/clearAllFilters';

const nextState = toggleFilter(state, 'color', 'green');
const withRange = setRangeFilter(state, 'price', {min: 10, max: 100});
const cleared = clearFilter(state, 'color');
const reset = clearAllFilters(state);

Sort & Pagination

import {setSort} from '@commerce-atoms/urlstate/sort/setSort';
import {setPage} from '@commerce-atoms/urlstate/pagination/setPage';
import {setCursor} from '@commerce-atoms/urlstate/pagination/setCursor';

const sorted = setSort(state, 'price-asc');
const paged = setPage(state, 2);
const cursored = setCursor(state, 'eyJsYXN0X2lkIjoxMH0=');

Patching URLs

import {patchSearchParams} from '@commerce-atoms/urlstate/patchSearchParams';

const patched = patchSearchParams(
  currentParams,
  {filters: {color: ['red']}},
  schema,
  {preserveUnknownParams: true},
);

Type Philosophy

Structural types, no framework dependency:

interface SearchState {
  filters: Record<string, FilterValue | undefined>;
  sort?: string;
  page?: number;
  cursor?: string;
}

type FilterValue = string | string[] | {min?: number; max?: number};

Status

  • 0.x
  • ESM only, Node >=18

Compatibility

  • Works with any router (React Router, Next.js, custom)
  • No framework dependencies
  • Stable param ordering (alphabetical)
  • Unknown params preserved by default

Delete-ability

Removing this package = replacing imports. That's it.