-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathuri.js.javascript.txt
83 lines (74 loc) · 5.29 KB
/
uri.js.javascript.txt
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
73
74
75
76
77
78
79
80
81
82
83
┏━━━━━━━━━━━━┓
┃ URI.JS ┃
┗━━━━━━━━━━━━┛
URIJS #require("URIjs") or web script (1.13.2)
#Like Node|DOM URL, but easier for modification, and more features.
#Quite big so consider using Node|DOM APIs instead, unless really needed.
URIJS([URL_STR]) #Returns URL_OBJ (def: location.href). Can be only part of the URL, e.g. QUERY
URIJS(ELEM) #Anything with href|src
URIJS(URL_OBJ) #Cloning. Can also URL_OBJ.clone()
URIJS.expand(STR, OBJ) #Same as URIJS(STR), but STR can contain {VAR}, expanded by OBJ
PARSED_URL_OBJ #Like URL_OBJ but as a plain object
#Has members protocol, username, password, hostname, port, part, query, fragment
URIJS(PARSED_URL_OBJ) #Returns URL_OBJ
URIJS.parse(URL_STR) #Returns PARSED_URL_OBJ
URIJS.build(PARSED_URL_OBJ) #Returns URL_STR
URIJS.buildPART(PARSED_URLOBJ)#Same but only returns part of URL_STR
#For QUERY, takes the QUERY OBJ directly
URL_OBJ.PART(STR) #Changes PART of URL, where PART is:
#SCHEME://USERNAME:PASSWORD@SUBDOMAIN.DOMAIN.TLD:PORT/DIRECTORY/FILENAME.SUFFIX?QUERY#[!]FRAGMENT
#SCHEME://USERINFO @SUBDOMAIN.DOMAIN :PORT/DIRECTOTY/FILENAME ?QUERY#[!]FRAGMENT
#SCHEME://USERINFO @HOSTNAME :PORT/PATH ?QUERY#[!]FRAGMENT
#SCHEME://USERINFO @HOST /RESOURCE
#SCHEME://AUTHORITY /RESOURCE
#HREF
#Where:
# - QUERY:
# - can use STR or OBJ. To get OBJ, use query(true)
# - can manipulates QUERY with:
# - addSearch(VAR, VAL)
# addSearch(OBJ)
# - removeSearch(VAR[, VAL])
# - hasSearch(VAR[, VAL|REGEXP|FUNC(VAL,VAR)->BOOL])
# - FRAGMENT:
# - can be OBJ (will look like a QUERY)
# - if another URL2, can be extracted as URL2_OBJ = URI_OBJ.fragment(true)
# (must load URI.fragmentURI.js)
# - can define URIJS|URI_OBJ.fragmentPrefix to change "!"
# - SCHEME: alias is PROTOCOL
# - PATH: alias is PATHNAME
# - SEGMENT[CODED]:
# - like DIRECTORY but using STR_ARR
# - can also use segment(NUM[, STR])
# - If "CODED", decodeURIComponent on getter, encodeURIComponent on setter
#Can parse URN:
# SCHEME:PATH?QUERY#FRAGMENT
URL_OBJ.PART() #Returns it
URL_OBJ.toString|valueOf() #Returns URL_OBJ.href(), e.g. URL_STR, so can be used as a STR.
URL_OBJ.normalize() #Do all normalize*()
URL_OBJ.normalizeProtocol() #Lowercase
URL_OBJ.normalizeHostname() # - lowercase
# - if PUNYCODE.* (can have client-side same as Node.js with Punycode.js), decodes it
# - if IPv6.js, removes leading 0 from IPv6 parts
URL_OBJ.normalizePort() #Removes default ports (based on URIJS.defaultPorts)
URL_OBJ.normalizePathname() #Removes extra .., ., etc.
URL_OBJ.normalizeQuery() #Erase bad & from QUERY: after ?, at the end and duplicates. Renoves trailing ?
URL_OBJ.normalizeHash() #Removes trailing #
URL_OBJ.iso8859|unicode() #
URL_OBJ.readable() #Does unicode() and Punycode encoding
URL_OBJ.encode|decode[Query]()#Like decode|encoreURIComponent() but encode() also escape also * and !
#If Query and URIJS.escapeQuerySpace is true, encode|decode spaces as +, not %20
URL_OBJ.withingString
(STR, FUNC(URL_STR)->STR2) #Returns STR, but after changing all auto-detected URL_STR to STR2
URL_OBJ.equals(URL2_STR) #Does not take into account case, default port, normalize paths, sort QUERY
ULR_OBJ.is("urn|url") #
URL_OBJ.is("domain|idn") #DOMAIN doesn't uses an IP [and has some non-alnum chars]
URL_OBJ.is("ip[v4|6") #DOMAIN uses an IP
URL_OBJ.is("punycode") #DOMAIN uses xn--
URL_OBJ.is("sld") #DOMAIN uses second level domain, e.g. "co.uk"
URL_OBJ.relativeTo(URL2_STR) #Returns absolute URL_OBJ as relative URL_STR, with relative path being resolved with URL2
#Don't forget trailing / for directories.
URL_OBJ.absoluteTo(URL2_STR) #Returns relative URL_OBJ as absolute URL_STR, with relative path being resolved with URL2
URLOBJ.is("relative|absolute")#
URL_OBJ.commonpath(URL_STR,
URL2_STR) #Returns URL3_STR ("" if none)