Created
November 22, 2019 14:08
-
-
Save carlitomurta/e69f2763d35b619c27be696b0220246c to your computer and use it in GitHub Desktop.
Pipe Angular para Linha digitável de Boletos
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
import { Pipe, PipeTransform } from '@angular/core'; | |
@Pipe({ | |
name: 'codigoBarras' | |
}) | |
export class CodigoBarrasPipe implements PipeTransform { | |
transform(value: string, args?: any): any { | |
if (value) { | |
value = value.replace(/\D/g, ''); | |
if (value.length > 47) { | |
value = value.substring(0, 47); | |
} | |
if (value.length === 47) { | |
value = value.replace(/(\d{5})(\d{5})(\d{5})(\d{6})(\d{5})(\d{6})(\d{1})(\d+)/, '$1.$2 $3.$4 $5.$6 $7 $8'); | |
} | |
} | |
return value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment