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

@oleksii-pavlov/url

v1.2.1

Published

URL utils that help to manage URLs

Downloads

3

Readme

@oleksii-pavlov/url - URL utils

Description

@oleksii-pavlov/url is a lightweight TypeScript utility library for manipulating URL search parameters, hash values, and pathnames in web applications.

Installation

npm install @oleksii-pavlov/url

Usage

Basic Usage

import { URLService } from '@oleksii-pavlov/url'

const urlService = new URLService(config);

urlService.setSearchParam('key', 'value');

const value = urlService.getSearchParam('key');

console.log(value); // Output: 'value'

Methods

Search Parameter Methods

setSearchParam(key: string, value: string): void

Sets a search parameter with the specified key and value.

setSearchParams(params: SearchParams): void

Sets multiple search parameters using an object of key-value pairs.

appendSearchParam(key: string, value: string): void

Appends a search parameter with the specified key and value.

appendSearchParams(params: SearchParams): void

Appends multiple search parameters using an object of key-value pairs.

getSearchParam(key: string): string | null

Gets the value of the search parameter with the specified key.

hasSearchParam(key: string): boolean

Checks if a search parameter with the specified key exists.

deleteSearchParam(key: string): void

Deletes the search parameter with the specified key.

getSearchParams(): SearchParams

Gets all search parameters as an object of key-value pairs.

deleteSearchParams(): void

Deletes all search parameters.

serializeSearchParams(params?: SearchParams): string

Serializes search parameters into a query string. Optionally, you can provide custom search parameters. By default, it uses the window URL search params.

deserializeSearchParams(paramString?: string): SearchParams

Deserializes a query string into an object of search parameters. Optionally, you can provide a custom query string. By default, it uses the window URL search params.

Hash Methods

setHash(hash: string): void

Sets the hash value of the URL.

getHash(): string

Gets the hash value of the URL.

clearHash(): void

Clears the hash value of the URL.

Pathname Methods

setPathname(pathname: string): void

Sets the pathname of the URL.

getPathname(): string

Gets the pathname of the URL.

resetPathname(): void

Resets the pathname to '/'.

Utility Methods

copyURL(): URL

Creates a copy of the current URL.

getBaseURL(): string

Gets the base URL without search parameters or hash.

Subscription Methods

onSearchParamsChange(callback: SubscriptionCallback<SearchParams>): UnsubscribeCallback

Subscribes to changes in the search parameters. Returns a function to unsubscribe from the callback.

onHashChange(callback: SubscriptionCallback<string>): UnsubscribeCallback

Subscribes to changes in the hash value. Returns a function to unsubscribe from the callback.

onPathnameChange(callback: SubscriptionCallback<string>): UnsubscribeCallback

Subscribes to changes in the pathname. Returns a function to unsubscribe from the callback.

Configuration

Config

The Config type defines the configuration options for URLService.

Properties
  • reload: A boolean that specifies whether the page should reload when the URL is updated. Defaults to false.

Example

import { URLService } from '@oleksii-pavlov/url';

// Initialize URLService with configuration
const urlService = new URLService({ reload: true });

// Set a search parameter
urlService.setSearchParam('foo', 'bar');

// window reloaded