Skip to content

Instantly share code, notes, and snippets.

@carlitomurta
Created November 22, 2019 14:08
Show Gist options
  • Save carlitomurta/e69f2763d35b619c27be696b0220246c to your computer and use it in GitHub Desktop.
Save carlitomurta/e69f2763d35b619c27be696b0220246c to your computer and use it in GitHub Desktop.
Pipe Angular para Linha digitável de Boletos
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