@argon-router/paths 0.6.0 → 0.6.1

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.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/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.1",
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": "7f4fbed2048af77d3087cc608fb2fe30c9991d9b"
45
45
  }