@argon-router/paths 0.6.1 → 0.6.3
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/dist/index.cjs +1 -1
- package/dist/index.js +90 -86
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function g(e){return r=>{const t=r.split("/").map(u=>u.trim()).filter(u=>u!=="");let n=null;function i(u,o){n||(n={}),n[u]=o}if(e.length===0)return t.length===0?{path:r,params:null}:null;for(let u=0;u<e.length;u++){const o=e[u];switch(o.type){case"const":{if(o.name!==t.shift())return null;continue}case"parameter":{const{arrayProps:y,genericProps:l,required:c}=o.payload;if(y){var a;const m=[];let f;for(;;){var s;if(f=t.shift(),!f)break;switch(l==null?void 0:l.type){case"number":{if(isNaN(+f))return null;m.push(+f);break}case"union":{if(!l.items.includes(f))return null;m.push(f);break}default:{m.push(f);break}}if(m.length>=((s=y.max)!==null&&s!==void 0?s:1/0))break}if(m.length<((a=y.min)!==null&&a!==void 0?a:0)||t.length>0&&!e[u+1])return null;i(o.name,m);break}const p=t.shift();if(c&&!p)return null;if(!p){i(o.name,void 0);continue}switch(l==null?void 0:l.type){case"number":{if(isNaN(+p))return null;i(o.name,+p);break}case"union":{if(!l.items.includes(p))return null;i(o.name,p);break}default:{i(o.name,p);break}}}}}return t.length>0?null:{path:r,params:n}}}function h(e){if(!e)return null;const r=e[1];let t,n,i;for(const a of e.slice(2))if(a){if(a.includes("<")){t=a.replace("<","").replace(">","");continue}if(a.includes("{")&&(n=a.replace("{","").replace("}","").split(",").map(s=>parseInt(s))),["*","?","+"].includes(a)){i=a;continue}}return{name:r,genericProps:t,arrayProps:n,modificator:i}}function v(e){return r=>{const t=[];if(e.length===0)return"/";for(const n of e)switch(n.type){case"const":{t.push(n.name);break}case"parameter":{if(!r[n.name])continue;if(Array.isArray(r[n.name]))for(const i of r[n.name])t.push(i.toString());else t.push(r[n.name].toString());break}}return"/".concat(t.join("/"))}}function d(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter(function(i){return Object.getOwnPropertyDescriptor(e,i).enumerable})),t.push.apply(t,n)}return t}function b(e){for(var r=1;r<arguments.length;r++){var t=arguments[r]!=null?arguments[r]:{};r%2?d(Object(t),!0).forEach(function(n){P(e,n,t[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):d(Object(t)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))})}return e}function P(e,r,t){return(r=w(r))in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function w(e){var r=k(e,"string");return typeof r=="symbol"?r:r+""}function k(e,r){if(typeof e!="object"||!e)return e;var t=e[Symbol.toPrimitive];if(t!==void 0){var n=t.call(e,r);if(typeof n!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(r==="string"?String:Number)(e)}function O(e){const r=[],t=/:(\w+)(<[\w|]+>)?({\d+\,\d+})?([+*?])?/,n=e.split("/").filter(Boolean);for(let i=0;i<n.length;i++){const a=n[i];if(!a)continue;const s=h(a.match(t));if(!s){r.push({type:"const",name:a,payload:void 0});continue}const{arrayProps:u,genericProps:o,modificator:y,name:l}=s;if(!l)throw new Error('Invalid path: "'.concat(e,'". Name for argument must be provided'));const c={type:"parameter",name:l,payload:{required:!0}};switch(o&&o==="number"&&(c.payload.genericProps={type:"number"}),o&&o.includes("|")&&(c.payload.genericProps={type:"union",items:o.split("|")}),y){case"*":{c.payload.arrayProps={};break}case"+":{c.payload.arrayProps={min:1};break}case"?":{c.payload.required=!1;break}}u&&(c.payload.arrayProps=b(b({},c.payload.arrayProps),{},{min:u[0],max:u[1]})),r.push(c)}return{parse:g(r),build:v(r)}}exports.compile=O;
|
package/dist/index.js
CHANGED
|
@@ -1,88 +1,92 @@
|
|
|
1
|
-
function
|
|
1
|
+
function h(e) {
|
|
2
2
|
return (r) => {
|
|
3
|
-
const n = r.split("/").filter(
|
|
3
|
+
const n = r.split("/").map((u) => u.trim()).filter((u) => u !== "");
|
|
4
4
|
let t = null;
|
|
5
|
-
function
|
|
6
|
-
t || (t = {}), t[
|
|
5
|
+
function i(u, o) {
|
|
6
|
+
t || (t = {}), t[u] = o;
|
|
7
7
|
}
|
|
8
8
|
if (e.length === 0)
|
|
9
9
|
return n.length === 0 ? {
|
|
10
10
|
path: r,
|
|
11
11
|
params: null
|
|
12
12
|
} : null;
|
|
13
|
-
for (let
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
switch (c.type) {
|
|
13
|
+
for (let u = 0; u < e.length; u++) {
|
|
14
|
+
const o = e[u];
|
|
15
|
+
switch (o.type) {
|
|
17
16
|
case "const": {
|
|
18
|
-
if (
|
|
17
|
+
if (o.name !== n.shift())
|
|
19
18
|
return null;
|
|
20
19
|
continue;
|
|
21
20
|
}
|
|
22
21
|
case "parameter": {
|
|
23
22
|
const {
|
|
24
|
-
arrayProps:
|
|
25
|
-
genericProps:
|
|
26
|
-
required:
|
|
27
|
-
} =
|
|
28
|
-
if (
|
|
29
|
-
var
|
|
30
|
-
const
|
|
31
|
-
|
|
23
|
+
arrayProps: y,
|
|
24
|
+
genericProps: l,
|
|
25
|
+
required: c
|
|
26
|
+
} = o.payload;
|
|
27
|
+
if (y) {
|
|
28
|
+
var a;
|
|
29
|
+
const m = [];
|
|
30
|
+
let f;
|
|
31
|
+
for (; ; ) {
|
|
32
32
|
var s;
|
|
33
|
-
|
|
33
|
+
if (f = n.shift(), !f)
|
|
34
|
+
break;
|
|
35
|
+
switch (l == null ? void 0 : l.type) {
|
|
34
36
|
case "number": {
|
|
35
|
-
if (isNaN(+
|
|
37
|
+
if (isNaN(+f))
|
|
36
38
|
return null;
|
|
37
|
-
|
|
39
|
+
m.push(+f);
|
|
38
40
|
break;
|
|
39
41
|
}
|
|
40
42
|
case "union": {
|
|
41
|
-
if (!
|
|
43
|
+
if (!l.items.includes(f))
|
|
42
44
|
return null;
|
|
43
|
-
|
|
45
|
+
m.push(f);
|
|
44
46
|
break;
|
|
45
47
|
}
|
|
46
48
|
default: {
|
|
47
|
-
|
|
49
|
+
m.push(f);
|
|
48
50
|
break;
|
|
49
51
|
}
|
|
50
52
|
}
|
|
51
|
-
|
|
53
|
+
if (m.length >= ((s = y.max) !== null && s !== void 0 ? s : 1 / 0))
|
|
54
|
+
break;
|
|
52
55
|
}
|
|
53
|
-
if (
|
|
56
|
+
if (m.length < ((a = y.min) !== null && a !== void 0 ? a : 0) || n.length > 0 && !e[u + 1])
|
|
54
57
|
return null;
|
|
55
|
-
|
|
58
|
+
i(o.name, m);
|
|
56
59
|
break;
|
|
57
60
|
}
|
|
58
|
-
|
|
61
|
+
const p = n.shift();
|
|
62
|
+
if (c && !p)
|
|
59
63
|
return null;
|
|
60
|
-
if (!
|
|
61
|
-
|
|
64
|
+
if (!p) {
|
|
65
|
+
i(o.name, void 0);
|
|
62
66
|
continue;
|
|
63
67
|
}
|
|
64
|
-
switch (
|
|
68
|
+
switch (l == null ? void 0 : l.type) {
|
|
65
69
|
case "number": {
|
|
66
|
-
if (isNaN(+
|
|
70
|
+
if (isNaN(+p))
|
|
67
71
|
return null;
|
|
68
|
-
|
|
72
|
+
i(o.name, +p);
|
|
69
73
|
break;
|
|
70
74
|
}
|
|
71
75
|
case "union": {
|
|
72
|
-
if (!
|
|
76
|
+
if (!l.items.includes(p))
|
|
73
77
|
return null;
|
|
74
|
-
|
|
78
|
+
i(o.name, p);
|
|
75
79
|
break;
|
|
76
80
|
}
|
|
77
81
|
default: {
|
|
78
|
-
|
|
82
|
+
i(o.name, p);
|
|
79
83
|
break;
|
|
80
84
|
}
|
|
81
85
|
}
|
|
82
86
|
}
|
|
83
87
|
}
|
|
84
88
|
}
|
|
85
|
-
return {
|
|
89
|
+
return n.length > 0 ? null : {
|
|
86
90
|
path: r,
|
|
87
91
|
params: t
|
|
88
92
|
};
|
|
@@ -92,15 +96,15 @@ function g(e) {
|
|
|
92
96
|
if (!e)
|
|
93
97
|
return null;
|
|
94
98
|
const r = e[1];
|
|
95
|
-
let n, t,
|
|
96
|
-
for (const
|
|
97
|
-
if (
|
|
98
|
-
if (
|
|
99
|
-
n =
|
|
99
|
+
let n, t, i;
|
|
100
|
+
for (const a of e.slice(2))
|
|
101
|
+
if (a) {
|
|
102
|
+
if (a.includes("<")) {
|
|
103
|
+
n = a.replace("<", "").replace(">", "");
|
|
100
104
|
continue;
|
|
101
105
|
}
|
|
102
|
-
if (
|
|
103
|
-
|
|
106
|
+
if (a.includes("{") && (t = a.replace("{", "").replace("}", "").split(",").map((s) => parseInt(s))), ["*", "?", "+"].includes(a)) {
|
|
107
|
+
i = a;
|
|
104
108
|
continue;
|
|
105
109
|
}
|
|
106
110
|
}
|
|
@@ -108,10 +112,10 @@ function g(e) {
|
|
|
108
112
|
name: r,
|
|
109
113
|
genericProps: n,
|
|
110
114
|
arrayProps: t,
|
|
111
|
-
modificator:
|
|
115
|
+
modificator: i
|
|
112
116
|
};
|
|
113
117
|
}
|
|
114
|
-
function
|
|
118
|
+
function v(e) {
|
|
115
119
|
return (r) => {
|
|
116
120
|
const n = [];
|
|
117
121
|
if (e.length === 0)
|
|
@@ -126,8 +130,8 @@ function h(e) {
|
|
|
126
130
|
if (!r[t.name])
|
|
127
131
|
continue;
|
|
128
132
|
if (Array.isArray(r[t.name]))
|
|
129
|
-
for (const
|
|
130
|
-
n.push(
|
|
133
|
+
for (const i of r[t.name])
|
|
134
|
+
n.push(i.toString());
|
|
131
135
|
else
|
|
132
136
|
n.push(r[t.name].toString());
|
|
133
137
|
break;
|
|
@@ -136,35 +140,35 @@ function h(e) {
|
|
|
136
140
|
return "/".concat(n.join("/"));
|
|
137
141
|
};
|
|
138
142
|
}
|
|
139
|
-
function
|
|
143
|
+
function d(e, r) {
|
|
140
144
|
var n = Object.keys(e);
|
|
141
145
|
if (Object.getOwnPropertySymbols) {
|
|
142
146
|
var t = Object.getOwnPropertySymbols(e);
|
|
143
|
-
r && (t = t.filter(function(
|
|
144
|
-
return Object.getOwnPropertyDescriptor(e,
|
|
147
|
+
r && (t = t.filter(function(i) {
|
|
148
|
+
return Object.getOwnPropertyDescriptor(e, i).enumerable;
|
|
145
149
|
})), n.push.apply(n, t);
|
|
146
150
|
}
|
|
147
151
|
return n;
|
|
148
152
|
}
|
|
149
|
-
function
|
|
153
|
+
function b(e) {
|
|
150
154
|
for (var r = 1; r < arguments.length; r++) {
|
|
151
155
|
var n = arguments[r] != null ? arguments[r] : {};
|
|
152
|
-
r % 2 ?
|
|
153
|
-
|
|
154
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(n)) :
|
|
156
|
+
r % 2 ? d(Object(n), !0).forEach(function(t) {
|
|
157
|
+
P(e, t, n[t]);
|
|
158
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(n)) : d(Object(n)).forEach(function(t) {
|
|
155
159
|
Object.defineProperty(e, t, Object.getOwnPropertyDescriptor(n, t));
|
|
156
160
|
});
|
|
157
161
|
}
|
|
158
162
|
return e;
|
|
159
163
|
}
|
|
160
|
-
function
|
|
161
|
-
return (r =
|
|
164
|
+
function P(e, r, n) {
|
|
165
|
+
return (r = w(r)) in e ? Object.defineProperty(e, r, { value: n, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = n, e;
|
|
162
166
|
}
|
|
163
|
-
function
|
|
164
|
-
var r =
|
|
167
|
+
function w(e) {
|
|
168
|
+
var r = k(e, "string");
|
|
165
169
|
return typeof r == "symbol" ? r : r + "";
|
|
166
170
|
}
|
|
167
|
-
function
|
|
171
|
+
function k(e, r) {
|
|
168
172
|
if (typeof e != "object" || !e) return e;
|
|
169
173
|
var n = e[Symbol.toPrimitive];
|
|
170
174
|
if (n !== void 0) {
|
|
@@ -174,75 +178,75 @@ function w(e, r) {
|
|
|
174
178
|
}
|
|
175
179
|
return (r === "string" ? String : Number)(e);
|
|
176
180
|
}
|
|
177
|
-
function
|
|
181
|
+
function O(e) {
|
|
178
182
|
const r = [], n = /:(\w+)(<[\w|]+>)?({\d+\,\d+})?([+*?])?/, t = e.split("/").filter(Boolean);
|
|
179
|
-
for (let
|
|
180
|
-
const
|
|
181
|
-
if (!
|
|
183
|
+
for (let i = 0; i < t.length; i++) {
|
|
184
|
+
const a = t[i];
|
|
185
|
+
if (!a)
|
|
182
186
|
continue;
|
|
183
|
-
const s = g(
|
|
187
|
+
const s = g(a.match(n));
|
|
184
188
|
if (!s) {
|
|
185
189
|
r.push({
|
|
186
190
|
type: "const",
|
|
187
|
-
name:
|
|
191
|
+
name: a,
|
|
188
192
|
payload: void 0
|
|
189
193
|
});
|
|
190
194
|
continue;
|
|
191
195
|
}
|
|
192
196
|
const {
|
|
193
|
-
arrayProps:
|
|
194
|
-
genericProps:
|
|
195
|
-
modificator:
|
|
196
|
-
name:
|
|
197
|
+
arrayProps: u,
|
|
198
|
+
genericProps: o,
|
|
199
|
+
modificator: y,
|
|
200
|
+
name: l
|
|
197
201
|
} = s;
|
|
198
|
-
if (!
|
|
202
|
+
if (!l)
|
|
199
203
|
throw new Error('Invalid path: "'.concat(e, '". Name for argument must be provided'));
|
|
200
|
-
const
|
|
204
|
+
const c = {
|
|
201
205
|
type: "parameter",
|
|
202
|
-
name:
|
|
206
|
+
name: l,
|
|
203
207
|
payload: {
|
|
204
208
|
required: !0
|
|
205
209
|
}
|
|
206
210
|
};
|
|
207
|
-
switch (
|
|
211
|
+
switch (o && o === "number" && (c.payload.genericProps = {
|
|
208
212
|
type: "number"
|
|
209
|
-
}),
|
|
213
|
+
}), o && o.includes("|") && (c.payload.genericProps = {
|
|
210
214
|
type: "union",
|
|
211
|
-
items:
|
|
212
|
-
}),
|
|
215
|
+
items: o.split("|")
|
|
216
|
+
}), y) {
|
|
213
217
|
case "*": {
|
|
214
|
-
|
|
218
|
+
c.payload.arrayProps = {};
|
|
215
219
|
break;
|
|
216
220
|
}
|
|
217
221
|
case "+": {
|
|
218
|
-
|
|
222
|
+
c.payload.arrayProps = {
|
|
219
223
|
min: 1
|
|
220
224
|
};
|
|
221
225
|
break;
|
|
222
226
|
}
|
|
223
227
|
case "?": {
|
|
224
|
-
|
|
228
|
+
c.payload.required = !1;
|
|
225
229
|
break;
|
|
226
230
|
}
|
|
227
231
|
}
|
|
228
|
-
|
|
229
|
-
min:
|
|
230
|
-
max:
|
|
231
|
-
})), r.push(
|
|
232
|
+
u && (c.payload.arrayProps = b(b({}, c.payload.arrayProps), {}, {
|
|
233
|
+
min: u[0],
|
|
234
|
+
max: u[1]
|
|
235
|
+
})), r.push(c);
|
|
232
236
|
}
|
|
233
237
|
return {
|
|
234
238
|
/**
|
|
235
239
|
* @param input Input path
|
|
236
240
|
* @returns `{ path: string; params: Params }` | `null`
|
|
237
241
|
*/
|
|
238
|
-
parse:
|
|
242
|
+
parse: h(r),
|
|
239
243
|
/**
|
|
240
244
|
* @param params Route parameters
|
|
241
245
|
* @returns string
|
|
242
246
|
*/
|
|
243
|
-
build:
|
|
247
|
+
build: v(r)
|
|
244
248
|
};
|
|
245
249
|
}
|
|
246
250
|
export {
|
|
247
|
-
|
|
251
|
+
O as compile
|
|
248
252
|
};
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"registry": "https://registry.npmjs.org/"
|
|
6
6
|
},
|
|
7
7
|
"private": false,
|
|
8
|
-
"version": "0.6.
|
|
8
|
+
"version": "0.6.3",
|
|
9
9
|
"description": "Paths with power of effector",
|
|
10
10
|
"keywords": [
|
|
11
11
|
"paths",
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"bugs": {
|
|
42
42
|
"url": "https://github.com/movpushmov/argon-router/issues"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "5faa9c25438bb19acd19fd19b9d9eb92399a3696"
|
|
45
45
|
}
|