https://github.com/angular/angular
Raw File
Tip revision: 7ca17a624988bdcf403f45827feffb908b4c3379 authored by George Kalpakas on 21 October 2020, 09:20:37 UTC
build(docs-infra): upgrade cli command docs sources to cba6d86ca (#39360)
Tip revision: 7ca17a6
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