Socket
Book a DemoInstallSign in
Socket

fast-url

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fast-url

A folk version of the `urlcat` library focus on performance and simplicity.

latest
Source
npmnpm
Version
6.0.2
Version published
Maintainers
1
Created
Source

fast-url NPM Downloads JSR

A folk version of the urlcat focuses on performance and simplicity. Build correct URLs easily. A fast, minimal fork of urlcat focused on performance and simplicity.

Test codecov Quality Gate Status Bundle Size CodSpeed

fast-url is a tiny JavaScript/TypeScript library that makes building URLs convenient and prevents common mistakes.

Features

  • Lightweight: Only one dependency (fast-querystring) and minimal bundle size
  • Type safe: Written in TypeScript with full type definitions
  • URL safe: Automatically escapes parameters and handles edge cases
  • Unicode-aware: Uses codePointAt for proper Unicode handling, including graceful encoding of lone surrogates
  • Flexible: Multiple ways to build URLs for different use cases

Installation

# Using JSR (recommended for Deno)
deno add jsr:@hckhanh/fast-url

# Using bun
bun add fast-url

# Using npm
npm install fast-url

Usage

Basic usage example Basic usage example (dark mode)

Basic URL building

import { createUrl } from "fast-url";

// Path parameters
createUrl("https://api.example.com", "/users/:id", { id: 123 });
// → 'https://api.example.com/users/123'

// Query parameters
createUrl("https://api.example.com", "/users", { limit: 10, offset: 20 });
// → 'https://api.example.com/users?limit=10&offset=20'

// Combined path and query parameters
createUrl("https://api.example.com", "/users/:id/posts", { id: 123, limit: 10 });
// → 'https://api.example.com/users/123/posts?limit=10'

CommonJS

const { createUrl } = require("fast-url");

Utility functions

import { query, subst, join } from "fast-url";

// Build query strings
query({ name: "John", age: 30 });
// → 'name=John&age=30'

// Substitute path parameters
subst("/users/:id/posts/:postId", { id: 123, postId: 456 });
// → '/users/123/posts/456'

// Join URL parts
join("https://api.example.com/", "/", "/users");
// → 'https://api.example.com/users'

API

createUrl(baseUrl, pathTemplate, params?)

Build a complete URL by combining a base URL, path template, and parameters.

createUrl(baseTemplate, params)

Use a single template containing path parameters; unused params become query parameters.

query(params)

Build a query string from an object of key-value pairs.

subst(template, params)

Substitute path parameters in a template string.

join(part1, separator, part2)

Join two URL parts with exactly one separator.

Why fast-url?

Building URLs manually is error-prone:

// ❌ Error-prone manual approach
const url = `${baseUrl}/users/${id}/posts?limit=${limit}&offset=${offset}`;
// Issues: double slashes, unescaped parameters, complex concatenation
// ✅ Clean and safe with fast-url
const url = createUrl(baseUrl, "/users/:id/posts", { id, limit, offset });

fast-url handles:

  • Automatic parameter escaping
  • Proper URL segment joining
  • Clean separation of path and query parameters

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT

Keywords

url

FAQs

Package last updated on 12 Nov 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts