Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

to-absolute-url

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

to-absolute-url

A function to resolve relative paths from current script's url to absolute urls.

latest
Source
npmnpm
Version
0.0.5
Version published
Maintainers
1
Created
Source

toAbsoluteUrl

A function to resolve relative paths to absolute urls (using stacktrace.js & native URL module).

Instalation

import toAbsoluteUrl from "to-absolute-url"

Usage

Get absolute url of current file
// https://domaine-name.com/path/to/module.js
toAbsoluteUrl() // returns "https://domaine-name.com/path/to/module.js"
Get absolute url of a relative path
// https://domaine-name.com/dir/dir1/module1.js
toAbsoluteUrl("../dir2/module2.js") // returns "https://domaine-name.com/dir/dir2/module2.js"
toAbsoluteUrl("../dir2/module2.js", /*depth*/ 0) // idem
Get absolute url of a relative path from the caller function

Useful when you create modules which receive relative path as parameter.

// https://domaine-name.com/dir/dir1/whereAmI.js
export default function whereAmI(){
    let callerUrl = toAbsoluteUrl(null, 1 /*Depth in the stacktrace. Default value : 0.*/);
    console.log("You a running at " + callerUrl);
}


// https://domaine-name.com/index.js
import whereAmI from "./dir/dir1/whereAmI.js"
whereAmI(); // logs "You are running at https://domaine-name.com/index.js"

Keywords

resolve

FAQs

Package last updated on 23 Feb 2021

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