Skip to main content

Easily navigate up URL paths to find a parent path.

Works with
It is unknown whether this package works with Bun
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Node.js
This package works with Deno
This package works with Browsers
JSR Score
100%
Published
2 months ago

upNlevels

upNlevels is a utility to simplify navigating up directory levels in a URL or file path.

Instead of manually constructing path strings like this:

// Using string concatenation
normalize(import.meta.url + "../../../").href;

// Or using the `new URL()` constructor for relative paths
new URL("../../", import.meta.url).href;

You can use upNlevels to navigate up directory levels more intuitively:

// Move up 2 levels with upNlevels
upNlevels(import.meta.url, 2).href;

This makes your code cleaner and easier to understand, especially when dealing with complex path manipulations.

Add Package

deno add @deer/upnlevels

Import symbol

import * as mod from "@deer/upnlevels";

Add Package

npx jsr add @deer/upnlevels

Import symbol

import * as mod from "@deer/upnlevels";

Add Package

yarn dlx jsr add @deer/upnlevels

Import symbol

import * as mod from "@deer/upnlevels";

Add Package

pnpm dlx jsr add @deer/upnlevels

Import symbol

import * as mod from "@deer/upnlevels";

Add Package

bunx jsr add @deer/upnlevels

Import symbol

import * as mod from "@deer/upnlevels";