re-nav/source/redirect/exports.ts

24 lines
594 B
TypeScript
Raw Normal View History

2022-10-05 17:08:17 +00:00
import {HostnameRedirect} from './hostname.js';
2022-10-18 16:29:01 +00:00
import {SimpleRedirect} from './simple.js';
2022-10-05 17:08:17 +00:00
export * from './base.js';
export * from './hostname.js';
2022-10-18 16:29:01 +00:00
export * from './simple.js';
2022-10-05 17:08:17 +00:00
2022-10-18 16:29:01 +00:00
export type Redirects = HostnameRedirect | SimpleRedirect;
2022-10-05 17:08:17 +00:00
2022-10-12 22:04:51 +00:00
export function parseRedirect<P extends Redirects['parameters']>(
2022-10-05 17:08:17 +00:00
parameters: P,
2022-10-19 19:10:41 +00:00
id: string,
2022-10-05 17:08:17 +00:00
): Redirects | undefined {
const redirectType = parameters?.redirectType;
2022-10-18 16:59:05 +00:00
if (redirectType === 'hostname') {
2022-10-19 19:10:41 +00:00
return new HostnameRedirect(parameters, id);
2022-10-05 17:08:17 +00:00
}
2022-10-18 16:59:05 +00:00
if (redirectType === 'simple') {
2022-10-19 19:10:41 +00:00
return new SimpleRedirect(parameters, id);
2022-10-18 16:59:05 +00:00
}
2022-10-05 17:08:17 +00:00
}