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

@lumeweb/query-builder

v0.1.0

Published

A flexible query parameter parser and serializer for building complex filters, sorting, and pagination in web applications. Extended from Refine's CRUD operators to support Go backend compatibility.

Readme

@lumeweb/query-builder

A flexible query parameter parser and serializer for building complex filters, sorting, and pagination in web applications. Extended from Refine's CRUD operators to support Go backend compatibility.

Features

  • Query Parsing - Parse URL query parameters into structured filter, sort, and pagination objects
  • Query Serialization - Convert structured query objects back to URL-friendly parameters
  • Rich Filter Operators - Support for comparison operators (eq, ne, lt, gt, contains, etc.) and logical operators (and, or, not)
  • Type-Safe - Full TypeScript support with exported types
  • Refine Compatible - Works seamlessly with @refinedev/core types
  • Go Backend Compatible - Extended operators include "not" for Go queryutil compatibility

Installation

pnpm add @lumeweb/query-builder

Usage

Parsing Query Parameters

import { parseQueryParams } from "@lumeweb/query-builder";

const params = {
  "filters[0][field]": "name",
  "filters[0][operator]": "contains",
  "filters[0][value]": ["John", "Doe"],
  "filters[1][field]": "status",
  "filters[1][operator]": "eq",
  "filters[1][value]": "active",
  "filters[2][operator]": "or",
  "filters[2][value][0][field]": "department",
  "filters[2][value][0][operator]": "eq",
  "filters[2][value][0][value]": "sales",
  "filters[2][value][1][field]": "engineering",
  "filters[2][value][1][operator]": "eq",
  "filters[2][value][1][value]": true,
  "_sort": "createdAt",
  "_order": "desc",
  "_start": "0",
  "_end": "20"
};

const parsed = parseQueryParams(params);
// Returns ParsedQuery with filters, sorters, and pagination

Serializing Query Parameters

import { serializeQueryParams } from "@lumeweb/query-builder";

const query = {
  filters: [
    {
      field: "status",
      operator: "eq",
      value: "active"
    }
  ],
  sorters: [
    {
      field: "createdAt",
      order: "desc"
    }
  ],
  pagination: {
    start: 0,
    end: 20
  }
};

const params = serializeQueryParams(query);
// Returns URL-friendly query parameters

Filter Operations

import {
  createEqFilter,
  createContainsFilter,
  createInFilter,
  addFilter,
  mergeFilters
} from "@lumeweb/query-builder";

// Create individual filters
const nameFilter = createEqFilter("name", "John");
const titleFilter = createContainsFilter("title", "Manager");
const statusFilter = createInFilter("status", ["active", "pending"]);

// Add filters to a collection
let filters: CrudFilter[] = [];
filters = addFilter(filters, nameFilter);

// Merge multiple filters
const merged = mergeFilters([nameFilter, statusFilter]);

Sort Operations

import {
  createAscSort,
  createDescSort,
  toggleSort,
  addSorter
} from "@lumeweb/query-builder";

// Create sort configurations
const nameAsc = createAscSort("name");
const createdDesc = createDescSort("createdAt");

// Toggle sort direction
const toggled = toggleSort(nameAsc); // becomes desc

// Add to sorters array
let sorters: CrudSort[] = [];
sorters = addSorter(sorters, nameAsc);

Pagination

import {
  calculatePagination,
  getTotalPages,
  getNextPage,
  getPrevPage,
  hasNextPage,
  hasPrevPage
} from "@lumeweb/query-builder";

const pagination = calculatePagination(2, 25); // page 2, 25 per page
// Returns: { start: 25, end: 50, page: 2, pageSize: 25 }

const totalItems = 100;
const pageSize = 20;

// Get total pages
const total = getTotalPages(totalItems, pageSize); // 5

// Navigate using pagination object
const next = getNextPage(pagination); // 3 (next page number)
const prev = getPrevPage(pagination); // 1 (previous page number)

// Check if more pages exist
const hasNext = hasNextPage(totalItems, pagination); // true
const hasPrev = hasPrevPage(pagination); // true

API Documentation

Types

  • QueryParams - URL query parameter structure
  • ParsedQuery - Parsed result with filters, sorters, and pagination
  • CrudFilter - Union type for LogicalFilter and ConditionalFilter
  • LogicalOperator - "and" | "or" | "not"
  • FieldOperator - Comparison operators (eq, ne, lt, lte, gt, gte, contains, etc.)
  • Pagination - Pagination parameters
  • CrudSort - Sort configuration (re-exported from @refinedev/core)

Constants

  • GLOBAL_SEARCH_FIELD - "q"
  • FILTER_PREFIX - "filters"
  • SORT_PARAM - "_sort"
  • ORDER_PARAM - "_order"
  • START_PARAM - "_start"
  • END_PARAM - "_end"

Operators

Comparison operators: eq, ne, lt, lte, gt, gte, in, nin, ina, nina, contains, ncontains, containss, ncontainss, between, nbetween, null, nnull, startswith, nstartswith, startswiths, nstartswiths, endswith, nendswith, endswiths, nendswiths

Logical operators: and, or, not

Development

# Build
pnpm run build

# Run tests
pnpm run test

# Type check
pnpm run lint

Contributing

Contributions are welcome! Please submit pull requests to the main repository.

License

See LICENSE file for details.