brembo 2.1.1 → 2.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +18 -21
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,46 +1,43 @@
|
|
|
1
1
|
const build = function(base, options) {
|
|
2
2
|
let urlOut = "";
|
|
3
3
|
const params = options.params;
|
|
4
|
-
let path = options.path;
|
|
4
|
+
let path = options.path || [];
|
|
5
5
|
const canonical = !!options.canonical;
|
|
6
6
|
const anchor = options.anchor;
|
|
7
7
|
|
|
8
8
|
const trimSlashes = function(str){
|
|
9
9
|
|
|
10
|
-
if (str
|
|
10
|
+
if (str == null || str === "") {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
str = str.toString().trim();
|
|
15
|
+
|
|
16
|
+
if (str[str.length - 1] === "/") {
|
|
11
17
|
str = str.slice(0, str.length - 1);
|
|
12
18
|
}
|
|
13
19
|
|
|
14
|
-
if (str[0]
|
|
20
|
+
if (str[0] === "/") {
|
|
15
21
|
str = str.slice(1, str.length);
|
|
16
22
|
}
|
|
17
23
|
|
|
18
24
|
return str;
|
|
19
25
|
};
|
|
20
26
|
|
|
21
|
-
if (
|
|
22
|
-
|
|
27
|
+
if (typeof(path) === "string") {
|
|
28
|
+
path = path.split("/");
|
|
23
29
|
}
|
|
24
30
|
|
|
25
|
-
|
|
26
|
-
if (typeof path == "string") {
|
|
27
|
-
path = [path];
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
path = path.map(item => trimSlashes(item.toString().trim())).join("/");
|
|
31
|
+
path = [base || ""].concat(path).map(trimSlashes).filter(i => !!i);
|
|
31
32
|
|
|
32
|
-
|
|
33
|
-
const last = path.split("/").pop();
|
|
34
|
-
const isFile = last.includes(".");
|
|
33
|
+
urlOut = path.join("/");
|
|
35
34
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
35
|
+
if (canonical && !path[path.length - 1].includes(".")) { // Not a file
|
|
36
|
+
urlOut = urlOut + "/";
|
|
37
|
+
}
|
|
40
38
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
39
|
+
if (!base || base === "/") {
|
|
40
|
+
urlOut = "/" + urlOut;
|
|
44
41
|
}
|
|
45
42
|
|
|
46
43
|
if (params){
|