UNPKG

documentid-checksum-validator

Version:
34 lines (30 loc) 1.03 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); exports['default'] = isValidDocId; function isValidDocId(inpValue) { var valueArray = inpValue.split(''); var valid = true; // standard multiplier for validating sin var multiplierString = [1, 2, 1, 2, 1, 2, 1, 2, 1]; var sum = 0; for (var i = 0; i < multiplierString.length; i++) { var value = multiplierString[i] * valueArray[i]; /* if the value of the multiplication is greater then 9 then sum the digits of the number and add thaat to the final sum */ if (value > 9) { /* The letiable obtained value denotes the value obtained by the product of multiplier string and the value array */ var obtainedValue = value; value = obtainedValue % 10 + Math.floor(obtainedValue / 10); } sum += value; } if (sum % 10 !== 0) { valid = false; } return valid; } module.exports = exports['default'];