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

@arraypress/site-url

v1.0.0

Published

Build absolute and canonical URLs from a base — for SSR/SSG canonical links, OG image URLs, JSON-LD and sitemaps. Zero dependencies.

Readme

@arraypress/site-url

Build absolute and canonical URLs from a base — for SSR/SSG canonical links, OG image URLs, JSON-LD and sitemaps. Zero dependencies.

Works in Node.js, Cloudflare Workers, Deno, Bun, and browsers.

Install

npm install @arraypress/site-url

Why

In a static/SSR site you constantly need absolute URLs (canonical <link>, og:image, JSON-LD url/@id, sitemap entries). It's tempting to hand-roll them:

const origin = site?.toString().replace(/\/$/, '') ?? '';
const url = `${origin}${path}`; // brittle: no fallback, double-slash bugs

This package does it correctly with the WHATWG URL constructor, takes the base as an argument (so it's framework-agnostic), and falls back gracefully when the base is unset.

Functions

absUrl(path, base?, fallback?)

Resolve path to an absolute URL against base (falling back to fallback). If path is already absolute the base is ignored; if no base is resolvable, path is returned unchanged.

import { absUrl } from '@arraypress/site-url';

absUrl('/og.png', 'https://example.com')        // 'https://example.com/og.png'
absUrl('/x', 'https://example.com/')             // 'https://example.com/x'  (no double slash)
absUrl('https://cdn.test/i.png', 'https://x.com')// 'https://cdn.test/i.png' (already absolute)
absUrl('/x')                                     // '/x'  (no base → unchanged)

originOf(base?, fallback?)

The origin of base (scheme + host, no trailing slash), or '' if unresolvable.

import { originOf } from '@arraypress/site-url';

originOf('https://example.com/some/path')  // 'https://example.com'

joinUrl(base, ...segments)

Join a base and path segments with single slashes, skipping empty/nullish segments. No trailing slash is added.

import { joinUrl } from '@arraypress/site-url';

joinUrl('https://x.com/a/', '/b/', 'c')  // 'https://x.com/a/b/c'
joinUrl('/types', 'zodiac', 'leo')       // '/types/zodiac/leo'
joinUrl('/types/enneagram', 4)           // '/types/enneagram/4'

stripTrailingSlash(url) / ensureTrailingSlash(url)

Normalise trailing slashes for canonical URLs. ensureTrailingSlash leaves URLs with a query/hash untouched.

import { stripTrailingSlash, ensureTrailingSlash } from '@arraypress/site-url';

stripTrailingSlash('https://x.com/a/')   // 'https://x.com/a'
stripTrailingSlash('/')                  // '/'
ensureTrailingSlash('https://x.com/a')   // 'https://x.com/a/'

Use with Astro

Astro.site and Astro.url are only available inside .astro frontmatter, so pass them in. Use Astro.site as the base and Astro.url as the fallback, so URLs still resolve in dev/preview where site may be unset.

---
import { absUrl, originOf } from '@arraypress/site-url';

const path = Astro.url.pathname;
const canonical = absUrl(path, Astro.site, Astro.url);
const ogImage   = absUrl('/og/home.png', Astro.site, Astro.url);
const origin    = originOf(Astro.site, Astro.url);
---
<link rel="canonical" href={canonical} />
<meta property="og:image" content={ogImage} />

License

MIT © ArrayPress Limited