ng2-pipes
Version:
Useful angular2 pipes
13 lines (10 loc) • 404 B
text/typescript
import {PipeTransform, Pipe} from '@angular/core';
import GeneralHelper from '../helpers/helpers';
({name: 'scan'})
export class ScanPipe implements PipeTransform {
transform(text: string, args: string[] = []): string {
return GeneralHelper.isString(text)
? text.replace(/\{(\d+)}/g, (match, index) => !GeneralHelper.isUndefined(args[index]) ? args[index] : match)
: text;
}
}