https://github.com/angular/angular
Raw File
Tip revision: 6d4f437973d2d3be6bfa91a54bf0a021da5155db authored by Paul Gschwendtner on 12 March 2020, 20:10:41 UTC
build: ng_rollup_bundle internal rule should support ngcc (#36044)
Tip revision: 6d4f437
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