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

advanced-url-search-params

v1.1.0

Published

Tool for converting search params to objects that can be used in typescript application.

Downloads

68

Readme

AdvancedUrlSearchParams

License: MIT

AdvancedUrlSearchParams is a TypeScript class that facilitates the parsing and extraction of filtering, pagination, and sorting information from URL search parameters.

Table of Contents

Installation

To use AdvancedUrlSearchParams in your project, you can install it via npm:

npm install advanced-url-search-params

Usage

import { AdvancedUrlSearchParams } from "advanced-url-search-params";

const searchParamsString = "page=1&size=10&column=name&direction=asc&filter=name:contains:john";

const urlSearchParams = new AdvancedUrlSearchParams(searchParamsString);

// Accessing parsed values
const pagination = urlSearchParams.pagination;
const sorting = urlSearchParams.sorting;
const filters = urlSearchParams.filters;

Examples

Here are some examples demonstrating how to use AdvancedUrlSearchParams:

Basic Usage

import { AdvancedUrlSearchParams } from "advanced-url-search-params";

const searchParamsString = "page=1&size=10&name:eq=john&sort=startDate";

const urlSearchParams = new AdvancedUrlSearchParams(searchParamsString);

console.log(urlSearchParams.pagination); // { page: 1, size: 10 }
console.log(urlSearchParams.sorting); // [{ column: 'name', direction: 'asc' }]
console.log(urlSearchParams.filters); // [{ column: 'name', value: 'john', rule: 'eq' }]

API

AdvancedUrlSearchParams

Constructor

  • new AdvancedUrlSearchParams(searchParams: string): AdvancedUrlSearchParams

    Creates an instance of AdvancedUrlSearchParams by parsing the provided search parameters.

Properties

  • pagination: Pagination

    Gets the pagination information from the URL search parameters.

  • sorting: Sorting[]

    Gets the sorting information from the URL search parameters.

  • filters: Filter[]

    Gets the filter information from the URL search parameters.

Pagination

  • page?: number

    The current page number.

  • size?: number

    The number of items per page.

Sorting

  • column: string

    The column to sort by.

  • direction: SortingDirection

    The sorting direction (enum).

Filter

  • column: string

    The column to filter by.

  • value: string

    The value to filter.

  • rule: FilterRule

    The filter rule (enum).

Filter rules:

  Equal = "eq",
  NotEqual = "ne",
  GreaterThan = "gt",
  GreaterThanOrEqual = "ge",
  LessThan = "lt",
  LessThanOrEqual = "le",
  Contains = "contains",
  NotContains = "not_contains",
  StartsWith = "starts_with",
  EndsWith = "ends_with",
  In = "in",
  NotIn = "not_in",
  Between = "between",
  NotBetween = "not_between",
  IsNull = "is_null",
  IsNotNull = "is_not_null",
  IsEmpty = "is_empty",
  IsNotEmpty = "is_not_empty",
  IsTrue = "is_true",
  IsFalse = "is_false",

Special thanks to @dszwcz for his support and contribution.

Contributing

Contributions are welcome! If you find any issues or have suggestions for improvement, please open an issue or submit a pull request.

License

This project is licensed under the MIT License.