-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
137 lines (101 loc) · 3.38 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
(function(global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.OLSKRouting = global.OLSKRouting || {})));
}(this, (function(exports) { 'use strict';
const mod = {
OLSKRoutingModelIsValid (inputData) {
if (typeof inputData !== 'object' || inputData === null) {
return false;
}
if (typeof inputData.OLSKRoutePath !== 'string') {
return false;
}
if (inputData.OLSKRouteRedirect !== undefined) {
if (typeof inputData.OLSKRouteRedirect !== 'string') {
return false;
}
return true;
}
if (typeof inputData.OLSKRouteMethod !== 'string') {
return false;
}
if (typeof inputData.OLSKRouteFunction !== 'function') {
return false;
}
if (inputData.OLSKRouteSignature !== undefined) {
if (typeof inputData.OLSKRouteSignature !== 'string') {
return false;
}
if (inputData.OLSKRouteSignature.match(/\s/)) {
return false;
};
}
if (inputData.OLSKRouteIsHidden) {
if (typeof inputData.OLSKRouteIsHidden !== 'boolean') {
return false;
}
}
if (inputData.OLSKRouteMiddlewares) {
if (!Array.isArray(inputData.OLSKRouteMiddlewares)) {
return false;
}
}
return true;
},
_OLSKRoutingQuerify (inputData) {
return Object.entries(inputData).map(function (e) {
return e.join('=');
}).join('&')
},
OLSKRoutingCanonicalPath (routePath, params = {}) {
if (typeof routePath !== 'string') {
throw new Error('OLSKErrorInputNotValid');
}
params = Object.assign({}, params);
let canonicalPath = mod.OLSKRoutingSubstitutionFunction(routePath)(params);
if (params && params.OLSKRoutingLanguage) {
canonicalPath = ['/', params.OLSKRoutingLanguage, canonicalPath].join('');
delete params.OLSKRoutingLanguage;
}
if (params && params.OLSKRoutingOrigin) {
canonicalPath = [params.OLSKRoutingOrigin, canonicalPath].join('');
delete params.OLSKRoutingOrigin;
}
if (params && params.OLSKRoutingHash) {
canonicalPath = canonicalPath + '#' + mod._OLSKRoutingQuerify(params.OLSKRoutingHash);
delete params.OLSKRoutingHash;
}
const query = mod._OLSKRoutingQuerify(params);
return canonicalPath + (query ? `?${ query }` : '');
},
OLSKRoutingSubstitutionFunction (routePath) {
if (typeof routePath !== 'string') {
throw new Error('OLSKErrorInputNotValid');
}
var functionString = (
function(inputData) {
if (typeof inputData !== 'object' || inputData === null) {
throw new Error('OLSKErrorInputNotValidMissingInput');
}
var substitutedPath = 'OLSKRoutingSubstitutionFunctionTemplate';
(substitutedPath.match(/(:[\w]+(\(.*\))?)/g) || []).forEach(function(e) {
if (!inputData[e.split(':').pop().split('(').shift()]) {
throw new Error('OLSKErrorInputNotValidMissingRouteParam');
}
substitutedPath = substitutedPath.replace(e, inputData[e.split(':').pop().split('(').shift()]);
delete inputData[e.split(':').pop().split('(').shift()]
});
return substitutedPath;
}
).toString().replace('OLSKRoutingSubstitutionFunctionTemplate', routePath);
var alfa;
eval('alfa = ' + functionString);
return alfa;
},
};
Object.assign(exports, mod);
Object.defineProperty(exports, '__esModule', {
value: true
});
})));