@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 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.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.1",
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": "7f4fbed2048af77d3087cc608fb2fe30c9991d9b"
44
+ "gitHead": "5faa9c25438bb19acd19fd19b9d9eb92399a3696"
45
45
  }