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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@alexfalconflores/better-url

v1.0.1

Published

Extension of the URL object with a fluent API (Fluent API) that allows to build URLs in a chained and readable way.

Readme


🚀 Installation

npm install @alexfalconflores/better-url

✨ Features

  • Based on native object URL
  • Seamless API with method chaining
  • Authentication support (auth)
  • Dynamic paths with normalization
  • Query parameters (query, setQuery, tryQuery, etc.)
  • Fragments (#anchor)
  • Generic typing for your query parameters

📦 Examples of use

⚙️ Create a new instance

import BetterURL from "better-url";

type Params = {
  search: string;
  page?: number;
  sort?: "asc" | "desc";
};

const url = new BetterURL<Params>("https://example.com");

🔐 auth

url.auth("admin", "1234");
// https://admin:[email protected]

🔧 portNumber y path

url.portNumber(8080).path("api/v1/users");
// https://admin:[email protected]:8080/api/v1/users

🧭 query

url.query("search", "john").query("sort", "asc");
// https://.../api/v1/users?search=john&sort=asc

❔tryQuery

const optionalPage = undefined;

url.tryQuery("page", optionalPage); // No se añade nada

🔁 (setQuery, trySetQuery)

url.setQuery("search", "doe").trySetQuery("page", 2);
// ?search=doe&page=2

❌ (removeQuery, clearQuery)

url.removeQuery("sort");
url.clearQuery();
// ? (queda vacío)

🧩 (fragment)

url.fragment("top");
// #top

🧪 Final result

console.log(url.toString());
// https://admin:[email protected]:8080/api/v1/users?search=doe&page=2#top

🧠 Strong typing

type QueryParams = {
  search: string;
  page: number;
};

url.query("search", "hello"); // ✅
url.query("unknown", "value"); // ❌ Error: 'unknown' no está en Params

🧰 Available methods

| Method | Description | | -------------------- | --------------------------------------------------- | | .auth(user, pass) | Add credentials to the URL | | .portNumber(port) | Defines the port | | .path(path) | Add routes (normalize /) | | .query(key, value) | Add a query param (use TQueryParams typing) | | .tryQuery(...) | Add a query only if the value is not null/undefined | | .setQuery(...) | Sets or replaces a query | | .trySetQuery(...) | Same as .setQuery but conditional | | .removeQuery(key) | Removes a query parameter | | .clearQuery() | Deletes all parameters | | .fragment(str) | Add or replace a #fragment |

👤 Autor

Alex Stefano Falcon Flores

📄 License

This project is licensed under the MIT license. See the LICENSE file for more details.

⭐ Do you like it?

Give the repo a star to support the project! And if you use it in your projects, I'd love to see it! 🎉