re-nav/source/redirect/exports.ts

23 lines
540 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,
): Redirects | undefined {
2022-10-18 16:59:05 +00:00
const type = parameters?.type;
if (type === 'hostname') {
2022-10-05 17:08:17 +00:00
return new HostnameRedirect(parameters);
}
2022-10-18 16:59:05 +00:00
if (type === 'simple') {
return new SimpleRedirect(parameters);
}
2022-10-05 17:08:17 +00:00
}