dzonatan / ngx-linky

Linky pipe for angular
MIT License
41 stars 13 forks source link

Default options for all pipes #7

Open HugoHeneault opened 6 years ago

HugoHeneault commented 6 years ago

First things firsts: thanks for your really cool pipe! :)

I'm working on an ionic app and I need to change the replaceFn for all pipes I use. It would be great if I could set it for the whole linky module instead of pipe by pipe.

How could I do that?

dzonatan commented 6 years ago

Hi. Thanks!

You could create your own pipe as a wrapper:

import { Pipe, PipeTransform } from '@angular/core';
import { LinkyPipe } from 'angular-linky';

@Pipe({ name: 'myLinky' })
export class MyLinkyPipe implements PipeTransform {
  transform(value: string, options: any = {}): string {
    // modify options here - add defaults like:
    options.replaceFn = options.replaceFn || yourDefaultReplaceFn;

    return new LinkyPipe().transform(value, options);
  }
}
HugoHeneault commented 6 years ago

Cool! I'll use this for now. You can close it if you don't plan to make it one day :) Thanks!