Skip to content

Commit

Permalink
fix: added natural numbers for EC/RUC
Browse files Browse the repository at this point in the history
  • Loading branch information
koblas committed Jul 4, 2023
1 parent 7fca29e commit 7ef8021
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/ec/ruc.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ describe('ec/ruc', () => {
expect(result.isValid && result.compact).toEqual('1792060346001');
});

test.each(['0101016905001', '0962467429001', '1803557964001'])(
'validate:%s',
value => {
const result = validate(value);

expect(result.isValid).toEqual(true);
},
);

it('validate:1792060346-00', () => {
const result = validate('1792060346-00');

Expand Down
7 changes: 6 additions & 1 deletion src/ec/ruc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ const impl: Validator = {
modulus: 11,
}) !== 0
) {
return { isValid: false, error: new exceptions.InvalidChecksum() };
// If it's not a public, try natural
if (end.endsWith('000')) {
return { isValid: false, error: new exceptions.InvalidComponent() };
}

return ci.validate(value.substring(0, 10));
}
} else if (value[2] === '9') {
// Juridical RUC
Expand Down

0 comments on commit 7ef8021

Please sign in to comment.