checksums.js 632 B

1234567891011121314151617181920212223242526272829
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.mod10 = mod10;
  6. exports.mod11 = mod11;
  7. function mod10(number) {
  8. var sum = 0;
  9. for (var i = 0; i < number.length; i++) {
  10. var n = parseInt(number[i]);
  11. if ((i + number.length) % 2 === 0) {
  12. sum += n;
  13. } else {
  14. sum += n * 2 % 10 + Math.floor(n * 2 / 10);
  15. }
  16. }
  17. return (10 - sum % 10) % 10;
  18. }
  19. function mod11(number) {
  20. var sum = 0;
  21. var weights = [2, 3, 4, 5, 6, 7];
  22. for (var i = 0; i < number.length; i++) {
  23. var n = parseInt(number[number.length - 1 - i]);
  24. sum += weights[i % weights.length] * n;
  25. }
  26. return (11 - sum % 11) % 11;
  27. }