-
Notifications
You must be signed in to change notification settings - Fork 0
/
regex-patterns.ts
108 lines (104 loc) · 3.8 KB
/
regex-patterns.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/**
* Contains Regular Expressions for parsing PerpetualOS URLs.
*/
export const PATTERNS = {
/**
* Matches a canister ID principal string.
*
* Example:
* matches[0] abcde-biaaa-aaaal-qbhwa-cai
*/
CanisterId: /(?:[a-z0-9]{5}-){4}[a-z0-9]{3}/i,
/**
* Matches the following URL formats:
* - https://{canister_id}.raw.icp0.io/...
* - https://{canister_id}.icp0.io/...
* - https://{canister_id}.raw.ic0.app/...
* - https://{canister_id}.ic0.app/...
* - http://{canister_id}.localhost:8080/...
*
* Example matches:
* - https://abcde-biaaa-aaaal-qbhwa-cai.raw.icp0.io
* - matches.groups.id abcde-biaaa-aaaal-qbhwa-cai
* - matches.groups.domain raw.icp0.io
* - https://abcde-biaaa-aaaal-qbhwa-cai.localhost:8080
* - matches.groups.id abcde-biaaa-aaaal-qbhwa-cai
* - matches.groups.domain localhost:8080
*
* Notes:
* - The id should be a canister ID.
* - Test it with the CanisterId pattern.
* - If it's not a canister ID, it's invalid.
*/
DirectCanisterUrl:
/https?:\/\/(?<id>[^\.]*)\.(?<domain>(?:(?:raw\.)?(?:ic0\.app|icp0\.io))|(?:localhost:(?<port>\d+)))/i,
/**
* Matches the following URL formats:
* - http://localhost:3000/-/{canister_id}/...
* - http://localhost:8080/-/{canister_id}/
* - https://prptl.io/-/{canister_id}/...
* - https://icx-proxy.origyn.ch/-/{canister_id}/...
* - https://exos.origyn.network/-/{canister_id}/...
* - http://localhost:3000/-/{canister_name}/...
* - http://localhost:8080/-/{canister_name}/
* - https://prptl.io/-/{canister_name}/...
* - https://icx-proxy.origyn.ch/-/{canister_name}/...
* - https://exos.origyn.network/-/{canister_name}/...
*
* Example matches:
* - http://prptl.io/-/abcde-biaaa-aaaal-qbhwa-cai
* - matches.groups.domain: prptl.io
* - matches.groups.id: abcde-biaaa-aaaal-qbhwa-cai
* - http://localhost:3000/-/brain-matters
* - matches.groups.domain: localhost:3000
* - matches.groups.id: brain-matters
*
* Note:
* - The id is either the canister ID or the collection ID (registered in the phone book canister)
* - First, test it with the `CanisterId` pattern.
* - If it's not a canister ID, look up the collection ID in the phone book to get the canister ID.
* - If the collection ID is not found in the phone book, it's invalid.
*/
ProxyCanisterUrl:
/https?:\/\/(?<domain>(?:prptl\.io)|(?:icx-proxy\.origyn\.ch)|(?:exos\.origyn\.network)|(?:localhost:(?<port>\d+)))\/-\/(?<id>[^\/\?#]*)/i,
/**
* Matches the following canister-relative URL formats:
* - /collection
* - /collection/info
* - /collection/-/library-asset.png
*
* Example matches:
* - /collection
* - matches.groups.known: undefined
* - matches.groups.asset: undefined
* - /collection/info
* - matches.groups.known: info
* - matches.groups.asset: undefined
* - /collection/-/library-asset.png
* - matches.groups.known: undefined
* - matches.groups.asset: library-asset.png
*/
CollectionRelativeUrl: /\/collection(?:\/(?:(?:-\/(?<asset>[^\/\?#]*))|(?<known>[^\/\?#]*)))?/i,
/**
* Matches the following canister-relative URL formats:
* - /-/token-1
* - /-/token-1/info
* - /-/token-1/-/library-asset.png
*
* Example matches:
* - /-/token-1
* - matches.groups.token: token-1
* - matches.groups.known: undefined
* - matches.groups.asset: undefined
* - /-/token-1/info
* - matches.groups.token: token-1
* - matches.groups.known: info
* - matches.groups.asset: undefined
* - /-/token-1/-/library-asset.png
* - matches.groups.token: token-1
* - matches.groups.known: undefined
* - matches.groups.asset: library-asset.png
*/
TokenRelativeUrl:
/\/-\/(?<token>[^\/\?#]*)(?:\/(?:(?:-\/(?<asset>[^\/\?#]*))|(?<known>[^\/\?#]*)))?/i,
};