ag-common 0.0.141 → 0.0.142
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.
|
@@ -39,6 +39,9 @@ function trimSide(str, fromStart = true, ...params) {
|
|
|
39
39
|
}
|
|
40
40
|
exports.trimSide = trimSide;
|
|
41
41
|
function trim(str, ...params) {
|
|
42
|
+
if (!str) {
|
|
43
|
+
return '';
|
|
44
|
+
}
|
|
42
45
|
str = trimSide(str, true, ...params);
|
|
43
46
|
str = trimSide(str, false, ...params);
|
|
44
47
|
return str;
|
|
@@ -149,6 +152,9 @@ exports.chunkString = chunkString;
|
|
|
149
152
|
*/
|
|
150
153
|
function stringToObject(raw, splitKeyValue, splitKeys) {
|
|
151
154
|
const ret = {};
|
|
155
|
+
if (!stringToObject) {
|
|
156
|
+
return ret;
|
|
157
|
+
}
|
|
152
158
|
raw.split(splitKeys).forEach((set) => {
|
|
153
159
|
const [k, v] = set.split(splitKeyValue);
|
|
154
160
|
ret[k] = v;
|
|
@@ -62,3 +62,15 @@ export interface IStateCommon<TRequest extends IRequestCommon> extends IInitialS
|
|
|
62
62
|
*/
|
|
63
63
|
cookieDocument: string | undefined;
|
|
64
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* get parsed url. will use window if possible
|
|
67
|
+
* @param param0
|
|
68
|
+
* @returns
|
|
69
|
+
*/
|
|
70
|
+
export declare const getClientOrServerReqHref: ({ href }: {
|
|
71
|
+
href?: string | undefined;
|
|
72
|
+
}) => LocationSubset;
|
|
73
|
+
export declare const getClientOrServerReq: ({ host, pathname, }: {
|
|
74
|
+
pathname: string;
|
|
75
|
+
host: string;
|
|
76
|
+
}) => LocationSubset;
|
|
@@ -1,2 +1,53 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getClientOrServerReq = exports.getClientOrServerReqHref = void 0;
|
|
4
|
+
const url_1 = require("url");
|
|
5
|
+
const string_1 = require("../../common/helpers/string");
|
|
6
|
+
const calculateServerHref = ({ host, pathname, }) => {
|
|
7
|
+
if (!host) {
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
10
|
+
let href = '';
|
|
11
|
+
if (host.includes('localhost')) {
|
|
12
|
+
href += 'http://';
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
href += 'https://';
|
|
16
|
+
}
|
|
17
|
+
href += host + pathname;
|
|
18
|
+
return href;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* get parsed url. will use window if possible
|
|
22
|
+
* @param param0
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
const getClientOrServerReqHref = ({ href }) => {
|
|
26
|
+
if (typeof window !== 'undefined') {
|
|
27
|
+
href = window.location.href;
|
|
28
|
+
}
|
|
29
|
+
if (!href) {
|
|
30
|
+
throw new Error('no href');
|
|
31
|
+
}
|
|
32
|
+
const parsed = (0, url_1.parse)(href);
|
|
33
|
+
const ret = {
|
|
34
|
+
hash: parsed.hash || '',
|
|
35
|
+
host: parsed.host || '',
|
|
36
|
+
origin: `${parsed.protocol}//${parsed.host}`,
|
|
37
|
+
href: `${parsed.protocol}//${parsed.host}${parsed.path}${parsed.hash || ''}`,
|
|
38
|
+
path: `${parsed.path}${parsed.hash || ''}`,
|
|
39
|
+
pathname: parsed.pathname || '',
|
|
40
|
+
protocol: parsed.protocol || '',
|
|
41
|
+
query: (0, string_1.stringToObject)(parsed.query || '', '=', '&'),
|
|
42
|
+
};
|
|
43
|
+
return ret;
|
|
44
|
+
};
|
|
45
|
+
exports.getClientOrServerReqHref = getClientOrServerReqHref;
|
|
46
|
+
const getClientOrServerReq = ({ host, pathname, }) => {
|
|
47
|
+
const href = calculateServerHref({
|
|
48
|
+
host,
|
|
49
|
+
pathname,
|
|
50
|
+
});
|
|
51
|
+
return (0, exports.getClientOrServerReqHref)({ href });
|
|
52
|
+
};
|
|
53
|
+
exports.getClientOrServerReq = getClientOrServerReq;
|