Skip to content

Instantly share code, notes, and snippets.

@faisalmuhammad
Created June 5, 2018 10:16
Show Gist options
  • Save faisalmuhammad/6765814034630ee45f04b3c4e525188a to your computer and use it in GitHub Desktop.
Save faisalmuhammad/6765814034630ee45f04b3c4e525188a to your computer and use it in GitHub Desktop.
Pipe to replace the value with * or specified character
/**
* @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