# @loxjs/url-join

> Join urls and normalize as in path.join.

Latest version **1.0.2** (published 2024-03-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install @loxjs/url-join
pnpm add @loxjs/url-join
yarn add @loxjs/url-join
bun add @loxjs/url-join
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2024-03-06 |
| First published | 2024-03-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Zen Li |
| Maintainers | galendai, zencode |
| Keywords | url, join, path, link |

## Links

- npm: https://www.npmjs.com/package/@loxjs/url-join
- Repository: https://github.com/loxjs/mono
- Homepage: https://github.com/loxjs/mono/tree/main/packages/url-join#readme
- Issues: https://github.com/loxjs/mono/issues
- npm.io page: https://npm.io/package/@loxjs/url-join

## 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

- 1.0.2 (latest) — 2024-03-06
- 1.0.1 — 2024-03-06
- 1.0.0 — 2024-03-06

## README

# @loxjs/url-join

`@loxjs/url-join` is a Node.js utility module that allows for the concatenation of URL segments into a single, normalized URL. It is a fork of the original [url-join](https://github.com/jfromaniello/url-join) module, modified to support `require` in addition to `import` for module inclusion, making it more accessible for a wider range of Node.js projects.

## Installation

To install the module, use npm or yarn as follows:

```sh
npm install @loxjs/url-join
```

or

```sh
yarn add @loxjs/url-join
```

## Usage

To use this module in your project, simply require it and then call the `urlJoin` function with the URL segments you want to join together:

```
const urlJoin = require('@loxjs/url-join');

const myUrl = urlJoin('http://example.com', 'path', 'to', 'resource');
console.log(myUrl);
// Output: http://example.com/path/to/resource
```

## Examples

Joining URL segments with query parameters:

```
const myUrl = urlJoin('http://example.com', 'search', '?query=node');
// Output: http://example.com/search?query=node
```

Handling trailing slashes:

```
const myUrl = urlJoin('http://example.com/', '/about/');
// Output: http://example.com/about/
```

Support for file protocol:

```
const myUrl = urlJoin('file:///', 'usr', 'local', 'bin');
// Output: file:///usr/local/bin
```

## Acknowledgements

We would like to express our gratitude to the author and contributors of the original [url-join](https://github.com/jfromaniello/url-join) module. `@loxjs/url-join` is built upon the solid foundation they provided, and this modification would not have been possible without their groundwork.

## Features

 - Normalizes URL paths by removing redundant slashes.
 - Correctly handles protocols and slashes specific to file URLs.
 - Supports both `require` and `import` statements for module inclusion.
 - Manages trailing slashes and query parameters in a URL.
 - Throws informative errors for non-string URL segments.

## API

### urlJoin(...args)

Joins all given URL segments and normalizes the result.

Arguments:

 - `...args` (String[]): An array of strings representing each segment of the URL.

Returns:

 - String: A string of the normalized URL.


## Contributing

Contributions to `@loxjs/url-join` are welcome! Please ensure that your contributions adhere to the following guidelines:

 - Write clear, readable, and maintainable code.
 - Follow existing coding styles and practices.
 - Write meaningful commit messages.
 - Update the documentation accordingly.

For more detailed information, please read the [contributing guide](https://github.com/loxjs/mono/CONTRIBUTING.md).

Enjoy using `@loxjs/url-join`!

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