File

projects/app-base-library/src/lib/angular/pipes/between.pipe.ts

Metadata

name replaceAll

Methods

transform
transform(value: string, prefix: string, suffix: string, ignoreCase: boolean)
Parameters :
Name Type Optional
value string no
prefix string no
suffix string no
ignoreCase boolean no
Returns : any
import {Pipe, PipeTransform} from '@angular/core';

@Pipe({
    name: 'replaceAll'
})
export class BetweenPipe implements PipeTransform {

    transform(value: string, prefix: string, suffix: string, ignoreCase: boolean): any {
        if (!value) {
            return value;
        }

        function between(s: string, prefix: string, suffix: string) {
            // Usage:  var betweenResult = between('hello you guys','hello ',' guys');
            let i = s.indexOf(prefix);
            if (i >= 0) {
                s = s.substring(i + prefix.length);
            } else {
                return '';
            }
            if (suffix) {
                i = s.indexOf(suffix);
                if (i >= 0) {
                    s = s.substring(0, i);
                } else {
                    return '';
                }
            }
            return s;
        }

        return between(value, prefix, suffix);
    }

}

results matching ""

    No results matching ""