https://github.com/angular/angular
Raw File
Tip revision: c6ca7b4a12c4b74720f30fa490e72760641c6d73 authored by Andrew Scott on 13 January 2021, 18:49:09 UTC
release: cut the v11.0.9 release (#40414)
Tip revision: c6ca7b4
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