https://github.com/angular/angular
Raw File
Tip revision: d36828a7a13938af634c213ae2c7999b11ce304a authored by Misko Hevery on 24 August 2020, 22:38:13 UTC
release: cut the v10.1.0-next.8 release
Tip revision: d36828a
FirebaseRedirect.ts
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(name => [ XRegExp(`:${name}`, 'g'), match[name] ]);
    const restReplacers = Object.keys(this.glob.restParams).map(name => [ XRegExp(`:${name}\\*`, 'g'), match[name] ]);
    return XRegExp.replaceEach(this.destination, [...paramReplacers, ...restReplacers]);
  }
}
back to top