Skip to content

Instantly share code, notes, and snippets.

@VivienGiraud
Created May 24, 2018 20:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VivienGiraud/57e017953e17bc187122c743b66b67ba to your computer and use it in GitHub Desktop.
Save VivienGiraud/57e017953e17bc187122c743b66b67ba to your computer and use it in GitHub Desktop.
function pad(n, width, z) {
z = z || '0';
n = n + '';
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
}
function get_key(siren) {
if (siren.length != 9) {
return null;
} else {
return pad((12 + 3 * (siren % 97)) % 97, 2);
}
}
function return_tva_intracommunautaire_number(siren) {
return 'FR ' + get_key(siren) + ' ' + siren
}
console.log(return_tva_intracommunautaire_number('000000000'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment