@argon-router/paths 0.6.0 → 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/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  Exteremly customizable paths without a headache
4
4
 
5
5
  > [!WARNING]
6
- > argon-router is extermely unstable & maybe buggy. DO NOT USE IN PRODUCTION!
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
7
 
8
8
  ## Documentation
9
9
 
@@ -13,6 +13,7 @@ For additional information, guides and api reference visit [documentation site](
13
13
 
14
14
  - [@argon-router/core](https://www.npmjs.com/package/@argon-router/core)
15
15
  - [@argon-router/react](https://www.npmjs.com/package/@argon-router/react)
16
+ - [@argon-router/paths](https://www.npmjs.com/package/@argon-router/paths)
16
17
 
17
18
  ## Installation
18
19
 
@@ -64,7 +65,7 @@ npm i @argon-router/paths
64
65
  '/:id<hello|world>'; // same as '/hello', '/world' and not '/test'
65
66
  ```
66
67
 
67
- - Length for parameter
68
+ - Ranges for parameter
68
69
 
69
70
  ```ts
70
71
  '/:id{2,3}'; // same as '/test/test', '/test/test/test' and not '/test'
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function b(e){return r=>{const n=r.split("/").filter(Boolean);let t=null;function a(l,i){t||(t={}),t[l]=i}if(e.length===0)return n.length===0?{path:r,params:null}:null;for(let l=0;l<e.length;l++){let i=n[l];const c=e[l];switch(c.type){case"const":{if(i!==c.name)return null;continue}case"parameter":{const{arrayProps:f,genericProps:o,required:d}=c.payload;if(f){var u;const p=[];for(;i&&p.length<((s=f.max)!==null&&s!==void 0?s:1/0);){var s;switch(o==null?void 0:o.type){case"number":{if(isNaN(+i))return null;p.push(+i);break}case"union":{if(!o.items.includes(i))return null;p.push(i);break}default:{p.push(i);break}}i=n[l+p.length]}if(p.length<((u=f.min)!==null&&u!==void 0?u:0)||n[l+p.length]&&!e[l+1])return null;a(c.name,p);break}if(d&&!i)return null;if(!i){a(c.name,void 0);continue}switch(o==null?void 0:o.type){case"number":{if(isNaN(+i))return null;a(c.name,+i);break}case"union":{if(!o.items.includes(i))return null;a(c.name,i);break}default:{a(c.name,i);break}}}}}return{path:r,params:t}}}function g(e){if(!e)return null;const r=e[1];let n,t,a;for(const u of e.slice(2))if(u){if(u.includes("<")){n=u.replace("<","").replace(">","");continue}if(u.includes("{")&&(t=u.replace("{","").replace("}","").split(",").map(s=>parseInt(s))),["*","?","+"].includes(u)){a=u;continue}}return{name:r,genericProps:n,arrayProps:t,modificator:a}}function h(e){return r=>{const n=[];if(e.length===0)return"/";for(const t of e)switch(t.type){case"const":{n.push(t.name);break}case"parameter":{if(!r[t.name])continue;if(Array.isArray(r[t.name]))for(const a of r[t.name])n.push(a.toString());else n.push(r[t.name].toString());break}}return"/".concat(n.join("/"))}}function m(e,r){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var t=Object.getOwnPropertySymbols(e);r&&(t=t.filter(function(a){return Object.getOwnPropertyDescriptor(e,a).enumerable})),n.push.apply(n,t)}return n}function y(e){for(var r=1;r<arguments.length;r++){var n=arguments[r]!=null?arguments[r]:{};r%2?m(Object(n),!0).forEach(function(t){v(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):m(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function v(e,r,n){return(r=P(r))in e?Object.defineProperty(e,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[r]=n,e}function P(e){var r=w(e,"string");return typeof r=="symbol"?r:r+""}function w(e,r){if(typeof e!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var t=n.call(e,r);if(typeof t!="object")return t;throw new TypeError("@@toPrimitive must return a primitive value.")}return(r==="string"?String:Number)(e)}function O(e){const r=[],n=/:(\w+)(<[\w|]+>)?({\d+\,\d+})?([+*?])?/,t=e.split("/").filter(Boolean);for(let a=0;a<t.length;a++){const u=t[a];if(!u)continue;const s=g(u.match(n));if(!s){r.push({type:"const",name:u,payload:void 0});continue}const{arrayProps:l,genericProps:i,modificator:c,name:f}=s;if(!f)throw new Error('Invalid path: "'.concat(e,'". Name for argument must be provided'));const o={type:"parameter",name:f,payload:{required:!0}};switch(i&&i==="number"&&(o.payload.genericProps={type:"number"}),i&&i.includes("|")&&(o.payload.genericProps={type:"union",items:i.split("|")}),c){case"*":{o.payload.arrayProps={};break}case"+":{o.payload.arrayProps={min:1};break}case"?":{o.payload.required=!1;break}}l&&(o.payload.arrayProps=y(y({},o.payload.arrayProps),{},{min:l[0],max:l[1]})),r.push(o)}return{parse:b(r),build:h(r)}}exports.compile=O;
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.d.ts CHANGED
@@ -1,77 +1,101 @@
1
1
  export declare type Builder<T> = (params: T) => string;
2
2
 
3
- export declare function compile<T extends string, Params = ParseUrlParams<T>>(path: T): {
4
- /**
5
- * @param input Input path
6
- * @returns `{ path: string; params: Params }` | `null`
7
- */
8
- parse: Parser<Params>;
9
- /**
10
- * @param params Route parameters
11
- * @returns string
3
+ /**
4
+ * @param path Route path
5
+ * @description compiles route and give two functions: build (from params to string) & parse (validate from string and get params)
6
+ * @returns { build: Builder<Params>; parse: Parser<Params>; }
7
+ * @example ```ts
8
+ * import { compile } from '@argon-router/paths';
9
+ *
10
+ * // without params
11
+ * const { parse, build } = compile('/profile');
12
+ *
13
+ * console.log(parse('/profile')) // { path: '/profile', params: null }
14
+ * console.log(parse('/test')) // null
15
+ *
16
+ * console.log(build()) // '/profile'
17
+ *
18
+ * // with params
19
+ * const { parse, build } = compile('/:id');
20
+ *
21
+ * console.log(parse('/movpushmov')) // { path: '/profile', params: { id: 'movpushmov' } }
22
+ * console.log(parse('/')) // null
23
+ *
24
+ * console.log(build({ id: 'movpushmov' })) // '/movpushmov'
25
+ * ```
12
26
  */
13
- build: Builder<Params>;
14
- };
27
+ export declare function compile<T extends string, Params = ParseUrlParams<T>>(path: T): {
28
+ /**
29
+ * @param input Input path
30
+ * @returns `{ path: string; params: Params }` | `null`
31
+ */
32
+ parse: Parser<Params>;
33
+ /**
34
+ * @param params Route parameters
35
+ * @returns string
36
+ */
37
+ build: Builder<Params>;
38
+ };
15
39
 
16
- declare type GenericType<T extends string> = T extends `number` ? number : T extends `${infer A}|${infer B}` ? Union<T> : T;
40
+ declare type GenericType<T extends string> = T extends `number` ? number : T extends `${infer A}|${infer B}` ? Union<T> : T;
17
41
 
18
- declare type Parameter<Name extends string, Payload> = {
19
- [k in Name]: Payload;
20
- };
42
+ declare type Parameter<Name extends string, Payload> = {
43
+ [k in Name]: Payload;
44
+ };
21
45
 
22
- export declare type Parser<T> = (path: string) => {
23
- path: string;
24
- params: T;
25
- } | null;
46
+ export declare type Parser<T> = (path: string) => {
47
+ path: string;
48
+ params: T;
49
+ } | null;
26
50
 
27
- /**
28
- * @description Extracts the parameters from a URL string.
29
- * @example
30
- *
31
- * type Params = ParseUrlParams<'/:id/:name'>;
32
- * // ^----- { id: string, name: string }
33
- *
34
- * type Params = ParseUrlParams<'/:id+'>;
35
- * // ^----- { id: string[] }
36
- *
37
- * type Params = ParseUrlParams<'/:id*'>;
38
- * // ^----- { id: string[] }
39
- *
40
- * type Params = ParseUrlParams<'/:id?'>;
41
- * // ^----- { id?: string }
42
- *
43
- * type Params = ParseUrlParams<'/:id<number>+'>;
44
- * // ^----- { id: number[] }
45
- *
46
- * type Params = ParseUrlParams<'/:id<number>*'>;
47
- * // ^----- { id: number[] }
48
- *
49
- * type Params = ParseUrlParams<'/:id<number>'>;
50
- * // ^----- { id: number }
51
- *
52
- * type Params = ParseUrlParams<'/:id<hello|world>?'>;
53
- * // ^----- { id?: 'hello' | 'world' }
54
- *
55
- * type Params = ParseUrlParams<'/:id<hello|world>+'>;
56
- * // ^----- { id: ('hello' | 'world')[] }
57
- *
58
- * type Params = ParseUrlParams<'/'>;
59
- * // ^----- void
60
- */
61
- export declare type ParseUrlParams<T extends string> = Unwrap<UrlParams<T>>;
51
+ /**
52
+ * @description Extracts the parameters from a URL string.
53
+ * @example ```ts
54
+ * type Params = ParseUrlParams<'/:id/:name'>;
55
+ * // ^----- { id: string, name: string }
56
+ *
57
+ * type Params = ParseUrlParams<'/:id+'>;
58
+ * // ^----- { id: string[] }
59
+ *
60
+ * type Params = ParseUrlParams<'/:id*'>;
61
+ * // ^----- { id: string[] }
62
+ *
63
+ * type Params = ParseUrlParams<'/:id?'>;
64
+ * // ^----- { id?: string }
65
+ *
66
+ * type Params = ParseUrlParams<'/:id<number>+'>;
67
+ * // ^----- { id: number[] }
68
+ *
69
+ * type Params = ParseUrlParams<'/:id<number>*'>;
70
+ * // ^----- { id: number[] }
71
+ *
72
+ * type Params = ParseUrlParams<'/:id<number>'>;
73
+ * // ^----- { id: number }
74
+ *
75
+ * type Params = ParseUrlParams<'/:id<hello|world>?'>;
76
+ * // ^----- { id?: 'hello' | 'world' }
77
+ *
78
+ * type Params = ParseUrlParams<'/:id<hello|world>+'>;
79
+ * // ^----- { id: ('hello' | 'world')[] }
80
+ *
81
+ * type Params = ParseUrlParams<'/'>;
82
+ * // ^----- void
83
+ * ```
84
+ */
85
+ export declare type ParseUrlParams<T extends string> = Unwrap<UrlParams<T>>;
62
86
 
63
- declare type Union<T extends string, Result = void> = T extends `${infer Start}|${infer Type}` ? Union<Type, Result extends void ? Start : Result | Start> : Result extends void ? T : Result | T;
87
+ declare type Union<T extends string, Result = void> = T extends `${infer Start}|${infer Type}` ? Union<Type, Result extends void ? Start : Result | Start> : Result extends void ? T : Result | T;
64
88
 
65
- declare type Unwrap<Result extends UrlParams<any, void>> = {
66
- [k in keyof Result]: Result[k];
67
- };
89
+ declare type Unwrap<Result extends UrlParams<any, void>> = {
90
+ [k in keyof Result]: Result[k];
91
+ };
68
92
 
69
- declare type UrlParameter<T extends string> = T extends `:${infer Name}<${infer Type}>${infer Modificator}` ? Parameter<WithoutModificator<Name>, WithModificator<GenericType<Type>, T>> : T extends `:${infer Name}<${infer Type}>` ? Parameter<Name, GenericType<Type>> : T extends `:${infer Name}` ? Parameter<WithoutModificator<Name>, WithModificator<string, T>> : never;
93
+ declare type UrlParameter<T extends string> = T extends `:${infer Name}<${infer Type}>${infer Modificator}` ? Parameter<WithoutModificator<Name>, WithModificator<GenericType<Type>, T>> : T extends `:${infer Name}<${infer Type}>` ? Parameter<Name, GenericType<Type>> : T extends `:${infer Name}` ? Parameter<WithoutModificator<Name>, WithModificator<string, T>> : never;
70
94
 
71
- declare type UrlParams<T extends string, Result = void> = T extends `/:${infer Parameter}/${infer Route}` ? Result extends void ? UrlParams<`/${Route}`, UrlParameter<`:${Parameter}`>> : UrlParams<`/${Route}`, Result & UrlParameter<`:${Parameter}`>> : T extends `/:${infer Parameter}` ? Result extends void ? UrlParameter<`:${Parameter}`> : Result & UrlParameter<`:${Parameter}`> : T extends `/${infer Static}/${infer Next}` ? UrlParams<`/${Next}`, Result> : Result;
95
+ declare type UrlParams<T extends string, Result = void> = T extends `/:${infer Parameter}/${infer Route}` ? Result extends void ? UrlParams<`/${Route}`, UrlParameter<`:${Parameter}`>> : UrlParams<`/${Route}`, Result & UrlParameter<`:${Parameter}`>> : T extends `/:${infer Parameter}` ? Result extends void ? UrlParameter<`:${Parameter}`> : Result & UrlParameter<`:${Parameter}`> : T extends `/${infer Static}/${infer Next}` ? UrlParams<`/${Next}`, Result> : Result;
72
96
 
73
- 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;
97
+ 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;
74
98
 
75
- declare type WithoutModificator<T extends string> = T extends `${infer K}{${infer Start},${infer End}}${infer Modificator}` ? K : T extends `${infer K}{${infer Start},${infer End}}` ? K : T extends `${infer K}?` ? K : T extends `${infer K}*` ? K : T extends `${infer K}+` ? K : T;
99
+ declare type WithoutModificator<T extends string> = T extends `${infer K}{${infer Start},${infer End}}${infer Modificator}` ? K : T extends `${infer K}{${infer Start},${infer End}}` ? K : T extends `${infer K}?` ? K : T extends `${infer K}*` ? K : T extends `${infer K}+` ? K : T;
76
100
 
77
- export { }
101
+ export { }
package/dist/index.js CHANGED
@@ -1,88 +1,92 @@
1
- function b(e) {
1
+ function h(e) {
2
2
  return (r) => {
3
- const n = r.split("/").filter(Boolean);
3
+ const n = r.split("/").map((u) => u.trim()).filter((u) => u !== "");
4
4
  let t = null;
5
- function a(l, i) {
6
- t || (t = {}), t[l] = i;
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 l = 0; l < e.length; l++) {
14
- let i = n[l];
15
- const c = e[l];
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 (i !== c.name)
17
+ if (o.name !== n.shift())
19
18
  return null;
20
19
  continue;
21
20
  }
22
21
  case "parameter": {
23
22
  const {
24
- arrayProps: f,
25
- genericProps: o,
26
- required: d
27
- } = c.payload;
28
- if (f) {
29
- var u;
30
- const p = [];
31
- for (; i && p.length < ((s = f.max) !== null && s !== void 0 ? s : 1 / 0); ) {
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
- switch (o == null ? void 0 : o.type) {
33
+ if (f = n.shift(), !f)
34
+ break;
35
+ switch (l == null ? void 0 : l.type) {
34
36
  case "number": {
35
- if (isNaN(+i))
37
+ if (isNaN(+f))
36
38
  return null;
37
- p.push(+i);
39
+ m.push(+f);
38
40
  break;
39
41
  }
40
42
  case "union": {
41
- if (!o.items.includes(i))
43
+ if (!l.items.includes(f))
42
44
  return null;
43
- p.push(i);
45
+ m.push(f);
44
46
  break;
45
47
  }
46
48
  default: {
47
- p.push(i);
49
+ m.push(f);
48
50
  break;
49
51
  }
50
52
  }
51
- i = n[l + p.length];
53
+ if (m.length >= ((s = y.max) !== null && s !== void 0 ? s : 1 / 0))
54
+ break;
52
55
  }
53
- if (p.length < ((u = f.min) !== null && u !== void 0 ? u : 0) || n[l + p.length] && !e[l + 1])
56
+ if (m.length < ((a = y.min) !== null && a !== void 0 ? a : 0) || n.length > 0 && !e[u + 1])
54
57
  return null;
55
- a(c.name, p);
58
+ i(o.name, m);
56
59
  break;
57
60
  }
58
- if (d && !i)
61
+ const p = n.shift();
62
+ if (c && !p)
59
63
  return null;
60
- if (!i) {
61
- a(c.name, void 0);
64
+ if (!p) {
65
+ i(o.name, void 0);
62
66
  continue;
63
67
  }
64
- switch (o == null ? void 0 : o.type) {
68
+ switch (l == null ? void 0 : l.type) {
65
69
  case "number": {
66
- if (isNaN(+i))
70
+ if (isNaN(+p))
67
71
  return null;
68
- a(c.name, +i);
72
+ i(o.name, +p);
69
73
  break;
70
74
  }
71
75
  case "union": {
72
- if (!o.items.includes(i))
76
+ if (!l.items.includes(p))
73
77
  return null;
74
- a(c.name, i);
78
+ i(o.name, p);
75
79
  break;
76
80
  }
77
81
  default: {
78
- a(c.name, i);
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, a;
96
- for (const u of e.slice(2))
97
- if (u) {
98
- if (u.includes("<")) {
99
- n = u.replace("<", "").replace(">", "");
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 (u.includes("{") && (t = u.replace("{", "").replace("}", "").split(",").map((s) => parseInt(s))), ["*", "?", "+"].includes(u)) {
103
- a = u;
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: a
115
+ modificator: i
112
116
  };
113
117
  }
114
- function h(e) {
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 a of r[t.name])
130
- n.push(a.toString());
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 m(e, r) {
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(a) {
144
- return Object.getOwnPropertyDescriptor(e, a).enumerable;
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 y(e) {
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 ? m(Object(n), !0).forEach(function(t) {
153
- v(e, t, n[t]);
154
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(n)) : m(Object(n)).forEach(function(t) {
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 v(e, r, n) {
161
- return (r = P(r)) in e ? Object.defineProperty(e, r, { value: n, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = n, e;
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 P(e) {
164
- var r = w(e, "string");
167
+ function w(e) {
168
+ var r = k(e, "string");
165
169
  return typeof r == "symbol" ? r : r + "";
166
170
  }
167
- function w(e, r) {
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 k(e) {
181
+ function O(e) {
178
182
  const r = [], n = /:(\w+)(<[\w|]+>)?({\d+\,\d+})?([+*?])?/, t = e.split("/").filter(Boolean);
179
- for (let a = 0; a < t.length; a++) {
180
- const u = t[a];
181
- if (!u)
183
+ for (let i = 0; i < t.length; i++) {
184
+ const a = t[i];
185
+ if (!a)
182
186
  continue;
183
- const s = g(u.match(n));
187
+ const s = g(a.match(n));
184
188
  if (!s) {
185
189
  r.push({
186
190
  type: "const",
187
- name: u,
191
+ name: a,
188
192
  payload: void 0
189
193
  });
190
194
  continue;
191
195
  }
192
196
  const {
193
- arrayProps: l,
194
- genericProps: i,
195
- modificator: c,
196
- name: f
197
+ arrayProps: u,
198
+ genericProps: o,
199
+ modificator: y,
200
+ name: l
197
201
  } = s;
198
- if (!f)
202
+ if (!l)
199
203
  throw new Error('Invalid path: "'.concat(e, '". Name for argument must be provided'));
200
- const o = {
204
+ const c = {
201
205
  type: "parameter",
202
- name: f,
206
+ name: l,
203
207
  payload: {
204
208
  required: !0
205
209
  }
206
210
  };
207
- switch (i && i === "number" && (o.payload.genericProps = {
211
+ switch (o && o === "number" && (c.payload.genericProps = {
208
212
  type: "number"
209
- }), i && i.includes("|") && (o.payload.genericProps = {
213
+ }), o && o.includes("|") && (c.payload.genericProps = {
210
214
  type: "union",
211
- items: i.split("|")
212
- }), c) {
215
+ items: o.split("|")
216
+ }), y) {
213
217
  case "*": {
214
- o.payload.arrayProps = {};
218
+ c.payload.arrayProps = {};
215
219
  break;
216
220
  }
217
221
  case "+": {
218
- o.payload.arrayProps = {
222
+ c.payload.arrayProps = {
219
223
  min: 1
220
224
  };
221
225
  break;
222
226
  }
223
227
  case "?": {
224
- o.payload.required = !1;
228
+ c.payload.required = !1;
225
229
  break;
226
230
  }
227
231
  }
228
- l && (o.payload.arrayProps = y(y({}, o.payload.arrayProps), {}, {
229
- min: l[0],
230
- max: l[1]
231
- })), r.push(o);
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: b(r),
242
+ parse: h(r),
239
243
  /**
240
244
  * @param params Route parameters
241
245
  * @returns string
242
246
  */
243
- build: h(r)
247
+ build: v(r)
244
248
  };
245
249
  }
246
250
  export {
247
- k as compile
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.0",
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": "02a833234ffa6ca8a6d4704634f73d2451e573d0"
44
+ "gitHead": "5faa9c25438bb19acd19fd19b9d9eb92399a3696"
45
45
  }