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

80% Statements 8/10
77.77% Branches 7/9
100% Functions 3/3
77.77% Lines 7/9

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 31                107x   11x       14x       14x 1x   1x         13x        
import { DecimalPipe } from '@angular/common';
import { Pipe, PipeTransform } from '@angular/core';
 
 
@Pipe({
  name: 'value',
  standalone: true,
})
export class ValuePipe implements PipeTransform {
 
  constructor(private decimalPipe: 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;
  }
 
}