Skip to content

Commit

Permalink
fixed code format, added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
k3ach committed Oct 27, 2024
1 parent 0c6c45b commit b92c1e7
Show file tree
Hide file tree
Showing 2 changed files with 391 additions and 21 deletions.
10 changes: 5 additions & 5 deletions src/core/operations/LuhnChecksum.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @author n1073645 [[email protected]]
* @author n1073645 [[email protected]]
* @author k3ach [[email protected]]
* @copyright Crown Copyright 2020
* @license Apache-2.0
Expand All @@ -21,7 +21,7 @@ class LuhnChecksum extends Operation {

this.name = "Luhn Checksum";
this.module = "Default";
this.description = "The Luhn mod N algorithm is an extension to the Luhn algorithm (also known as mod 10 algorithm) that allows it to work with sequences of values in any even-numbered base. This can be useful when a check digit is required to validate an identification string composed of letters, a combination of letters and digits or any arbitrary set of N characters where N is divisible by 2.";
this.description = "The Luhn mod N algorithm using the english alphabet. The Luhn mod N algorithm is an extension to the Luhn algorithm (also known as mod 10 algorithm) that allows it to work with sequences of values in any even-numbered base. This can be useful when a check digit is required to validate an identification string composed of letters, a combination of letters and digits or any arbitrary set of N characters where N is divisible by 2.";
this.infoURL = "https://en.wikipedia.org/wiki/Luhn_mod_N_algorithm";
this.inputType = "string";
this.outputType = "string";
Expand Down Expand Up @@ -71,20 +71,20 @@ class LuhnChecksum extends Operation {
run(input, args) {
if (!input) return "";

let radix = args[0];
const radix = args[0];

if (radix < 2 || radix > 36) {
throw new OperationError("Error: Radix argument must be between 2 and 36");
}

if (radix % 2 != 0) {
if (radix % 2 !== 0) {
throw new OperationError("Error: Radix argument must be divisible by 2");
}

const checkSum = this.checksum(input, radix).toString(radix);
let checkDigit = this.checksum(input + "0", radix);
checkDigit = checkDigit === 0 ? 0 : (radix - checkDigit);
checkDigit = checkDigit.toString(radix)
checkDigit = checkDigit.toString(radix);

return `Checksum: ${checkSum}
Checkdigit: ${checkDigit}
Expand Down
Loading

0 comments on commit b92c1e7

Please sign in to comment.