re-nav/source/redirect/exports.ts

31 lines
841 B
TypeScript
Raw Normal View History

import {RedirectParameters} from './base.js';
2022-10-05 17:08:17 +00:00
import {HostnameRedirect} from './hostname.js';
2022-11-02 10:10:29 +00:00
import {RegexRedirect} from './regex.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-11-02 10:10:29 +00:00
export * from './regex.js';
2022-10-18 16:29:01 +00:00
export * from './simple.js';
2022-10-05 17:08:17 +00:00
export type Redirects = HostnameRedirect | RegexRedirect | SimpleRedirect;
2022-10-05 17:08:17 +00:00
export function parseRedirect(
parameters: RedirectParameters,
2022-10-05 17:08:17 +00:00
): Redirects | undefined {
2022-11-02 10:10:29 +00:00
const matcherType = parameters?.matcherType;
const redirectType = parameters?.redirectType;
2022-10-18 16:59:05 +00:00
if (redirectType === 'hostname') {
return new HostnameRedirect(parameters);
2022-10-05 17:08:17 +00:00
}
2022-10-18 16:59:05 +00:00
if (redirectType === 'simple') {
return new SimpleRedirect(parameters);
2022-10-18 16:59:05 +00:00
}
2022-11-02 10:10:29 +00:00
if (matcherType === 'regex' && redirectType === 'regex') {
return new RegexRedirect(parameters);
}
2022-10-05 17:08:17 +00:00
}