Makes creating, reading and editing urls easy in Javascript
Pull request Compare This branch is 1 commit behind theozaurus:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
config
spec/javascripts
src
.gitignore
Gemfile
Gemfile.lock
LICENSE
README.mdown
Rakefile

README.mdown

Description

This is a small library designed to make dealing with URLs in Javascript easier.

Examples

var url = new JSUrlify('https://foo.com/hello?one=1&two=2#bar')
url.scheme()
-> "https"

url.scheme("http")
-> "http"

url.toString()
-> "http://foo.com/hello?one=hello+%26+goodbye&two=2#bar"

url.authority()
-> "foo.com"

url.path()
-> "/hello"

url.attribute_names()
-> ["one", "two"]

url.one
-> "1"

url['one']
-> "1"

url.two
-> "2"

url['two']
-> "2"

url.fragment
-> "bar"

url.one = "hello & goodbye"
-> "hello & goodbye"

url.toString()
-> "http://foo.com/hello?one=hello+%26+goodbye&two=2#bar"

url['three'] = 3
-> 3

url.toString()
-> "http://foo.com/hello?one=hello+%26+goodbye&two=2&three=3#bar"

url.prepend("zero",0)

url.toString()
-> new 

url.remove("three")
-> "3"

url.toString()
-> "http://foo.com/hello?one=hello+%26+goodbye&two=2#bar"

url.append("z","zee")

url.toString()
-> "http://foo.com/hello?one=hello+%26+goodbye&two=2&z=zee#bar"

url.query({abc: 123, fraggle: "rock"})

url.toString()
-> "http://foo.com/hello?abc=123&fraggle=rock#bar"

url.query("a=b&c=d")

url.toString()
-> "http://foo.com?a=b&c=d#bar"

url.clear_fragment()

url.toString()
-> "http://foo.com/hello?a=b&c=d"

url.clear_query()

url.toString()
-> "http://foo.com/hello"

url.clear_scheme()

url.toString()
-> "/hello"

url.scheme("http")

url.toString()
-> "http://foo.com/hello"

url.clear_path()
-> "http://foo.com"

url.go()
// Changes browser location

Supported Browsers

Currently the test suite is run against:

  • Firefox 2.0
  • Firefox 3.0
  • Firefox 3.5
  • Firefox 3.6
  • Firefox 4.0
  • Google Chrome
  • Safari 3
  • Safari 4
  • Safari 5
  • Opera 9
  • Opera 10
  • Opera 11
  • IE 8

Currently Internet Explorer 6 and 7 are not supported. IE9 should work fine, but has not been built into the automated testing.

Testing

Testing is done using Jasmine, with Ruby used to help automate things.

Setup

  • Install Ruby
  • Install Bundler

    $ gem install bundler
    
  • Install Gems with Bundler

    $ cd jsurlify
    $ bundle install
    

Running locally

To run the tests on a browser that is local to your machine

  $ cd jsurlify
  $ rake jasmine

Then open your local browser to http://localhost:8888

Running at Saucelabs

You will need an account at Saucelabs then run:

$ cd jsurlify
$ SAUCE_USERNAME=<YOUR USERNAME> SAUCE_ACCESS_KEY=<YOUR ACCESS KEY> rake jasmine:ci:sauce