asma-helpers 0.4.0 → 0.4.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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSubdomain.d.ts","sourceRoot":"","sources":["../../src/helpers/getSubdomain.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getSubdomain.d.ts","sourceRoot":"","sources":["../../src/helpers/getSubdomain.ts"],"names":[],"mappings":"AAuBA,eAAO,MAAM,SAAS,QAAiB,CAAA;AAEvC,wBAAgB,6BAA6B,SAM5C;AAED,wBAAgB,4BAA4B,WAe3C"}
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
const hostname_arr = window.location.hostname.split('.'); // fretex-dfsf.advoca.no
|
|
1
|
+
const hostname_arr = () => window.location.hostname.split('.'); // fretex-dfsf.advoca.no
|
|
2
2
|
function getSubdomain() {
|
|
3
3
|
let subdomain = '';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
const host_arr = hostname_arr();
|
|
5
|
+
if (host_arr.length === 3 &&
|
|
6
|
+
host_arr[0] &&
|
|
7
|
+
!['dev', 'test', 'stage', 'intern', 'www'].find((sub) => sub === host_arr[0])) {
|
|
8
|
+
subdomain = host_arr[0];
|
|
8
9
|
const subdomain_arr = subdomain.split('-');
|
|
9
10
|
if (subdomain_arr.length === 2 && subdomain_arr[0]) {
|
|
10
11
|
subdomain = subdomain_arr[0];
|
|
11
12
|
}
|
|
12
13
|
}
|
|
13
|
-
else if (
|
|
14
|
-
subdomain =
|
|
14
|
+
else if (host_arr.length === 4 && host_arr[0]) {
|
|
15
|
+
subdomain = host_arr[0];
|
|
15
16
|
}
|
|
16
17
|
return subdomain;
|
|
17
18
|
}
|
|
@@ -23,13 +24,14 @@ export function redirectFromSubdomainToDomain() {
|
|
|
23
24
|
}
|
|
24
25
|
export function createDomainUrlFromSubdomain() {
|
|
25
26
|
let hostname = window.location.hostname.replace(subdomain, '');
|
|
27
|
+
const hostname_arr_length = hostname_arr().length;
|
|
26
28
|
//TODO first if statment will be removed in the future when we all asma will move to nested subdomains
|
|
27
|
-
if (
|
|
29
|
+
if (hostname_arr_length === 3) {
|
|
28
30
|
;
|
|
29
31
|
(hostname.startsWith('-') && (hostname = hostname.substring(1))) ||
|
|
30
32
|
(hostname.startsWith('.') && (hostname = 'www' + hostname));
|
|
31
33
|
}
|
|
32
|
-
else if (
|
|
34
|
+
else if (hostname_arr_length === 4) {
|
|
33
35
|
// deepcode ignore GlobalReplacementRegex: <this is intended>
|
|
34
36
|
hostname = hostname.replace('.', '');
|
|
35
37
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSubdomain.js","sourceRoot":"","sources":["../../src/helpers/getSubdomain.ts"],"names":[],"mappings":"AAAA,MAAM,YAAY,GAAG,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA,
|
|
1
|
+
{"version":3,"file":"getSubdomain.js","sourceRoot":"","sources":["../../src/helpers/getSubdomain.ts"],"names":[],"mappings":"AAAA,MAAM,YAAY,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA,CAAC,wBAAwB;AAEvF,SAAS,YAAY;IACjB,IAAI,SAAS,GAAG,EAAE,CAAA;IAClB,MAAM,QAAQ,GAAG,YAAY,EAAE,CAAA;IAC/B,IACI,QAAQ,CAAC,MAAM,KAAK,CAAC;QACrB,QAAQ,CAAC,CAAC,CAAC;QACX,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,EAC/E;QACE,SAAS,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAA;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C,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA;KACvC;IAED,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAC,QAAQ,CAAA;IAE1C,OAAO,QAAQ,GAAG,IAAI,GAAG,QAAQ,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA;AAChE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
const hostname_arr = window.location.hostname.split('.')// fretex-dfsf.advoca.no
|
|
1
|
+
const hostname_arr = () => window.location.hostname.split('.') // fretex-dfsf.advoca.no
|
|
2
2
|
|
|
3
3
|
function getSubdomain() {
|
|
4
|
-
|
|
5
4
|
let subdomain = ''
|
|
6
|
-
|
|
5
|
+
const host_arr = hostname_arr()
|
|
7
6
|
if (
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
!['dev', 'test', 'stage', 'intern', 'www'].find((sub) => sub ===
|
|
7
|
+
host_arr.length === 3 &&
|
|
8
|
+
host_arr[0] &&
|
|
9
|
+
!['dev', 'test', 'stage', 'intern', 'www'].find((sub) => sub === host_arr[0])
|
|
11
10
|
) {
|
|
12
|
-
subdomain =
|
|
11
|
+
subdomain = host_arr[0]
|
|
13
12
|
|
|
14
13
|
const subdomain_arr = subdomain.split('-')
|
|
15
14
|
|
|
16
15
|
if (subdomain_arr.length === 2 && subdomain_arr[0]) {
|
|
17
16
|
subdomain = subdomain_arr[0]
|
|
18
17
|
}
|
|
19
|
-
}else if(
|
|
20
|
-
subdomain =
|
|
18
|
+
} else if (host_arr.length === 4 && host_arr[0]) {
|
|
19
|
+
subdomain = host_arr[0]
|
|
21
20
|
}
|
|
22
21
|
return subdomain
|
|
23
22
|
}
|
|
@@ -34,18 +33,17 @@ export function redirectFromSubdomainToDomain() {
|
|
|
34
33
|
|
|
35
34
|
export function createDomainUrlFromSubdomain() {
|
|
36
35
|
let hostname = window.location.hostname.replace(subdomain, '')
|
|
36
|
+
const hostname_arr_length = hostname_arr().length
|
|
37
37
|
//TODO first if statment will be removed in the future when we all asma will move to nested subdomains
|
|
38
|
-
if(
|
|
39
|
-
|
|
38
|
+
if (hostname_arr_length === 3) {
|
|
40
39
|
;(hostname.startsWith('-') && (hostname = hostname.substring(1))) ||
|
|
41
40
|
(hostname.startsWith('.') && (hostname = 'www' + hostname))
|
|
42
|
-
}
|
|
43
|
-
else if(hostname_arr.length === 4){
|
|
41
|
+
} else if (hostname_arr_length === 4) {
|
|
44
42
|
// deepcode ignore GlobalReplacementRegex: <this is intended>
|
|
45
|
-
hostname = hostname.replace('.','')
|
|
43
|
+
hostname = hostname.replace('.', '')
|
|
46
44
|
}
|
|
47
45
|
|
|
48
46
|
const { port, protocol } = window.location
|
|
49
47
|
|
|
50
48
|
return protocol + '//' + hostname + (port ? `:${port}` : '')
|
|
51
|
-
}
|
|
49
|
+
}
|