summaryrefslogtreecommitdiff
path: root/includes/external/addressbook/node_modules/validator/lib/util
diff options
context:
space:
mode:
Diffstat (limited to 'includes/external/addressbook/node_modules/validator/lib/util')
-rw-r--r--includes/external/addressbook/node_modules/validator/lib/util/algorithms.js101
-rw-r--r--includes/external/addressbook/node_modules/validator/lib/util/assertString.js22
-rw-r--r--includes/external/addressbook/node_modules/validator/lib/util/includes.js17
-rw-r--r--includes/external/addressbook/node_modules/validator/lib/util/merge.js22
-rw-r--r--includes/external/addressbook/node_modules/validator/lib/util/multilineRegex.js22
-rw-r--r--includes/external/addressbook/node_modules/validator/lib/util/toString.js25
-rw-r--r--includes/external/addressbook/node_modules/validator/lib/util/typeOf.js20
7 files changed, 229 insertions, 0 deletions
diff --git a/includes/external/addressbook/node_modules/validator/lib/util/algorithms.js b/includes/external/addressbook/node_modules/validator/lib/util/algorithms.js
new file mode 100644
index 0000000..cf8e512
--- /dev/null
+++ b/includes/external/addressbook/node_modules/validator/lib/util/algorithms.js
@@ -0,0 +1,101 @@
+"use strict";
+
+Object.defineProperty(exports, "__esModule", {
+ value: true
+});
+exports.iso7064Check = iso7064Check;
+exports.luhnCheck = luhnCheck;
+exports.reverseMultiplyAndSum = reverseMultiplyAndSum;
+exports.verhoeffCheck = verhoeffCheck;
+
+/**
+ * Algorithmic validation functions
+ * May be used as is or implemented in the workflow of other validators.
+ */
+
+/*
+ * ISO 7064 validation function
+ * Called with a string of numbers (incl. check digit)
+ * to validate according to ISO 7064 (MOD 11, 10).
+ */
+function iso7064Check(str) {
+ var checkvalue = 10;
+
+ for (var i = 0; i < str.length - 1; i++) {
+ checkvalue = (parseInt(str[i], 10) + checkvalue) % 10 === 0 ? 10 * 2 % 11 : (parseInt(str[i], 10) + checkvalue) % 10 * 2 % 11;
+ }
+
+ checkvalue = checkvalue === 1 ? 0 : 11 - checkvalue;
+ return checkvalue === parseInt(str[10], 10);
+}
+/*
+ * Luhn (mod 10) validation function
+ * Called with a string of numbers (incl. check digit)
+ * to validate according to the Luhn algorithm.
+ */
+
+
+function luhnCheck(str) {
+ var checksum = 0;
+ var second = false;
+
+ for (var i = str.length - 1; i >= 0; i--) {
+ if (second) {
+ var product = parseInt(str[i], 10) * 2;
+
+ if (product > 9) {
+ // sum digits of product and add to checksum
+ checksum += product.toString().split('').map(function (a) {
+ return parseInt(a, 10);
+ }).reduce(function (a, b) {
+ return a + b;
+ }, 0);
+ } else {
+ checksum += product;
+ }
+ } else {
+ checksum += parseInt(str[i], 10);
+ }
+
+ second = !second;
+ }
+
+ return checksum % 10 === 0;
+}
+/*
+ * Reverse TIN multiplication and summation helper function
+ * Called with an array of single-digit integers and a base multiplier
+ * to calculate the sum of the digits multiplied in reverse.
+ * Normally used in variations of MOD 11 algorithmic checks.
+ */
+
+
+function reverseMultiplyAndSum(digits, base) {
+ var total = 0;
+
+ for (var i = 0; i < digits.length; i++) {
+ total += digits[i] * (base - i);
+ }
+
+ return total;
+}
+/*
+ * Verhoeff validation helper function
+ * Called with a string of numbers
+ * to validate according to the Verhoeff algorithm.
+ */
+
+
+function verhoeffCheck(str) {
+ var d_table = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 2, 3, 4, 0, 6, 7, 8, 9, 5], [2, 3, 4, 0, 1, 7, 8, 9, 5, 6], [3, 4, 0, 1, 2, 8, 9, 5, 6, 7], [4, 0, 1, 2, 3, 9, 5, 6, 7, 8], [5, 9, 8, 7, 6, 0, 4, 3, 2, 1], [6, 5, 9, 8, 7, 1, 0, 4, 3, 2], [7, 6, 5, 9, 8, 2, 1, 0, 4, 3], [8, 7, 6, 5, 9, 3, 2, 1, 0, 4], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]];
+ var p_table = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 5, 7, 6, 2, 8, 3, 0, 9, 4], [5, 8, 0, 3, 7, 9, 6, 1, 4, 2], [8, 9, 1, 6, 0, 4, 3, 5, 2, 7], [9, 4, 5, 3, 1, 2, 6, 8, 7, 0], [4, 2, 8, 6, 5, 7, 3, 9, 0, 1], [2, 7, 9, 3, 8, 0, 6, 4, 1, 5], [7, 0, 4, 6, 9, 1, 3, 2, 5, 8]]; // Copy (to prevent replacement) and reverse
+
+ var str_copy = str.split('').reverse().join('');
+ var checksum = 0;
+
+ for (var i = 0; i < str_copy.length; i++) {
+ checksum = d_table[checksum][p_table[i % 8][parseInt(str_copy[i], 10)]];
+ }
+
+ return checksum === 0;
+} \ No newline at end of file
diff --git a/includes/external/addressbook/node_modules/validator/lib/util/assertString.js b/includes/external/addressbook/node_modules/validator/lib/util/assertString.js
new file mode 100644
index 0000000..2c508af
--- /dev/null
+++ b/includes/external/addressbook/node_modules/validator/lib/util/assertString.js
@@ -0,0 +1,22 @@
+"use strict";
+
+Object.defineProperty(exports, "__esModule", {
+ value: true
+});
+exports.default = assertString;
+
+function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
+
+function assertString(input) {
+ var isString = typeof input === 'string' || input instanceof String;
+
+ if (!isString) {
+ var invalidType = _typeof(input);
+
+ if (input === null) invalidType = 'null';else if (invalidType === 'object') invalidType = input.constructor.name;
+ throw new TypeError("Expected a string but received a ".concat(invalidType));
+ }
+}
+
+module.exports = exports.default;
+module.exports.default = exports.default; \ No newline at end of file
diff --git a/includes/external/addressbook/node_modules/validator/lib/util/includes.js b/includes/external/addressbook/node_modules/validator/lib/util/includes.js
new file mode 100644
index 0000000..e061828
--- /dev/null
+++ b/includes/external/addressbook/node_modules/validator/lib/util/includes.js
@@ -0,0 +1,17 @@
+"use strict";
+
+Object.defineProperty(exports, "__esModule", {
+ value: true
+});
+exports.default = void 0;
+
+var includes = function includes(arr, val) {
+ return arr.some(function (arrVal) {
+ return val === arrVal;
+ });
+};
+
+var _default = includes;
+exports.default = _default;
+module.exports = exports.default;
+module.exports.default = exports.default; \ No newline at end of file
diff --git a/includes/external/addressbook/node_modules/validator/lib/util/merge.js b/includes/external/addressbook/node_modules/validator/lib/util/merge.js
new file mode 100644
index 0000000..a96c739
--- /dev/null
+++ b/includes/external/addressbook/node_modules/validator/lib/util/merge.js
@@ -0,0 +1,22 @@
+"use strict";
+
+Object.defineProperty(exports, "__esModule", {
+ value: true
+});
+exports.default = merge;
+
+function merge() {
+ var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
+ var defaults = arguments.length > 1 ? arguments[1] : undefined;
+
+ for (var key in defaults) {
+ if (typeof obj[key] === 'undefined') {
+ obj[key] = defaults[key];
+ }
+ }
+
+ return obj;
+}
+
+module.exports = exports.default;
+module.exports.default = exports.default; \ No newline at end of file
diff --git a/includes/external/addressbook/node_modules/validator/lib/util/multilineRegex.js b/includes/external/addressbook/node_modules/validator/lib/util/multilineRegex.js
new file mode 100644
index 0000000..6980d14
--- /dev/null
+++ b/includes/external/addressbook/node_modules/validator/lib/util/multilineRegex.js
@@ -0,0 +1,22 @@
+"use strict";
+
+Object.defineProperty(exports, "__esModule", {
+ value: true
+});
+exports.default = multilineRegexp;
+
+/**
+ * Build RegExp object from an array
+ * of multiple/multi-line regexp parts
+ *
+ * @param {string[]} parts
+ * @param {string} flags
+ * @return {object} - RegExp object
+ */
+function multilineRegexp(parts, flags) {
+ var regexpAsStringLiteral = parts.join('');
+ return new RegExp(regexpAsStringLiteral, flags);
+}
+
+module.exports = exports.default;
+module.exports.default = exports.default; \ No newline at end of file
diff --git a/includes/external/addressbook/node_modules/validator/lib/util/toString.js b/includes/external/addressbook/node_modules/validator/lib/util/toString.js
new file mode 100644
index 0000000..6295192
--- /dev/null
+++ b/includes/external/addressbook/node_modules/validator/lib/util/toString.js
@@ -0,0 +1,25 @@
+"use strict";
+
+Object.defineProperty(exports, "__esModule", {
+ value: true
+});
+exports.default = toString;
+
+function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
+
+function toString(input) {
+ if (_typeof(input) === 'object' && input !== null) {
+ if (typeof input.toString === 'function') {
+ input = input.toString();
+ } else {
+ input = '[object Object]';
+ }
+ } else if (input === null || typeof input === 'undefined' || isNaN(input) && !input.length) {
+ input = '';
+ }
+
+ return String(input);
+}
+
+module.exports = exports.default;
+module.exports.default = exports.default; \ No newline at end of file
diff --git a/includes/external/addressbook/node_modules/validator/lib/util/typeOf.js b/includes/external/addressbook/node_modules/validator/lib/util/typeOf.js
new file mode 100644
index 0000000..5bfacdb
--- /dev/null
+++ b/includes/external/addressbook/node_modules/validator/lib/util/typeOf.js
@@ -0,0 +1,20 @@
+"use strict";
+
+Object.defineProperty(exports, "__esModule", {
+ value: true
+});
+exports.default = typeOf;
+
+/**
+ * Better way to handle type checking
+ * null, {}, array and date are objects, which confuses
+ */
+function typeOf(input) {
+ var rawObject = Object.prototype.toString.call(input).toLowerCase();
+ var typeOfRegex = /\[object (.*)]/g;
+ var type = typeOfRegex.exec(rawObject)[1];
+ return type;
+}
+
+module.exports = exports.default;
+module.exports.default = exports.default; \ No newline at end of file