Skip to content

Instantly share code, notes, and snippets.

@renatoargh
Created May 14, 2013 19:41
Show Gist options
  • Select an option

  • Save renatoargh/5578849 to your computer and use it in GitHub Desktop.

Select an option

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.
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