Gathering detailed insights and metrics for relative-url-interface
Gathering detailed insights and metrics for relative-url-interface
npm install relative-url-interface
Typescript
Module System
Min. Node Version
Node Version
NPM Version
73.9
Supply Chain
98.9
Quality
75.2
Maintenance
100
Vulnerability
99.6
License
JavaScript (56.39%)
TypeScript (43.61%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
759
Last Day
2
Last Week
7
Last Month
45
Last Year
281
19 Stars
4 Commits
4 Watchers
1 Branches
5 Contributors
Updated on Jun 05, 2024
Minified
Minified + Gzipped
Latest Version
0.3.0
Package Id
relative-url-interface@0.3.0
Unpacked Size
141.98 kB
Size
35.30 kB
File Count
5
NPM Version
9.5.0
Node Version
18.15.0
Published on
Mar 14, 2023
Cumulative downloads
Total Downloads
Last Day
0%
2
Compared to previous day
Last Week
75%
7
Compared to previous week
Last Month
4,400%
45
Compared to previous month
Last Year
30.7%
281
Compared to previous year
URI is a URL interface that does not require a base URL. 1 2 3
1npm install relative-url-interface
1import URI from 'relative-url-interface' 2 3const uri = new URI('../assets/kitten.jpg') 4 5String(uri) // "../assets/kitten.jpg"
The URI
class extends URL
and can be used as a drop-in replacement. It is powered by spec-url
, and it is ideal for server-side code, pre-compiled code, or any situation where absolute URLs may not be known.
1import URI from 'relative-url-interface'
2
3const puppy_page = new URI('file://path/to/site/src/pages/puppy.astro')
4const kitty_image = URI.from('../assets/kitten.jpg')
5
6const absolute_kitten = new URI(kitty_image, puppy_page)
7
8fs.readFile(absolute_kitten, 'utf8') // contents of "file://path/to/site/src/assets/kitten.jpg"
The segments
property is an array of strings representing the path segments of the URL.
1const uri = new URI('https://un:pw@localhost:8080/path/to/asset.jpg?q=a#content')
2
3uri.segments // [ "path", "to", "asset.jpg" ]
1const uri = new URI('../to/asset.jpg') 2 3uri.segments // [ "..", "to", "asset.jpg" ]
The href
property is a string representing the whole URL, including any search parameters and fragment identifiers.
1const uri = new URI('https://un:pw@localhost:8080/path/to/asset.jpg?q=a#content')
2
3uri.href // "https://un:pw@localhost:8080/path/to/asset.jpg?q=a#content"
1const uri = new URI('../to/asset.jpg')
2
3uri.href // "../to/asset.jpg"
The protocol
property is a string representing the scheme of the URL, including the colon (:
) that proceeds it.
1const uri = new URI('https://un:pw@localhost:8080/path/to/asset.jpg?q=a#content')
2
3uri.protocol // "https:"
1const uri = new URI('../to/asset.jpg')
2
3uri.protocol // ""
The origin
property is a string representing the scheme, domain, and port of the URL. When present, the port is preceeded by a colon (:
).
1const uri = new URI('https://un:pw@localhost:8080/path/to/asset.jpg?q=a#content')
2
3uri.origin // "https://localhost:8080"
1const uri = new URI('../to/asset.jpg')
2
3uri.origin // ""
The host
property is a string representing the domain and port of the URL. When present, the port is preceeded by a colon (:
).
1const uri = new URI('https://un:pw@localhost:8080/path/to/asset.jpg?q=a#content')
2
3uri.host // "localhost:8080"
1const uri = new URI('../to/asset.jpg')
2
3uri.host // ""
The hostname
property is a string representing the domain of the URL.
1const uri = new URI('https://un:pw@localhost:8080/path/to/asset.jpg?q=a#content')
2
3uri.hostname // "localhost"
1const uri = new URI('../to/asset.jpg')
2
3uri.hostname // ""
The username
property is a string representing the username of the URL.
1const uri = new URI('https://un:pw@localhost:8080/path/to/asset.jpg?q=a#content')
2
3uri.username // "un"
1const uri = new URI('../to/asset.jpg')
2
3uri.username // ""
The password
property is a string representing the password of the URL.
1const uri = new URI('https://un:pw@localhost:8080/path/to/asset.jpg?q=a#content')
2
3uri.password // "pw"
1const uri = new URI('../to/asset.jpg')
2
3uri.password // ""
The port
property is a string representing the port of the URL.
1const uri = new URI('https://un:pw@localhost:8080/path/to/asset.jpg?q=a#content')
2
3uri.port // "8080"
1const uri = new URI('../to/asset.jpg')
2
3uri.port // ""
The pathname
property is a string representing the path of the URL, which does not include the origin, search parameters, or fragment identifiers.
1const uri = new URI('https://un:pw@localhost:8080/path/to/asset.jpg?q=a#content')
2
3uri.pathname // "/path/to/asset.jpg"
1const uri = new URI('../to/asset.jpg')
2
3uri.pathname // "../to/asset.jpg"
The search
property is a string representing the search parameters of the URL. When present, it is preceeded by a question mark (?
).
1const uri = new URI('https://un:pw@localhost:8080/path/to/asset.jpg?q=a#content')
2
3uri.search // "?q=a"
1const uri = new URI('../to/asset.jpg')
2
3uri.search // ""
The searchParams
property is a URLSearchParams
object representing the parsed search parameters of the URL.
1const uri = new URI('https://un:pw@localhost:8080/path/to/asset.jpg?q=a#content')
2
3uri.searchParams // URLSearchParams { 'q' => 'a' }
1const uri = new URI('../to/asset.jpg')
2
3uri.searchParams // URLSearchParams {}
The hash
property is a string representing the fragment identifier of the URL. When present, it is preceeded by a number sign (#
).
1const uri = new URI('https://un:pw@localhost:8080/path/to/asset.jpg?q=a#content')
2
3uri.hash // "#content"
1const uri = new URI('../to/asset.jpg')
2
3uri.hash // ""
The toString
method returns the whole URL as a string. It is a synonym for the href
getter property.
1new URI('../assets/kitten.jpg').toString() // "../assets/kitten.jpg"
The toJSON
method returns the whole URL as a string. It is a synonym for the href
getter property.
1new URI('../assets/kitten.jpg').toJSON() // "../assets/kitten.jpg"
The to
method returns a new URL resolved by the current URL.
1const kitten = new URI('../assets/kitten.jpg')
2
3String(kitten.to('puppy.jpg')) // "../assets/puppy.jpg"
The static from
method returns a new URI resolved by the current source.
1const kitten = new URI('../assets/kitten.jpg')
2
3String(kitten.to('puppy.jpg')) // "../assets/puppy.jpg"
URI contributes approximately 42kB of JavaScript when unminified, or 14kB when minified, or 6kB when minified and compressed.
Code original to this project is licensed under the CC0-1.0 License.
Code from spec-url is licensed under the The MIT License (MIT), Copyright Alwin Blok.
No vulnerabilities found.
No security vulnerabilities found.