mirror of
https://github.com/supabase/supabase.git
synced 2026-07-05 07:14:28 +08:00
25 lines
1.1 KiB
TypeScript
25 lines
1.1 KiB
TypeScript
// Regex from: https://stackoverflow.com/a/68002755/4807782
|
|
// modified to accept numbers in the body of domain though
|
|
// examples of matches:
|
|
// "vercel.com"
|
|
// "www.vercel.com"
|
|
// "uptime-monitor-fe.vercel.app"
|
|
// "https://uptime-monitor-fe.vercel.app/"
|
|
|
|
// Supports wildcards, port numbers at the end, paths at the end and query params
|
|
const baseDomainRegex =
|
|
/^((ftp|http|https):\/\/)?(www.)?(?!.*(ftp|http|https|www.))[a-zA-Z0-9_*-]+(\.[a-zA-Z0-9_*-]+)+((\/)[\w#]+)*(\/\w+\?[a-zA-Z0-9_]+=\w+(&[a-zA-Z0-9_]+=\w+)*)+(?:\.[a-z]+)*(?::\d+)?(?![^<]*(?:<\/\w+>|\/?>))(.*)?\/?(.)*?$/gm
|
|
|
|
// iOS deep linking scheme https://benoitpasquier.com/deep-linking-url-scheme-ios/
|
|
const appRegex =
|
|
/^[a-z0-9]+([.][a-z0-9]+)*:\/(\/[-a-z0-9._~!$&'()*+,;=:@%]+)+(?:\.[a-z]+)*(?::\d+)?(?![^<]*(?:<\/\w+>|\/?>))(.*)?\/?(.)*?$/i
|
|
|
|
// Regex from https://stackoverflow.com/a/18696953/4807782
|
|
const localhostRegex = /^(?:^|\s)((https?:\/\/)?(?:localhost|[\w-]+(?:\.[\w-]+)+)(:\d+)?(\/\S*)?)/i
|
|
|
|
// combine the above regexes
|
|
export const domainRegex = new RegExp(
|
|
`(${baseDomainRegex.source})|(${localhostRegex.source})|(${appRegex.source})`,
|
|
'i'
|
|
)
|