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

81.81% Statements 9/11
77.77% Branches 7/9
100% Functions 2/2
80% Lines 8/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                123x 15x       18x       18x 2x   2x         16x 108x      
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 '';
    }
 
    if (typeof value == "number"){
      Eif (!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;
  }
 
}