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

@cheprasov/url-query-params

v2.0.0

Published

The URLQueryParams class defines utility methods to work with the query string of a URL. It is a good replacement for standard URLSearchParams class

Downloads

43

Readme

MIT license

npm i @cheprasov/url-query-params

URLQueryParams

The URLQueryParams class defines utility methods to work with the query string of a URL. It is a good replacement for standard URLSearchParams class.

An object implementing URLQueryParams can directly be used in a for...of structure.

Why URLQueryParams is better than URLSearchParams?

  • According to WHATWG, URLSearchParams uses application/x-www-form-urlencoded format. While it's suitable for decoding URL queries, for encoding it can lead to unexpected results such as spaces being encoded as + and extra characters such as ~ being percent-encoded.
  • URLQueryParams is based on URLSearchParams class and implements all methods of URLSearchParams, but it uses correct encoding format for all characters via encodeURIComponentRFC3986 and conforms to newer RFC 3986 which defines more characters to escape, for example *.

1. How to install

> npm i @cheprasov/url-query-params

Import in .js / .ts file:

import { URLQueryParams } from '@chepraspv/url-query-params';

2. Quick examples

import { URLQueryParams } from '@chepraspv/url-query-params';

new URLQueryParams('foo=bar baz').toString(); // foo=bar%20baz

new URLQueryParams('a=1&b=2&c=3').toObject(); // { a: 1, b: 2, c: 3 }

3. Documentation

3.1 Constructor

// Returns a URLSearchParams object instance.
new URLQueryParams(init?: string[][] | Record<string, string> | string | URLSearchParams | URLQueryParams)

3.2 Methods

// Appends a specified key/value pair as a new search parameter. 
URLQueryParams.append(name: string, value: string): void 
// Deletes the given search parameter, and its associated value, from the list of all search parameters.  
URLQueryParams.delete(name: string): void
// Returns an iterator allowing iteration through all key/value pairs contained in this object.
URLQueryParams.entries(): IterableIterator<[string, string]>
// Allows iteration through all values contained in this object via a callback function.
URLQueryParams.forEach(callbackfn: (value: string, key: string, parent: URLQueryParams) => void, thisArg?: any): void
// Returns the first value associated with the given search parameter.
URLQueryParams.get(name: string): string | null
// Returns all the values associated with a given search parameter.
URLQueryParams.getAll(name: string): string[]
// Returns a boolean value indicating if such a given parameter exists.
URLQueryParams.has(name: string): boolean
// Returns an iterator allowing iteration through all keys of the key/value pairs contained in this object.
URLQueryParams.keys(): IterableIterator<string>
// Sets the value associated with a given search parameter to the given value. If there are several values, the others are deleted.
URLQueryParams.set(name: string, value: string): void
// Sorts all key/value pairs, if any, by their keys.
URLQueryParams.sort(): void
// Returns new object created from key/values params.
URLQueryParams.toObject(): Record<string, string>
// Returns a string containing a query string suitable for use in a URL.
URLQueryParams.toString(): string
// Returns an iterator allowing iteration through all values of the key/value pairs contained in this object.
URLQueryParams.values(): IterableIterator<string>

Something does not work

Feel free to fork project, fix bugs, write tests and finally request for pull