Created
May 14, 2013 19:41
-
-
Save renatoargh/5578849 to your computer and use it in GitHub Desktop.
Algoritmo para formatar chave de acesso da nota fiscal eletrônica (NFe) em JavaScript.
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
| function formatarChaveDeAcessoNfe(chave){ | |
| if(chave.length !== 44) return chave; | |
| else{ | |
| return chave.split("").reduceRight(function(elemento, anterior){ | |
| var temp = anterior + elemento; | |
| if(temp.replace(/\s/g, "").length % 4 === 0) return " " + temp; | |
| else return temp; | |
| }); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment