# to-absolute-url

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

Latest version **0.0.5** (published 2021-02-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install to-absolute-url
pnpm add to-absolute-url
yarn add to-absolute-url
bun add to-absolute-url
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.5 |
| Published | 2021-02-23 |
| First published | 2018-08-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 4.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Yair |
| Maintainers | yairopro |
| Keywords | resolve, url, relative, absolute |

## Links

- npm: https://www.npmjs.com/package/to-absolute-url
- Repository: https://github.com/yairopro/to-absolute-url
- Homepage: https://github.com/yairopro/to-absolute-url#readme
- Issues: https://github.com/yairopro/to-absolute-url/issues
- npm.io page: https://npm.io/package/to-absolute-url

## Dependencies (1)

- [stacktrace-js](https://npm.io/package/stacktrace-js.md) ^2.0.2

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 0.0.5 (latest) — 2021-02-23
- 0.0.4 — 2021-01-09
- 0.0.3 — 2018-10-16
- 0.0.2 — 2018-08-12
- 0.0.1 — 2018-08-12
- 0.0.0 — 2018-08-12

## README

# toAbsoluteUrl
A function to resolve relative paths to absolute urls (using [stacktrace.js](https://www.stacktracejs.com/) & native URL module).

#### Instalation
````javascript
import toAbsoluteUrl from "to-absolute-url"
````

#### Usage

###### Get absolute url of current file
````javascript
// 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
````javascript
// 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.
````javascript
// 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"
````

---
_Source: https://npm.io/package/to-absolute-url · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
