metal-uri
Class for parsing and formatting URIs.
Use
After passing a URI as a string to the constructor, the individual components of the URI can be accessed and updated with the provided setters and getters.
Simple use case
; const uri = 'http://foo:8080'; uri; // 'foo'uri; // '8080'uri; // 'http:'
Updating values
const uri = 'http://foo:8080/path'; uri;uri;uri;uri; uri; // 'https://bar:81/login'
Handling query parameters
const uri = 'http://hostname?a=1&b=2'; uri; // '1'uri; // '2' uri;uri;uri; uri; // 'http://hostname/?b=x&c=y'uri; // '?b=x&c=y'
You can also set multiple values for one parameter.
const uri = 'http://hostname?a=1'; uri; uri; // 'http://hostname/?a=1&b=x&b=y'
Non-standard protocols
A default protocol is added automatically when none is provided. This default
value will either be http:
or https:
depending if you are on a secure
connection or not.
In order to use other protocols, you must instruct Uri
to not add a default
protocol by passing false
as the second argument.
const uri = 'tel:555-555-5555' false; uri; uri; // tel:/1-555-555-5555
Setup
-
Install a recent release of NodeJS if you don't have it yet.
-
Install local dependencies:
npm install
- Run the tests:
npm test
Contributing
Check out the contributing guidelines for more information.