-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathurihandler.common.ts
130 lines (118 loc) · 2.91 KB
/
urihandler.common.ts
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
export interface SchemeObject{
uri: string,
scheme: string,
path: string,
fragment: string,
query: string,
host: string,
user?: string,
password?: string
}
/**
* Class URIHandler
* The class can be injected into Angular class
* @module SchemeHandler
* @example
* import { URIHandler } from 'tns-ng-urihandler';
*
* export class myApp{
* constructor(private urihandler: URIHandler){
* console.log(this.uriHandler.getURI());
* }
* }
*/
export class _URIHandler{
public uri: string;
public scheme: string;
public path: string;
public query: string;
public fragment: string;
public host: string;
public user: string;
public password: string;
private _getSearch(query: string){
if(query === null || query.length == 0){
return {};
}
let _queries = query.split('&');
let search = {};
_queries.forEach(q=>{
let _qs = q.split('=');
search[_qs[0]] = _qs[1] ? _qs[1] : null
})
return search;
}
/**
* @function getURI
* @return {string} Full uri path
*/
getURI(): string{
return this.uri;
}
/**
* @function getFragment
* @return {string} the fragment of uri if there's any
* @example
* myapp://host:8080/path/to/my/directory#home-page // return "home-page"
*/
getFragment(): string{
return this.fragment;
}
/**
* @function getScheme
* @return {string} the scheme of uri
* @example
* myapp://host:8080/path/to/my/directory // return "myapp"
*/
getScheme(): string{
return this.scheme;
}
/**
* @function getQuery
* @return {string} the queries of uri
* @example
* myapp://host:8080/path/to/my/directory?name=Bob // return "name=Bob"
*/
getQuery(): string{
return this.query;
}
/**
* @function getPath
* @return {string} the path of uri
* @example
* myapp://host:8080/path/to/my/directory?name=Bob // return "path/to/my/directory"
*/
getPath(): string{
return this.path;
}
/**
* @function getHost
* @return {string} the host of uri
* @example
* myapp://host:8080/path/to/my/directory?name=Bob // return "host"
*/
getHost(): string{
return this.host;
}
/**
* @function getUser
* @return {string} the user info of uri if any
* @example
* myapp://Alice@host:8080/path/to/my/directory?name=Bob // return "Alice"
*/
getUser(): string{
return this.user;
}
/**
* @function getPassword
* @return {string} the password of uri if any
* @example
* myapp://Alice:Passw0rd@host:8080/path/to/my/directory?name=Bob // return "Passw0rd"
*/
getPassword(): string{
return this.password;
}
search(): any{
return this._getSearch( this.query );
}
}