title: Angular pipe with multiple patterns
body: <p>I have a simple custom pipe that implements DecimalPipe transform() method, like so:</p>
  
  <pre><code>export class MyDecimalFormatPipe implements PipeTransform {
  
      constructor(public decimalPipe: DecimalPipe) {};
  
      transform(value: any) {
          if (value || value === 0) {
              value = this.decimalPipe.transform(value, '1.2-2');
          }
          return value;
      }
  } 
  </code></pre>
  
  <p>This is the plunker link: <a href="https://plnkr.co/edit/eEfXoXdM1OakuX1TjR1N?p=preview" rel="nofollow noreferrer">https://plnkr.co/edit/eEfXoXdM1OakuX1TjR1N?p=preview</a><br>
  Obviously , this is not much of a custom pipe, as it implements DecimalPipe, but my ultimate goal is to have this pipe support more patterns other than '1.2-2'.  I did some research and everyone seems to using control structures like if/else or switch statements.  I suppose that would look like:</p>
  
  <pre><code>export class MyDecimalFormatPipe implements PipeTransform {
  
      constructor(public decimalPipe: DecimalPipe) {};
  
      transform(value: any) {
          if (somevalue) {
              let format = '1.2-2'
              value = this.decimalPipe.transform(value, format);
          }
          else if (othervalue) {
              let format = '1.4-4'
              value = this.decimalPipe.transform(value, format);
          }
          ...
          return value
      }
  } 
  </code></pre>
  
  <p>This seems wrong and 'clunky' and this method would get rather large as we add more format patterns.  I suppose a pipe should have a number of pre-set format patterns that will be set based on the input value.  One could create a method for this perhaps, like so:</p>
  
  <pre><code>setFormatPattern(inputPattern: string): string {
      let pattern: any;
      this.myPatternsArray.forEach(element =&gt; {
          if (element.format === inputPattern ) {
             pattern = element.pattern;
          }
      });
      return pattern;
  }
  </code></pre>
  
  <p>I am struggling with design as well as the implementation(code) of this problem.  There must be an easier way...</p>