Tanchor The (anchor) URL parsing library
Fork me on Github! http://github.com/draeton/tanchor
Tanchor is a small utility library for working with URLs using the DOM's anchor element.
Implementation
Tanchor is a single-script utility.
<script src="js/tanchor-1.0.79-min.js"></script>
Documentation is available here. Unit tests are available here.
Usage
var a = new Tanchor("http://www.example.com?fruit=banana&pie=apple#page=1");
a.href(); // "http://www.example.com?fruit=banana&pie=apple#page=1";
a.search(); // "?fruit=banana&pie=apple"
a.hash(); // "#page=1"
a.getSearchVars(); // {"fruit": "banana", "pie": "apple"}
a.getHashVars(); // {"page": "1"}
a.setSearchVars({fruit: "pear", type: "test"});
a.href(); // "http://www.example.com/?fruit=pear&pie=apple&type=test#page=1"
a.setHashVars({page: 2});
a.href(); // "http://www.example.com/?fruit=pear&pie=apple&type=test#page=2"
a.setSearchVar("type", "live");
a.href(); // "http://www.example.com/?fruit=pear&pie=apple&type=live#page=2"
a.setHashVar("page", 3);
a.href(); // "http://www.example.com/?fruit=pear&pie=apple&type=live#page=3"
a.delSearchVar("type");
a.href(); // "http://www.example.com/?fruit=pear&pie=apple#page=3"
a.delHashVar("page");
a.href(); // "http://www.example.com/?fruit=pear&pie=apple#"
Contributing
- Fork the project.
- Read through the outstanding issues or report new ones.
- Write some tests to make sure we don't accidentally break each other's code.
- Send a pull request.
License
Download
The latest release, 1.0.79 is available here.
You can download this project in either zip or tar formats.
You can also clone the project with Git by running:
$ git clone git://github.com/draeton/tanchor