-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathREADME
72 lines (52 loc) · 2.67 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
URI Type for javascript
====================================================
- Supports all kinds of URI (URL, URN, any scheme).
- Relative URI Resolution
- All classes extend the native String implementation.
- Pure ECMA-262 implementation of URI spec (RFC-3986)
- Works Client or Server side, (V8 / node.js compatible).
Usage:
var u = new URI('http://user:[email protected]/webr3/URI?query=string#this');
URI extends the native String implementation, so 'u' is a string, and you can call all the normal
String methods like u.indexOf(), u.match(), u.substr() and so forth.
In addition, URI exposes the following URI specific methods for reading parts of a URI (each of
which are strings themselves):
u.scheme(); -> 'http:'
u.heirpart(); -> '//user:[email protected]/webr3/URI'
u.heirpart().authority(); -> 'user:[email protected]'
u.heirpart().authority().userinfo(); -> 'user:pass'
u.heirpart().authority().host(); -> 'github.com'
u.heirpart().path(); -> '/webr3/URI'
u.querystring(); -> '?query=string'
u.fragment(); -> '#this'
Further, methods are exposed to handle complicated URIs:
u = new URI('http://github.com/a/b/c/d/../.././egg#s/../x');
u.isAbsolute(); -> boolean
u.defrag(); -> 'http://github.com/a/b/c/d/../.././egg'
u.toAbsolute(); -> 'http://github.com/a/b/egg'
and to resolve relative URIs + URI References:
u = new URI('http://github.com/a/b/c/d');
u.resolveReference('../.././n?x=y'); -> 'http://github.com/a/n?x=y'
node.js usage:
require('./uris'); // require the file, and no, you don't need 'var uri ='
var u = new URI('http://github.com/webr3/URI'); // nothing's different
running the tests:
URI.Test(); // be sure to include uristest first
Notes:
- I *may* add case normalisation for segments which support it..
- the file is called uris.js instead of uri.js because for some reason the line require('uri') makes
v8/node throw a wobbly..
- validation is out of scope, couldn't possibly implement validation for every scheme..
A few examples of some of the URIs supported:
- ftp://ftp.is.co.za/rfc/rfc1808.txt
- http://www.ietf.org:8080/rfc/rfc2396.txt
- ldap://[2001:db8::7]:140/c=GB?objectClass?one
- mailto:[email protected]
- news:comp.infosystems.www.servers.unix
- tel:+1-816-555-1212
- telnet://192.0.2.16/
- telnet://192.0.2.16:/
- telnet://192.0.2.16:80/
- urn:oasis:names:specification:docbook:dtd:xml:4.1.2
- svn+ssh://data.fm/opt/repos/ssl/trunk
- file:///dev/null