https://github.com/angular/angular
Raw File
Tip revision: acffa22a35859df8105733edb990f1a8406c4387 authored by Kara Erickson on 26 September 2018, 19:02:03 UTC
release: cut the v6.1.9 release
Tip revision: acffa22
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) {
    const match = this.glob.match(url);
    if (match) {
      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