@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 +3 -2
- package/dist/index.d.ts +87 -63
- package/package.json +2 -2
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
|
|
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
|
-
-
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
*
|
|
11
|
-
*
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
} | null;
|
|
46
|
+
export declare type Parser<T> = (path: string) => {
|
|
47
|
+
path: string;
|
|
48
|
+
params: T;
|
|
49
|
+
} | null;
|
|
26
50
|
|
|
27
|
-
/**
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
*
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
-
|
|
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.
|
|
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": "
|
|
44
|
+
"gitHead": "7f4fbed2048af77d3087cc608fb2fe30c9991d9b"
|
|
45
45
|
}
|