@konplit-services/common 1.0.125 → 1.0.126

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,6 @@
1
+ /**
2
+ * this algorithm is called the luhn algorigth for validating the validity of a card
3
+ * @param cardNumber the card number as string
4
+ * @returns
5
+ */
6
+ export declare const cardValidate: (cardNumber: string) => boolean;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ /**
3
+ * this algorithm is called the luhn algorigth for validating the validity of a card
4
+ * @param cardNumber the card number as string
5
+ * @returns
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.cardValidate = void 0;
9
+ const cardValidate = (cardNumber) => {
10
+ let sum = 0;
11
+ let shouldDouble = false;
12
+ for (let i = cardNumber.length - 1; i >= 0; i--) {
13
+ let digit = parseInt(cardNumber[i], 10);
14
+ if (isNaN(digit)) {
15
+ throw new Error(`Invalid character '${cardNumber[i]}' in card number.`);
16
+ }
17
+ if (shouldDouble) {
18
+ digit *= 2;
19
+ if (digit > 9)
20
+ digit -= 9;
21
+ }
22
+ sum += digit;
23
+ shouldDouble = !shouldDouble;
24
+ }
25
+ return sum % 10 === 0;
26
+ };
27
+ exports.cardValidate = cardValidate;
@@ -38,3 +38,4 @@ export * from "./worker-task-types";
38
38
  export * from "./api-config-types";
39
39
  export * from "./settings-types";
40
40
  export * from "./business-types";
41
+ export * from "./card-validate";
@@ -54,3 +54,4 @@ __exportStar(require("./worker-task-types"), exports);
54
54
  __exportStar(require("./api-config-types"), exports);
55
55
  __exportStar(require("./settings-types"), exports);
56
56
  __exportStar(require("./business-types"), exports);
57
+ __exportStar(require("./card-validate"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@konplit-services/common",
3
- "version": "1.0.125",
3
+ "version": "1.0.126",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",