@8ms/helpers 2.0.1 → 2.0.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/.yarn/install-state.gz +0 -0
- package/package.json +1 -1
- package/url/index.d.ts +12 -1
- package/url/index.js +9 -7
package/.yarn/install-state.gz
CHANGED
|
Binary file
|
package/package.json
CHANGED
package/url/index.d.ts
CHANGED
|
@@ -12,8 +12,19 @@ export declare const isAbsolute: (input: string) => boolean;
|
|
|
12
12
|
* Does the URL begin with a slash.
|
|
13
13
|
*/
|
|
14
14
|
export declare const isRelative: (input: string) => boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Take an object and return the parameter for a given URL irrespective of path.
|
|
17
|
+
*/
|
|
18
|
+
export declare const buildParameters: (existing?: object, updated?: object) => string;
|
|
19
|
+
/**
|
|
20
|
+
* Create a new relative URL based on the current path.
|
|
21
|
+
*/
|
|
22
|
+
export declare const buildRelative: ({ router, updated }: {
|
|
23
|
+
router: any;
|
|
24
|
+
updated: object;
|
|
25
|
+
}) => string;
|
|
15
26
|
/**
|
|
16
27
|
* Get the current base url.
|
|
17
28
|
*/
|
|
18
|
-
export declare const
|
|
29
|
+
export declare const buildEnvironmentUrl: (path: string, url: EnvironmentUrl) => string;
|
|
19
30
|
export { writeUrlContents } from "./writeUrlContents";
|
package/url/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.writeUrlContents = exports.
|
|
6
|
+
exports.writeUrlContents = exports.buildEnvironmentUrl = exports.buildRelative = exports.buildParameters = exports.isRelative = exports.isAbsolute = void 0;
|
|
7
7
|
const environment_1 = require("../environment");
|
|
8
8
|
const merge_1 = __importDefault(require("lodash/merge"));
|
|
9
9
|
/**
|
|
@@ -28,28 +28,30 @@ exports.isRelative = isRelative;
|
|
|
28
28
|
/**
|
|
29
29
|
* Take an object and return the parameter for a given URL irrespective of path.
|
|
30
30
|
*/
|
|
31
|
-
const buildParameters = ({
|
|
31
|
+
const buildParameters = (existing = {}, updated = {}) => {
|
|
32
32
|
const merged = (0, merge_1.default)(existing, updated);
|
|
33
|
-
let response =
|
|
33
|
+
let response = "";
|
|
34
34
|
if (Object.values(merged).length) {
|
|
35
35
|
for (const key in merged) {
|
|
36
36
|
const value = undefined === updated[key] ? existing[key] : updated[key];
|
|
37
|
-
response +=
|
|
37
|
+
response += "" === response ? "?" : "&";
|
|
38
38
|
response += `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
return response;
|
|
42
42
|
};
|
|
43
|
+
exports.buildParameters = buildParameters;
|
|
43
44
|
/**
|
|
44
45
|
* Create a new relative URL based on the current path.
|
|
45
46
|
*/
|
|
46
47
|
const buildRelative = ({ router, updated }) => {
|
|
47
|
-
return `${router.pathname}${buildParameters({ existing: router.query, updated: updated || {} })}`;
|
|
48
|
+
return `${router.pathname}${(0, exports.buildParameters)({ existing: router.query, updated: updated || {} })}`;
|
|
48
49
|
};
|
|
50
|
+
exports.buildRelative = buildRelative;
|
|
49
51
|
/**
|
|
50
52
|
* Get the current base url.
|
|
51
53
|
*/
|
|
52
|
-
const
|
|
54
|
+
const buildEnvironmentUrl = (path, url) => {
|
|
53
55
|
let response;
|
|
54
56
|
if ((0, environment_1.isDevelopment)() && (0, environment_1.isLocalhost)()) {
|
|
55
57
|
response = url.localhost;
|
|
@@ -65,6 +67,6 @@ const buildUrl = (path, url) => {
|
|
|
65
67
|
}
|
|
66
68
|
return response + path || "";
|
|
67
69
|
};
|
|
68
|
-
exports.
|
|
70
|
+
exports.buildEnvironmentUrl = buildEnvironmentUrl;
|
|
69
71
|
var writeUrlContents_1 = require("./writeUrlContents");
|
|
70
72
|
Object.defineProperty(exports, "writeUrlContents", { enumerable: true, get: function () { return writeUrlContents_1.writeUrlContents; } });
|