This is to fix the below error: ``` tools/firebase-test-utils/FirebaseRedirect.ts:17:50 - error TS2345: Argument of type '(string | RegExp)[][]' is not assignable to parameter of type 'ReplacementDetail[]'. Type '(string | RegExp)[]' is missing the following properties from type 'ReplacementDetail': 0, 1 17 return XRegExp.replaceEach(this.destination, [...paramReplacers, ...restReplacers]); ``` https://app.circleci.com/pipelines/github/angular/angular/31076/workflows/5fd3851e-ae9e-4d77-b0ef-366ba38a9088/jobs/961795 PR Close #41596
20 lines
728 B
TypeScript
20 lines
728 B
TypeScript
import * as XRegExp from 'xregexp';
|
|
import { FirebaseGlob } from './FirebaseGlob';
|
|
|
|
export class FirebaseRedirect {
|
|
glob = new FirebaseGlob(this.source);
|
|
constructor(public source: string, public destination: string) {}
|
|
|
|
replace(url: string): string | undefined {
|
|
const match = this.glob.match(url);
|
|
|
|
if (!match) {
|
|
return undefined;
|
|
}
|
|
|
|
const paramReplacers = Object.keys(this.glob.namedParams).map<[RegExp, string]>(name => [ XRegExp(`:${name}`, 'g'), match[name] ]);
|
|
const restReplacers = Object.keys(this.glob.restParams).map<[RegExp, string]>(name => [ XRegExp(`:${name}\\*`, 'g'), match[name] ]);
|
|
return XRegExp.replaceEach(this.destination, [...paramReplacers, ...restReplacers]);
|
|
}
|
|
}
|