https://github.com/angular/angular
Raw File
Tip revision: 6bacd32fbd26952231d6c4ae9b654703dae22cfd authored by Igor Minar on 02 August 2018, 18:42:10 UTC
release: cut the v7.0.0-beta.0 release
Tip revision: 6bacd32
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