-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpath.js
99 lines (82 loc) · 1.52 KB
/
path.js
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
/*!
* Path.js - Simple Javascript path management library
* (c) 2014 Jason Lavorante
* MIT Licensed.
*
* https://github.com/jasonlav/path-js
*/
function Path(config) {
this.config = config;
this.config.tags = Tags.get(this.config.tags, config);
this.config.prefixes = Tags.get(this.config.prefixes, config);
}
/**
* URL
*/
Path.prototype.url = function(url) {
//Array
if(typeof url === "object") {
for(var key in url) {
url[key] = this.url(url[key]);
}
return url;
}
//Base
if(url === "/") {
url = "";
}
//Raw
var raw = url;
//Ignore
if(this.ignore(url)) {
return url;
}
//Keywords
url = Tags.get(url, this.config.tags);
//Prefix
url = this.prefix(url);
if(url === raw) {
return this.clean(this.config.base+url);
} else {
return this.clean(url);
}
};
/**
* HTML
*/
Path.prototype.html = function(html, strip) {
if(typeof strip !== "boolean") {
strip = false;
}
return Tags.get(html, this.config.tags, strip);
};
/**
* Ignore
*/
Path.prototype.ignore = function(path) {
for(var key in this.config.ignorePrefixes) {
var ignore = this.config.ignorePrefixes[key];
if(path.substr(0, ignore.length) === ignore) {
return true;
}
}
return false;
};
/**
* Prefix
*/
Path.prototype.prefix = function(path) {
for(var key in this.config.prefixes) {
var prefix = this.config.prefixes[key];
if(path.substr(0, key.length) === key) {
return prefix+path.substr(key.length, 9999);
}
}
return path;
};
/**
* Clean
*/
Path.prototype.clean = function(path) {
return path;
};