https://github.com/angular/angular
Raw File
Tip revision: 0560751381df2250419efec0207297a9271688a8 authored by Vikram Subramanian on 22 July 2018, 07:05:53 UTC
fix(core): stop reusing provider definitions across NgModuleRef instances (#25088)
Tip revision: 0560751
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