URL.js
Simple URL implementation of RFC #3986 for both NodeJS & browsers.
Installation
NPM
npm install unified-resource-locator
Bower
bower install unified-resource-locator
Usage
In Short...
var locator = "http://localhost:1234/a/b/c/resource?X=1&Y&Z=3#page=1"; locatorprotocol // "http"locatorhost // "localhost"locatorport // 1234locatorpath // "/a/b/c/resource"locatorquery// {X: "1", Y: "", Z: "3"}locatorfragment // "page=1" Stringlocator query: p: "San Francisco"// "https://search.yahoo.com/search?p=San%20Francisco" Stringlocator path: "/search/images" true// "https://search.yahoo.com/search/images?p=New%20York" Stringlocator query: null true// "https://search.yahoo.com/search"
API
URL
)
Constructor (URL objects can be constructed from raw locators, like:
"http://foo.bar-baz.com:80/p/a/t/h?q=u&e&r=y#fragment";"/p/a/t/h?q=u&e&r=y#fragment";"https://engine/search/?q=Earth";"http://fr.wikipedia.org/wiki/Sp%C3%A9cial:Page_au_hasard";"//en.wikipedia.org/wiki/URI_scheme#Generic_syntax";"redis://undefined:password@localhost:6379/0";"http://mickey@disney.com/#/house";
Also, you can complement the locators with specific parts if missing or completely overwrite some of them:
"https://engine/search" query: "q=Earth";"https://engine/search" query: q: "Solar System";"https://engine/search/?q=Earth" query: q: "Moon" true;
Finally, full control of URL parts is possible by providing them to the constructor without any text locator.
protocol: "http" "host": "server";host: "server";path: "/from/root";query: "A=1";
URL.pattern
)
Pattern (
URL.parts
)
Supported Parts (protocol
user
password
host
port
path
query
fragment
URL#parseQueryString
(string)
Guess what!..
URL#makeQueryString
(object)
Yes, you can!
More?
Have a look at the test suite! ;)
Workflow
npm test
for running tests;test/coverage.sh
for measuring code coverage.