import { Pipe , PipeTransform } from "@angular/core" ; import { Utils } from "jslib-common/misc/utils" ; @ Pipe ( { name : "colorPassword" } ) export class ColorPasswordPipe implements PipeTransform { transform ( password ) { const passwordArray = Array . from ( password ) ; let colorizedPassword = "" ; for ( let i = 0 ; i < passwordArray . length ; i ++ ) { let character = passwordArray [ i ] ; let isSpecial = false ; switch ( character ) { case "&" : character = "&amp;" ; isSpecial = true ; break ; case "<" : character = "&lt;" ; isSpecial = true ; break ; case ">" : character = "&gt;" ; isSpecial = true ; break ; case " " : character = "&nbsp;" ; isSpecial = true ; break ; default : break ; } let type = "letter" ; if ( character . match ( Utils . regexpEmojiPresentation ) ) { type = "emoji" ; } else if ( isSpecial || character . match ( /[^\w ]/ ) ) { type = "special" ; } else if ( character . match ( /\d/ ) ) { type = "number" ; } colorizedPassword += '<span class="password-' + type + '">' + character + "</span>" ; } return colorizedPassword ; } }