relateurl

WebJar for relateurl

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

relateurl
Last Version

Last Version

0.2.7
Release Date

Release Date

Type

Type

jar
Description

Description

relateurl
WebJar for relateurl
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/stevenvachon/relateurl

Download relateurl

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/relateurl/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>relateurl</artifactId>
    <version>0.2.7</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/relateurl/
implementation 'org.webjars.npm:relateurl:0.2.7'
// https://jarcasting.com/artifacts/org.webjars.npm/relateurl/
implementation ("org.webjars.npm:relateurl:0.2.7")
'org.webjars.npm:relateurl:jar:0.2.7'
<dependency org="org.webjars.npm" name="relateurl" rev="0.2.7">
  <artifact name="relateurl" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='relateurl', version='0.2.7')
)
libraryDependencies += "org.webjars.npm" % "relateurl" % "0.2.7"
[org.webjars.npm/relateurl "0.2.7"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

relateurl NPM Version File Size Build Status Coverage Status Dependency Monitor

Create a relative URL with minify options.

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

Versions

Version
0.2.7
0.2.6