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

url-merge

v0.1.0

Published

A zero-dependency URL path joiner. Like `path.join()` but for URLs.

Readme

url-merge

A zero-dependency URL path joiner. Like path.join() but for URLs.

Based on proper-url-join but with no dependencies (uses native URLSearchParams instead of query-string).

Installation

bun add url-merge
yarn add url-joiner
npm install url-joiner
pnpm add url-joiner

Usage

import urlMerge from "url-joiner";

urlMerge("http://example.com", "foo", "bar");
// => 'http://example.com/foo/bar'

Examples

Basic joining

urlMerge("foo", "bar");
// => '/foo/bar'

urlMerge("/foo/", "/bar/", "/baz/");
// => '/foo/bar/baz'

urlMerge("http://example.com", "api", "users");
// => 'http://example.com/api/users'

With query strings

urlMerge("http://example.com", "foo?page=1");
// => 'http://example.com/foo?page=1'

urlMerge("http://example.com", "foo", "?page=1");
// => 'http://example.com/foo?page=1'

Adding query parameters via options

urlMerge("http://example.com", "users", { query: { page: 1, limit: 10 } });
// => 'http://example.com/users?limit=10&page=1'

// Merges with existing query string
urlMerge("http://example.com/users?sort=name", { query: { page: 1 } });
// => 'http://example.com/users?page=1&sort=name'

// Array values
urlMerge("http://example.com", { query: { tags: ["a", "b", "c"] } });
// => 'http://example.com?tags=a&tags=b&tags=c'

Trailing slash control

// Default: no trailing slash
urlMerge("foo", "bar");
// => '/foo/bar'

// Force trailing slash
urlMerge("foo", "bar", { trailingSlash: true });
// => '/foo/bar/'

// Keep original trailing slash
urlMerge("/foo/bar/", { trailingSlash: "keep" });
// => '/foo/bar/'

urlMerge("/foo/bar", { trailingSlash: "keep" });
// => '/foo/bar'

Leading slash control

// Default: add leading slash
urlMerge("foo", "bar");
// => '/foo/bar'

// Remove leading slash
urlMerge("/foo", "/bar", { leadingSlash: false });
// => 'foo/bar'

// Keep original leading slash
urlMerge("foo", "bar", { leadingSlash: "keep" });
// => 'foo/bar'

urlMerge("/foo", "bar", { leadingSlash: "keep" });
// => '/foo/bar'

Protocol-relative URLs

// By default, // is treated as a path
urlMerge("//cdn.example.com", "assets", "image.png");
// => '/cdn.example.com/assets/image.png'

// Enable protocol-relative URL handling
urlMerge("//cdn.example.com", "assets", "image.png", { protocolRelative: true });
// => '//cdn.example.com/assets/image.png'

Handling numbers

urlMerge("users", 123, "posts");
// => '/users/123/posts'

urlMerge("http://example.com", "api", "v", 2);
// => 'http://example.com/api/v/2'

Filtering invalid values

Non-string and non-numeric values are automatically filtered:

urlMerge("foo", null, "bar", undefined, "baz");
// => '/foo/bar/baz'

urlMerge("foo", "", "bar");
// => '/foo/bar'

API

urlMerge(...parts, [options])

Joins URL parts into a single URL string.

parts

Type: string | number

URL parts to join. Non-string/non-numeric values are ignored.

options

Type: object

leadingSlash

Type: boolean | 'keep'
Default: true

  • true - Always add a leading slash
  • false - Never add a leading slash
  • 'keep' - Keep the leading slash if present in the input
trailingSlash

Type: boolean | 'keep'
Default: false

  • true - Always add a trailing slash
  • false - Never add a trailing slash
  • 'keep' - Keep the trailing slash if present in the input
protocolRelative

Type: boolean
Default: false

When true, treats // at the start as a protocol-relative URL (e.g., //cdn.example.com).

query

Type: Record<string, string | number | boolean | Array<string | number | boolean>>
Default: undefined

Query parameters to append to the URL. These are merged with any existing query string. Keys are sorted alphabetically in the output.

Testing

bun test

License

MIT