angular/aio/tools/firebase-test-utils/FirebaseRedirect.ts
2018-01-23 13:33:36 -08:00

16 lines
481 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) {
const match = this.glob.match(url);
if (match) {
const replacers = Object.keys(match).map(name => [ XRegExp(`:${name}`, 'g'), match[name] ]);
return XRegExp.replaceEach(this.destination, replacers);
}
}
}