JSPM

@loxjs/url-join

1.0.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 9397
  • Score
    100M100P100Q136320F
  • License MIT

Join urls and normalize as in path.join.

Package Exports

  • @loxjs/url-join
  • @loxjs/url-join/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@loxjs/url-join) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

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

npm install @loxjs/url-join

or

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

Enjoy using @loxjs/url-join!