brembo 2.0.7 → 2.1.1

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.
Files changed (3) hide show
  1. package/README.md +10 -12
  2. package/index.js +10 -0
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -6,7 +6,7 @@ Example:
6
6
  import url from 'brembo';
7
7
  ```
8
8
 
9
- ```
9
+ ```js
10
10
  url.build("https://massimocandela.com", {
11
11
  path: ["example", "api", "v1"] // This can be a simple string too
12
12
  params: {
@@ -28,19 +28,17 @@ url.parse("https://massimocandela.com/example/api/data.json?a=1&a=2&b=3#here");
28
28
  ```
29
29
 
30
30
  It will return the following object:
31
- ```
31
+
32
+ ```js
32
33
  {
33
- path: ["example", "api"],
34
- filename: "data",
35
- format: "json",
36
- host: "massimocandela.com,
37
- port: "",
38
- searchParams: URLSearchParams,
39
- params: { "a": [1, 2], "b": 3 },
40
- hash: "here",
34
+ host: "massimocandela.com",
41
35
  protocol: "https",
42
- password: "",
43
- username: ""
36
+ path: ["example", "api", "v1"] // This can be a simple string too
37
+ params: {
38
+ a: 1,
39
+ b: 2
40
+ },
41
+ anchor: "here"
44
42
  }
45
43
  ```
46
44
 
package/index.js CHANGED
@@ -2,6 +2,7 @@ const build = function(base, options) {
2
2
  let urlOut = "";
3
3
  const params = options.params;
4
4
  let path = options.path;
5
+ const canonical = !!options.canonical;
5
6
  const anchor = options.anchor;
6
7
 
7
8
  const trimSlashes = function(str){
@@ -28,6 +29,15 @@ const build = function(base, options) {
28
29
 
29
30
  path = path.map(item => trimSlashes(item.toString().trim())).join("/");
30
31
 
32
+ if (canonical) {
33
+ const last = path.split("/").pop();
34
+ const isFile = last.includes(".");
35
+
36
+ if (!isFile) {
37
+ path = path + "/";
38
+ }
39
+ }
40
+
31
41
  if (path.length) {
32
42
  urlOut = trimSlashes(base).concat("/" + path.toString());
33
43
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "brembo",
3
- "version": "2.0.7",
3
+ "version": "2.1.1",
4
4
  "description": "A simple utility for building URLs",
5
5
  "main": "index.js",
6
6
  "scripts": {