All files / src/app/core/pipes html-encode.pipe.ts

100% Statements 4/4
100% Branches 0/0
100% Functions 1/1
100% Lines 3/3

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 143x               3x   2x      
import { Pipe, PipeTransform } from '@angular/core';
 
/**
 * The HTML encode pipe simply replaces HTML special characters like angle brackets (< and >) with HTML entities
 * so they can be displayed as plain text in a web page.
 * https://jasonwatmore.com/vanilla-js-html-encode-in-javascript
 */
@Pipe({ name: 'ishHtmlEncode', pure: true })
export class HtmlEncodePipe implements PipeTransform {
  transform(value: string): string {
    return value?.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
  }
}