All files / src/app/pipes value.pipe.ts

63.63% Statements 7/11
55.55% Branches 5/9
100% Functions 2/2
60% Lines 6/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30                119x 10x       13x       13x               13x 109x      
import { DecimalPipe } from '@angular/common';
import { Pipe, PipeTransform, inject } from '@angular/core';
 
 
@Pipe({
  name: 'value',
  standalone: true,
})
export class ValuePipe implements PipeTransform {
  private decimalPipe = inject(DecimalPipe);
 
  transform(value: string | number | undefined , decimalFormat: string = '1.0-2'): string | null{
    // Check if the value is a number
    Iif (value === undefined){
      return '';
    }
 
    Iif (typeof value == "number"){
      if (!isNaN(value)) {
        // Apply Angular's DecimalPipe
        return this.decimalPipe.transform(value, decimalFormat);
      }
      return "";
    }
    // If it's not a number, return the value as-is
    return value;
  }
 
}