Created
June 5, 2018 10:16
-
-
Save faisalmuhammad/6765814034630ee45f04b3c4e525188a to your computer and use it in GitHub Desktop.
Pipe to replace the value with * or specified character
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @author Muhammad Faisal | |
* @description Pipe to replace the value with * or specified character. | |
*/ | |
// Angular Imports | |
import { Pipe, PipeTransform } from '@angular/core'; | |
@Pipe({ | |
name: 'password' | |
}) | |
export class PasswordPipe implements PipeTransform { | |
transform(value: string, replaceChar?: string): any { | |
if (value === undefined) { | |
return value; | |
} | |
// Replace with the specified character | |
if (replaceChar) { | |
return replaceChar.repeat(value.length); | |
} | |
// Replace value with asterisks | |
return '*'.repeat(value.length); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment