re-nav/source/redirect/regex.ts

10 lines
337 B
TypeScript
Raw Normal View History

2022-11-02 10:10:29 +00:00
import {Redirect} from './base.js';
export class RegexRedirect extends Redirect {
public redirect(redirect: URL | string): string {
2022-11-02 10:10:29 +00:00
const url = redirect instanceof URL ? redirect.href : redirect;
const regex = new RegExp(this.parameters.matcherValue, 'gi');
return url.replace(regex, this.parameters.redirectValue);
2022-11-02 10:10:29 +00:00
}
}