Skip to content

Instantly share code, notes, and snippets.

@neiker
Last active April 16, 2024 22:08
Show Gist options
  • Save neiker/874c197cd0cbb06efb328f3cbc6753b3 to your computer and use it in GitHub Desktop.
Save neiker/874c197cd0cbb06efb328f3cbc6753b3 to your computer and use it in GitHub Desktop.
Validación de CUIL (Argentina) en TypeScript / JavaScript
export function cuilValidator(cuil: string): boolean {
if (cuil.length !== 11) {
return false;
}
const [checkDigit, ...rest] = cuil
.split('')
.map(Number)
.reverse();
const total = rest.reduce(
(acc, cur, index) => acc + cur * (2 + (index % 6)),
0,
);
const mod11 = 11 - (total % 11);
if (mod11 === 11) {
return checkDigit === 0;
}
if (mod11 === 10) {
return false;
}
return checkDigit === mod11;
}
@teebu
Copy link

teebu commented Mar 29, 2023

I was looking for a validator, and stumbled on to this library https://github.com/brielov/cuit/tree/master/src and checked their tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment