@argon-router/paths 0.11.0 → 1.0.0-rc.0
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/README.md +0 -3
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +165 -158
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -2,9 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
Exteremly customizable paths without a headache
|
|
4
4
|
|
|
5
|
-
> [!WARNING]
|
|
6
|
-
> argon-router is not production ready yet and still may have bugs and unstable API. If you found bug — please report it on GitHub.
|
|
7
|
-
|
|
8
5
|
## Documentation
|
|
9
6
|
|
|
10
7
|
For additional information, guides and api reference visit [documentation site](https://movpushmov.dev/argon-router/)
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";function
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function g(e){return r=>{const t=r.split("/").map(c=>c.trim()).filter(c=>c!=="");let n=null;function i(c,a){n||(n={}),n[c]=a}if(e.length===0)return t.length===0?{path:r,params:null}:null;for(let c=0;c<e.length;c++){const a=e[c];switch(a.type){case"const":{if(a.name!==t.shift())return null;continue}case"parameter":{const{arrayProps:m,genericProps:u,required:s}=a.payload;if(m){var o;const d=[];let f;for(;;){var l;if(f=t.shift(),!f)break;switch(u?.type){case"number":{if(isNaN(+f))return null;d.push(+f);break}case"union":{if(!u.items.includes(f))return null;d.push(f);break}default:{d.push(f);break}}if(d.length>=((l=m.max)!==null&&l!==void 0?l:1/0))break}if(d.length<((o=m.min)!==null&&o!==void 0?o:0)||t.length>0&&!e[c+1])return null;i(a.name,d);break}const p=t.shift();if(s&&!p)return null;if(!p){i(a.name,void 0);continue}switch(u?.type){case"number":{if(isNaN(+p))return null;i(a.name,+p);break}case"union":{if(!u.items.includes(p))return null;i(a.name,p);break}default:{i(a.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 o of e.slice(2))if(o){if(o.includes("<")){t=o.replaceAll(/\s/g,"").replace("<","").replace(">","");continue}if(o.includes("{")&&(n=o.replace("{","").replace("}","").split(",").map(l=>parseInt(l))),["*","?","+"].includes(o)){i=o;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 y(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?y(Object(t),!0).forEach(function(n){P(e,n,t[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):y(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+)(<[\s?\w|]+>)?({\d+,\d+})?([+*?])?/,n=e.split("/").filter(Boolean);for(let i=0;i<n.length;i++){const o=n[i];if(!o)continue;const l=h(o.match(t));if(!l){r.push({type:"const",name:o,payload:void 0});continue}const{arrayProps:c,genericProps:a,modificator:m,name:u}=l;if(!u)throw new Error('Invalid path: "'.concat(e,'". Name for argument must be provided'));const s={type:"parameter",name:u,payload:{required:!0}};switch(a&&a==="number"&&(s.payload.genericProps={type:"number"}),a&&a.includes("|")&&(s.payload.genericProps={type:"union",items:a.split("|")}),m){case"*":{s.payload.arrayProps={};break}case"+":{s.payload.arrayProps={min:1};break}case"?":{s.payload.required=!1;break}}c&&(s.payload.arrayProps=b(b({},s.payload.arrayProps),{},{min:c[0],max:c[1]})),r.push(s)}return{parse:g(r),build:v(r)}}const j={express:[[/:id<.+>/g,":id"],[/:id\+/g,"*id"],[/:id\*/g,"*id"],[/:id\{.+\}/g,"*id"],[/([a-zA-Z0-9:/_.]+)\/([*:])id\?/g,"$1{/$2id}"],[/([*:])id\?/g,"{$1id}"]]};function S(e,r){switch(r){case"express":{let t=e;for(const[n,i]of j.express)t.match(n)&&(t=t.replace(n,i));return t}}}exports.compile=O;exports.convertPath=S;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export declare type Builder<T> = (params: T) => string;
|
|
2
2
|
|
|
3
|
+
declare type CompabilityMode = 'express';
|
|
4
|
+
|
|
3
5
|
/**
|
|
4
6
|
* @param path Route path
|
|
5
7
|
* @description compiles route and give two functions: build (from params to string) & parse (validate from string and get params)
|
|
@@ -37,6 +39,8 @@ export declare type Builder<T> = (params: T) => string;
|
|
|
37
39
|
build: Builder<Params>;
|
|
38
40
|
};
|
|
39
41
|
|
|
42
|
+
export declare function convertPath(path: string, mode: CompabilityMode): string;
|
|
43
|
+
|
|
40
44
|
declare type GenericType<T extends string> = ReplaceAll<T, ' ', ''> extends infer Trimmed ? Trimmed extends `number` ? number : Trimmed extends `${infer A}|${infer B}` ? Union<Trimmed> : Trimmed : never;
|
|
41
45
|
|
|
42
46
|
declare type Join<T extends any[]> = T['length'] extends 0 ? never : T extends [infer F, ...infer Rest] ? Join<Rest> extends infer Tail ? [Tail] extends [never] ? `${F & string}` : `${F & string}/${Tail & string}` : never : never;
|
|
@@ -115,7 +119,7 @@ export declare type Builder<T> = (params: T) => string;
|
|
|
115
119
|
infer TokenReplacer
|
|
116
120
|
] ? ['invalid', JoinPath<[...Res, TokenReplacer, ...Rest]>] : ValidateTokens<Path, Rest, [...Res, Token & string]> : Path;
|
|
117
121
|
|
|
118
|
-
declare type ValidateTypes<GenTypes> = GenTypes extends 'number' ? 'valid' : GenTypes extends '' ? ['invalid', `<number,union>`] : GenTypes extends
|
|
122
|
+
declare type ValidateTypes<GenTypes> = GenTypes extends 'number' ? 'valid' : GenTypes extends '' ? ['invalid', `<number,union>`] : GenTypes extends `${string}|${string}` | string ? 'valid' : ['invalid', `<number,union>`];
|
|
119
123
|
|
|
120
124
|
declare type WithModificator<Type, T extends string> = T extends `${infer K}{${infer Start},${infer End}}+` ? Type[] : T extends `${infer K}{${infer Start},${infer End}}*` ? Type[] : T extends `${infer K}{${infer Start},${infer End}}?` ? Type[] | undefined : T extends `${infer K}{${infer Start},${infer End}}` ? Type[] : T extends `${infer K}+` ? Type[] : T extends `${infer K}*` ? Type[] : T extends `${infer K}?` ? Type | undefined : Type;
|
|
121
125
|
|
package/dist/index.js
CHANGED
|
@@ -1,259 +1,266 @@
|
|
|
1
|
-
function
|
|
2
|
-
return (
|
|
3
|
-
const
|
|
4
|
-
let
|
|
5
|
-
function
|
|
6
|
-
|
|
7
|
-
params = {};
|
|
8
|
-
}
|
|
9
|
-
params[key] = value;
|
|
1
|
+
function g(e) {
|
|
2
|
+
return (r) => {
|
|
3
|
+
const t = r.split("/").map((c) => c.trim()).filter((c) => c !== "");
|
|
4
|
+
let n = null;
|
|
5
|
+
function i(c, o) {
|
|
6
|
+
n || (n = {}), n[c] = o;
|
|
10
7
|
}
|
|
11
|
-
if (
|
|
12
|
-
return
|
|
13
|
-
path:
|
|
8
|
+
if (e.length === 0)
|
|
9
|
+
return t.length === 0 ? {
|
|
10
|
+
path: r,
|
|
14
11
|
params: null
|
|
15
12
|
} : null;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
switch (token.type) {
|
|
13
|
+
for (let c = 0; c < e.length; c++) {
|
|
14
|
+
const o = e[c];
|
|
15
|
+
switch (o.type) {
|
|
20
16
|
case "const": {
|
|
21
|
-
if (
|
|
17
|
+
if (o.name !== t.shift())
|
|
22
18
|
return null;
|
|
23
|
-
}
|
|
24
19
|
continue;
|
|
25
20
|
}
|
|
26
21
|
case "parameter": {
|
|
27
22
|
const {
|
|
28
|
-
arrayProps,
|
|
29
|
-
genericProps,
|
|
30
|
-
required
|
|
31
|
-
} =
|
|
32
|
-
if (
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
23
|
+
arrayProps: m,
|
|
24
|
+
genericProps: u,
|
|
25
|
+
required: s
|
|
26
|
+
} = o.payload;
|
|
27
|
+
if (m) {
|
|
28
|
+
var a;
|
|
29
|
+
const d = [];
|
|
30
|
+
let f;
|
|
31
|
+
for (; ; ) {
|
|
32
|
+
var l;
|
|
33
|
+
if (f = t.shift(), !f)
|
|
38
34
|
break;
|
|
39
|
-
|
|
40
|
-
switch (genericProps == null ? void 0 : genericProps.type) {
|
|
35
|
+
switch (u?.type) {
|
|
41
36
|
case "number": {
|
|
42
|
-
if (isNaN(+
|
|
37
|
+
if (isNaN(+f))
|
|
43
38
|
return null;
|
|
44
|
-
|
|
45
|
-
array.push(+rawToken2);
|
|
39
|
+
d.push(+f);
|
|
46
40
|
break;
|
|
47
41
|
}
|
|
48
42
|
case "union": {
|
|
49
|
-
if (!
|
|
43
|
+
if (!u.items.includes(f))
|
|
50
44
|
return null;
|
|
51
|
-
|
|
52
|
-
array.push(rawToken2);
|
|
45
|
+
d.push(f);
|
|
53
46
|
break;
|
|
54
47
|
}
|
|
55
48
|
default: {
|
|
56
|
-
|
|
49
|
+
d.push(f);
|
|
57
50
|
break;
|
|
58
51
|
}
|
|
59
52
|
}
|
|
60
|
-
if (
|
|
53
|
+
if (d.length >= ((l = m.max) !== null && l !== void 0 ? l : 1 / 0))
|
|
61
54
|
break;
|
|
62
|
-
}
|
|
63
55
|
}
|
|
64
|
-
if (
|
|
56
|
+
if (d.length < ((a = m.min) !== null && a !== void 0 ? a : 0) || t.length > 0 && !e[c + 1])
|
|
65
57
|
return null;
|
|
66
|
-
|
|
67
|
-
if (rawTokens.length > 0 && !tokens[i + 1]) {
|
|
68
|
-
return null;
|
|
69
|
-
}
|
|
70
|
-
setKey(token.name, array);
|
|
58
|
+
i(o.name, d);
|
|
71
59
|
break;
|
|
72
60
|
}
|
|
73
|
-
const
|
|
74
|
-
if (
|
|
61
|
+
const p = t.shift();
|
|
62
|
+
if (s && !p)
|
|
75
63
|
return null;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
setKey(token.name, void 0);
|
|
64
|
+
if (!p) {
|
|
65
|
+
i(o.name, void 0);
|
|
79
66
|
continue;
|
|
80
67
|
}
|
|
81
|
-
switch (
|
|
68
|
+
switch (u?.type) {
|
|
82
69
|
case "number": {
|
|
83
|
-
if (isNaN(+
|
|
70
|
+
if (isNaN(+p))
|
|
84
71
|
return null;
|
|
85
|
-
|
|
86
|
-
setKey(token.name, +rawToken);
|
|
72
|
+
i(o.name, +p);
|
|
87
73
|
break;
|
|
88
74
|
}
|
|
89
75
|
case "union": {
|
|
90
|
-
if (!
|
|
76
|
+
if (!u.items.includes(p))
|
|
91
77
|
return null;
|
|
92
|
-
|
|
93
|
-
setKey(token.name, rawToken);
|
|
78
|
+
i(o.name, p);
|
|
94
79
|
break;
|
|
95
80
|
}
|
|
96
81
|
default: {
|
|
97
|
-
|
|
82
|
+
i(o.name, p);
|
|
98
83
|
break;
|
|
99
84
|
}
|
|
100
85
|
}
|
|
101
86
|
}
|
|
102
87
|
}
|
|
103
88
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
return {
|
|
108
|
-
path: input,
|
|
109
|
-
params
|
|
89
|
+
return t.length > 0 ? null : {
|
|
90
|
+
path: r,
|
|
91
|
+
params: n
|
|
110
92
|
};
|
|
111
93
|
};
|
|
112
94
|
}
|
|
113
|
-
function
|
|
114
|
-
if (!
|
|
95
|
+
function h(e) {
|
|
96
|
+
if (!e)
|
|
115
97
|
return null;
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
if (parameter.includes("{")) {
|
|
130
|
-
arrayProps = parameter.replace("{", "").replace("}", "").split(",").map((item) => parseInt(item));
|
|
131
|
-
}
|
|
132
|
-
if (["*", "?", "+"].includes(parameter)) {
|
|
133
|
-
modificator = parameter;
|
|
134
|
-
continue;
|
|
98
|
+
const r = e[1];
|
|
99
|
+
let t, n, i;
|
|
100
|
+
for (const a of e.slice(2))
|
|
101
|
+
if (a) {
|
|
102
|
+
if (a.includes("<")) {
|
|
103
|
+
t = a.replaceAll(/\s/g, "").replace("<", "").replace(">", "");
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
if (a.includes("{") && (n = a.replace("{", "").replace("}", "").split(",").map((l) => parseInt(l))), ["*", "?", "+"].includes(a)) {
|
|
107
|
+
i = a;
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
135
110
|
}
|
|
136
|
-
}
|
|
137
111
|
return {
|
|
138
|
-
name,
|
|
139
|
-
genericProps,
|
|
140
|
-
arrayProps,
|
|
141
|
-
modificator
|
|
112
|
+
name: r,
|
|
113
|
+
genericProps: t,
|
|
114
|
+
arrayProps: n,
|
|
115
|
+
modificator: i
|
|
142
116
|
};
|
|
143
117
|
}
|
|
144
|
-
function
|
|
145
|
-
return (
|
|
146
|
-
const
|
|
147
|
-
if (
|
|
118
|
+
function v(e) {
|
|
119
|
+
return (r) => {
|
|
120
|
+
const t = [];
|
|
121
|
+
if (e.length === 0)
|
|
148
122
|
return "/";
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
switch (token.type) {
|
|
123
|
+
for (const n of e)
|
|
124
|
+
switch (n.type) {
|
|
152
125
|
case "const": {
|
|
153
|
-
|
|
126
|
+
t.push(n.name);
|
|
154
127
|
break;
|
|
155
128
|
}
|
|
156
129
|
case "parameter": {
|
|
157
|
-
if (!
|
|
130
|
+
if (!r[n.name])
|
|
158
131
|
continue;
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
} else {
|
|
165
|
-
result.push(params[token.name].toString());
|
|
166
|
-
}
|
|
132
|
+
if (Array.isArray(r[n.name]))
|
|
133
|
+
for (const i of r[n.name])
|
|
134
|
+
t.push(i.toString());
|
|
135
|
+
else
|
|
136
|
+
t.push(r[n.name].toString());
|
|
167
137
|
break;
|
|
168
138
|
}
|
|
169
139
|
}
|
|
170
|
-
|
|
171
|
-
return `/${result.join("/")}`;
|
|
140
|
+
return "/".concat(t.join("/"));
|
|
172
141
|
};
|
|
173
142
|
}
|
|
174
|
-
function
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
143
|
+
function y(e, r) {
|
|
144
|
+
var t = Object.keys(e);
|
|
145
|
+
if (Object.getOwnPropertySymbols) {
|
|
146
|
+
var n = Object.getOwnPropertySymbols(e);
|
|
147
|
+
r && (n = n.filter(function(i) {
|
|
148
|
+
return Object.getOwnPropertyDescriptor(e, i).enumerable;
|
|
149
|
+
})), t.push.apply(t, n);
|
|
150
|
+
}
|
|
151
|
+
return t;
|
|
152
|
+
}
|
|
153
|
+
function b(e) {
|
|
154
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
155
|
+
var t = arguments[r] != null ? arguments[r] : {};
|
|
156
|
+
r % 2 ? y(Object(t), !0).forEach(function(n) {
|
|
157
|
+
P(e, n, t[n]);
|
|
158
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : y(Object(t)).forEach(function(n) {
|
|
159
|
+
Object.defineProperty(e, n, Object.getOwnPropertyDescriptor(t, n));
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
return e;
|
|
163
|
+
}
|
|
164
|
+
function P(e, r, t) {
|
|
165
|
+
return (r = w(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e;
|
|
166
|
+
}
|
|
167
|
+
function w(e) {
|
|
168
|
+
var r = k(e, "string");
|
|
169
|
+
return typeof r == "symbol" ? r : r + "";
|
|
170
|
+
}
|
|
171
|
+
function k(e, r) {
|
|
172
|
+
if (typeof e != "object" || !e) return e;
|
|
173
|
+
var t = e[Symbol.toPrimitive];
|
|
174
|
+
if (t !== void 0) {
|
|
175
|
+
var n = t.call(e, r);
|
|
176
|
+
if (typeof n != "object") return n;
|
|
177
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
178
|
+
}
|
|
179
|
+
return (r === "string" ? String : Number)(e);
|
|
180
|
+
}
|
|
181
|
+
function j(e) {
|
|
182
|
+
const r = [], t = /:(\w+)(<[\s?\w|]+>)?({\d+,\d+})?([+*?])?/, n = e.split("/").filter(Boolean);
|
|
183
|
+
for (let i = 0; i < n.length; i++) {
|
|
184
|
+
const a = n[i];
|
|
185
|
+
if (!a)
|
|
181
186
|
continue;
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
tokens.push({
|
|
187
|
+
const l = h(a.match(t));
|
|
188
|
+
if (!l) {
|
|
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
|
-
} =
|
|
198
|
-
if (!
|
|
199
|
-
throw new Error(
|
|
200
|
-
|
|
201
|
-
const token = {
|
|
197
|
+
arrayProps: c,
|
|
198
|
+
genericProps: o,
|
|
199
|
+
modificator: m,
|
|
200
|
+
name: u
|
|
201
|
+
} = l;
|
|
202
|
+
if (!u)
|
|
203
|
+
throw new Error('Invalid path: "'.concat(e, '". Name for argument must be provided'));
|
|
204
|
+
const s = {
|
|
202
205
|
type: "parameter",
|
|
203
|
-
name,
|
|
206
|
+
name: u,
|
|
204
207
|
payload: {
|
|
205
|
-
required:
|
|
208
|
+
required: !0
|
|
206
209
|
}
|
|
207
210
|
};
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
token.payload.genericProps = {
|
|
215
|
-
type: "union",
|
|
216
|
-
items: genericProps.split("|")
|
|
217
|
-
};
|
|
218
|
-
}
|
|
219
|
-
switch (modificator) {
|
|
211
|
+
switch (o && o === "number" && (s.payload.genericProps = {
|
|
212
|
+
type: "number"
|
|
213
|
+
}), o && o.includes("|") && (s.payload.genericProps = {
|
|
214
|
+
type: "union",
|
|
215
|
+
items: o.split("|")
|
|
216
|
+
}), m) {
|
|
220
217
|
case "*": {
|
|
221
|
-
|
|
218
|
+
s.payload.arrayProps = {};
|
|
222
219
|
break;
|
|
223
220
|
}
|
|
224
221
|
case "+": {
|
|
225
|
-
|
|
222
|
+
s.payload.arrayProps = {
|
|
226
223
|
min: 1
|
|
227
224
|
};
|
|
228
225
|
break;
|
|
229
226
|
}
|
|
230
227
|
case "?": {
|
|
231
|
-
|
|
228
|
+
s.payload.required = !1;
|
|
232
229
|
break;
|
|
233
230
|
}
|
|
234
231
|
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
max: arrayProps[1]
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
tokens.push(token);
|
|
232
|
+
c && (s.payload.arrayProps = b(b({}, s.payload.arrayProps), {}, {
|
|
233
|
+
min: c[0],
|
|
234
|
+
max: c[1]
|
|
235
|
+
})), r.push(s);
|
|
243
236
|
}
|
|
244
237
|
return {
|
|
245
238
|
/**
|
|
246
239
|
* @param input Input path
|
|
247
240
|
* @returns `{ path: string; params: Params }` | `null`
|
|
248
241
|
*/
|
|
249
|
-
parse:
|
|
242
|
+
parse: g(r),
|
|
250
243
|
/**
|
|
251
244
|
* @param params Route parameters
|
|
252
245
|
* @returns string
|
|
253
246
|
*/
|
|
254
|
-
build:
|
|
247
|
+
build: v(r)
|
|
255
248
|
};
|
|
256
249
|
}
|
|
250
|
+
const O = {
|
|
251
|
+
express: [[/:id<.+>/g, ":id"], [/:id\+/g, "*id"], [/:id\*/g, "*id"], [/:id\{.+\}/g, "*id"], [/([a-zA-Z0-9:/_.]+)\/([*:])id\?/g, "$1{/$2id}"], [/([*:])id\?/g, "{$1id}"]]
|
|
252
|
+
};
|
|
253
|
+
function S(e, r) {
|
|
254
|
+
switch (r) {
|
|
255
|
+
case "express": {
|
|
256
|
+
let t = e;
|
|
257
|
+
for (const [n, i] of O.express)
|
|
258
|
+
t.match(n) && (t = t.replace(n, i));
|
|
259
|
+
return t;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
257
263
|
export {
|
|
258
|
-
compile
|
|
264
|
+
j as compile,
|
|
265
|
+
S as convertPath
|
|
259
266
|
};
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"registry": "https://registry.npmjs.org/"
|
|
6
6
|
},
|
|
7
7
|
"private": false,
|
|
8
|
-
"version": "0.
|
|
8
|
+
"version": "1.0.0-rc.0",
|
|
9
9
|
"description": "Paths with power of effector",
|
|
10
10
|
"keywords": [
|
|
11
11
|
"paths",
|
|
@@ -34,12 +34,12 @@
|
|
|
34
34
|
"type": "git",
|
|
35
35
|
"url": "git+https://github.com/movpushmov/argon-router.git"
|
|
36
36
|
},
|
|
37
|
-
"scripts": {
|
|
38
|
-
"build": "vite build",
|
|
39
|
-
"test": "vitest run"
|
|
40
|
-
},
|
|
41
37
|
"bugs": {
|
|
42
38
|
"url": "https://github.com/movpushmov/argon-router/issues"
|
|
43
39
|
},
|
|
44
|
-
"gitHead": "
|
|
45
|
-
|
|
40
|
+
"gitHead": "9832d6cd282d6abd33c26ba4d03b9a1176110fc4",
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "vite build",
|
|
43
|
+
"test": "vitest run"
|
|
44
|
+
}
|
|
45
|
+
}
|