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

pathurl

v1.0.0

Published

Node.js path API but for URLs. Works everywhere.

Downloads

3

Readme

pathurl

Node.js path API but for URLs. Works on all runtimes and platforms.

Usage

All functions accept both a url string or a native URL object and always return a URL object wherever possible.

basename

Return the last portion of a url.

import { basename } from "pathurl";
basename("https://deno.land/std/assert/mod.ts"); // "mod.ts"
basename("https://deno.land/"); // "deno.land"

dirname

Return the parent directory url of a url path.

import { dirname } from "pathurl";
dirname("https://deno.land/std/assert/mod.ts");
// "https://deno.land/std/assert"

extname

Return the extension of a url.

import { extname } from "pathurl";
extname("https://deno.land/std/assert/mod.ts"); // ".ts"
extname("https://deno.land/") // ".land"

format

Generate a url from ParsedURL object.

import { format } from "pathurl";
format({
	dir: "https://deno.land/std/assert",
	base: "mod.ts"
}); // "https://deno.land/std/assert/mod.ts"

join

Join all given a sequence of url and paths, then normalizes the resulting url.

import { join } from "pathurl";
join("https://deno.land", "std", "assert", "mod.ts");
// "https://deno.land/std/assert/mod.ts"

normalize

Normalize a url, resolving '..' and '.' segments and extra '/'s (if any).

import { normalize } from "pathurl";
normalize("https://deno.land/std/assert//../async/retry.ts/");
// "https://deno.land/std/async/retry.ts/"

parse

Return a ParsedURL object of the url.

import { parse } from "pathurl";
parse("https://deno.land/std/assert/mod.ts");
// {
//     dir: "https://deno.land/std/assert",
//     root: "https://deno.land",
//     base: "mod.ts",
//     name: "mod",
//     ext: ".ts"
// }

relative

Return the relative url from from to to based on from as base url.

import { relative } from "pathurl";
relative("https://deno.land/std/assert/mod.ts", "./equal.ts");
// "https://deno.land/std/assert/equal.ts"

resolve

Resolve url and path segments into an absolute url.

import { resolve } from "pathurl";
resolve("https://deno.land", "std", "assert", "mod.ts", "../assert.ts");
// "https://deno.land/std/assert/assert.ts"

strip

Strips any hash (eg. #header) or search parameters (eg. ?foo=bar) from the provided URL.

(Mutates the original url provided)

import { strip } from "pathurl";
const url = new URL("https://deno.land/std/assert/mod.ts?foo=bar#header");
strip(url);
// url is now "https://deno.land/std/assert/mod.ts"

Building

  • Clone this repository.

  • Run tests and ensure that all pass along with 100% code coverage.

    bun test --coverage
  • Build the module and output in ./dist folder.

    bun run build

License

This repository uses MIT license. See LICENSE for full license text.