All Projects → stevenvachon → relateurl

stevenvachon / relateurl

Licence: MIT license
Create a relative URL with options to minify.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to relateurl

Universal Url
WHATWG URL for Node & Browser.
Stars: ✭ 20 (-61.54%)
Mutual labels:  url, whatwg
Url
URL Standard
Stars: ✭ 343 (+559.62%)
Mutual labels:  url, whatwg
mongoose-slug-updater
Schema-based slug plugin for Mongoose - single/compound - unique over collection/group - nested docs/arrays - relative/abs paths - sync on change: create/save/update/updateOne/updateMany/findOneAndUpdate tracked - $set operator - counter/shortId
Stars: ✭ 37 (-28.85%)
Mutual labels:  url
uri
A type to represent, query, and manipulate a Uniform Resource Identifier.
Stars: ✭ 16 (-69.23%)
Mutual labels:  url
deadlink
💀 Checks and fixes URLs in code and documentation.
Stars: ✭ 105 (+101.92%)
Mutual labels:  url
b23.wtf
Remove tracing parameters from b23.tv/*.
Stars: ✭ 85 (+63.46%)
Mutual labels:  url
1c http
Подсистема 1С для работы с HTTP
Stars: ✭ 48 (-7.69%)
Mutual labels:  url
UrlManager
Javascript class for getting and setting url parameters
Stars: ✭ 15 (-71.15%)
Mutual labels:  url
Odyssey
A piece of software that shows a traceroute of a URL redirect path
Stars: ✭ 41 (-21.15%)
Mutual labels:  url
immurl
🔗 A tiny immutable URL library, backed by the native whatwg URL.
Stars: ✭ 23 (-55.77%)
Mutual labels:  url
golgi
A composable routing library for Haxe.
Stars: ✭ 37 (-28.85%)
Mutual labels:  url
gravatar-url-generator
A fun and friendly generator of Gravatar urls.
Stars: ✭ 44 (-15.38%)
Mutual labels:  url
seenreq
Generate an object for testing if a request is sent, request is Mikeal's request.
Stars: ✭ 42 (-19.23%)
Mutual labels:  url
url
Build and parse URLs. Useful for HTTP and "routing" in single-page apps (SPAs)
Stars: ✭ 69 (+32.69%)
Mutual labels:  url
url-trailing-slash
Allows enforcing URL routes with or without trailing slash
Stars: ✭ 35 (-32.69%)
Mutual labels:  url
MinifyAllCli
📦 A lightweight, simple and easy npm tool to 𝗺𝗶𝗻𝗶𝗳𝘆 JSON/C, HTML and CSS! Also known as MinifyAll core! ⭐ Usable as 𝑪𝑳𝑰 tool or 𝒊𝒎𝒑𝒐𝒓𝒕𝒂𝒃𝒍𝒆 in TS/JS as a 𝑴𝑶𝑫𝑼𝑳𝑬 🥰
Stars: ✭ 21 (-59.62%)
Mutual labels:  minify
url-regex-safe
Regular expression matching for URL's. Maintained, safe, and browser-friendly version of url-regex. Resolves CVE-2020-7661 for Node.js servers.
Stars: ✭ 59 (+13.46%)
Mutual labels:  url
LaraOutPress
This is simply compress your final out of Larvel Application and serve to the browser.
Stars: ✭ 56 (+7.69%)
Mutual labels:  minify
link text
Easy to use text widget for Flutter apps, which converts inlined urls into working, clickable links
Stars: ✭ 20 (-61.54%)
Mutual labels:  url
webidl
Web IDL Standard
Stars: ✭ 296 (+469.23%)
Mutual labels:  whatwg

relateurl NPM Version File Size Build Status Coverage Status Dependency Monitor

Create a relative URL with options to minify.

With http://domain.com/seg1/seg1-1/ as a base URL, you can produce:

Before After
http://domain.com/seg1/seg1-2/index.html ../seg1-2/
http://domain.com/seg2/seg2-1/ /seg2/seg2-1/
http://domain.com/seg1/seg1-1/
httpS://domain.com/seg1/seg1-1/ https://domain.com/seg1/seg1-1/
../../../../../../../../#anchor /#anchor

Installation

Node.js >= 14 is required. To install, type this at the command line:

npm install relateurl

Usage

Inputs must be URL instances.

const relateURL = require('relateurl');

const base = new URL('http://domain.com/seg1/seg1-1/');
const url  = new URL('//domain.com/seg1/seg1-2/index.html', base);

relateURL(url, base, options);
//-> ../seg1-2/

Options

It is simplest to use an option profile, but custom configurations are still possible.

output

Type: Symbol
Default value: relateURL.SHORTEST
The limit of how far the resulting URL should be related. Possible values:

  • PROTOCOL_RELATIVE: will try to produce something like //domain.com/path/to/file.html.
  • ROOT_PATH_RELATIVE: will try to produce something like /child-of-root/etc/.
  • PATH_RELATIVE: will try to produce something like ../child-of-parent/etc/.
  • SHORTEST: will try to choose whichever is shortest between PATH_RELATIVE and ROOT_PATH_RELATIVE.

Minify Options

Any other defined option will be passed to minurl. Avoid setting stringify to false, as it will prevent any operations performed by this library from being outputted.

Ignoring Basic Authentication

Ignoring a URL's username and password attributes will need the not-so-obvious removeAuth option (from minurl):

const base = new URL('http://user:[email protected]/seg1/seg1-1/');
const url  = new URL('http://domain.com/seg1/seg1-2/');

relateURL(url, base, {
  removeAuth: true
});
//-> ../seg1-2/

Option Profiles

There're two profiles: CAREFUL_PROFILE and COMMON_PROFILE.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].