@amanat-qa/utils-frontend 1.0.7 → 1.0.8
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.
- package/dist/API/baseAPI.js +143 -75
- package/dist/DB/baseDB.js +138 -40
- package/dist/data/JSONLoader.js +1 -1
- package/dist/data/dataUtils.js +324 -268
- package/dist/data/filesParser.js +61 -42
- package/dist/data/gitlabCIGenerator.js +21 -11
- package/dist/log/logger.js +78 -49
- package/dist/random/randomizer.js +131 -99
- package/dist/str/strUtils.js +23 -7
- package/dist/time/timeUtils.js +58 -42
- package/package.json +1 -1
package/dist/data/filesParser.js
CHANGED
|
@@ -1,64 +1,83 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
|
|
4
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
5
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
6
|
+
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
7
|
+
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
|
|
8
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
9
|
+
var fs = require('fs');
|
|
10
|
+
var path = require('path');
|
|
5
11
|
require('dotenv').config({
|
|
6
12
|
path: path.join(__dirname, '../../../../../../', '.env.test'),
|
|
7
13
|
override: true
|
|
8
14
|
});
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
var envDirectory = path.join(__dirname, '../../../../../../');
|
|
16
|
+
var loaderFileLocation = path.join(envDirectory, './cypress/main/utils/data/', 'JSONLoader.js');
|
|
17
|
+
var testClientsFileLocation = path.join(envDirectory, './cypress/resources/data/testClients.json');
|
|
18
|
+
var testCarsFileLocation = path.join(envDirectory, './cypress/resources/data/testCars.json');
|
|
19
|
+
var JSONDirectory = path.join(envDirectory, './cypress/resources');
|
|
20
|
+
var suitesDirectory = path.join(envDirectory, './cypress/tests/suites');
|
|
21
|
+
var jsonExtension = '.json';
|
|
22
|
+
var testExtension = '.test';
|
|
23
|
+
var testSuitePattern = 'Suite.js';
|
|
24
|
+
var _getFiles = function getFiles(directory, extension) {
|
|
25
|
+
var allFiles = fs.readdirSync(directory);
|
|
26
|
+
var selectedFiles = allFiles.filter(function (file) {
|
|
27
|
+
return file.endsWith(extension);
|
|
28
|
+
});
|
|
29
|
+
allFiles.forEach(function (file) {
|
|
30
|
+
var fullPath = path.join(directory, file);
|
|
23
31
|
if (fs.statSync(fullPath).isDirectory()) {
|
|
24
|
-
|
|
25
|
-
selectedFiles.push(
|
|
32
|
+
var nestedFiles = _getFiles(fullPath, extension);
|
|
33
|
+
selectedFiles.push.apply(selectedFiles, _toConsumableArray(nestedFiles.map(function (nestedFile) {
|
|
34
|
+
return path.join(file, nestedFile);
|
|
35
|
+
})));
|
|
26
36
|
}
|
|
27
37
|
});
|
|
28
38
|
return selectedFiles;
|
|
29
39
|
};
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
40
|
+
var generateClassInit = function generateClassInit(selectedFiles, directory) {
|
|
41
|
+
return "class JSONLoader {\n".concat(selectedFiles.map(function (file) {
|
|
42
|
+
var variableName = path.parse(file).name;
|
|
43
|
+
return "\tstatic get ".concat(variableName, "() {\n\t\tconst ").concat(variableName, " = require('").concat(path.join(directory, file), "');\n\t\treturn JSON.parse(JSON.stringify(").concat(variableName, "));\n\t}\n\n");
|
|
44
|
+
}).join(''));
|
|
45
|
+
};
|
|
46
|
+
var generateTestSuitesNames = function generateTestSuitesNames(selectedFiles) {
|
|
47
|
+
var suiteNames = selectedFiles.map(function (file) {
|
|
48
|
+
return file.replace(testSuitePattern, '');
|
|
49
|
+
}).map(function (name) {
|
|
50
|
+
return "'".concat(name, "'");
|
|
51
|
+
}).join(', ');
|
|
52
|
+
return "\tstatic get testSuitesNames() {\n\t\treturn [".concat(suiteNames, "];\n\t}\n\n");
|
|
37
53
|
};
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
54
|
+
var generateJSONLoader = function generateJSONLoader(filePath, directory) {
|
|
55
|
+
var jsonFiles = _getFiles(directory, jsonExtension);
|
|
56
|
+
var testSuites = _getFiles(suitesDirectory, testSuitePattern);
|
|
57
|
+
var classInit = generateClassInit(jsonFiles, directory);
|
|
58
|
+
var suitesNames = generateTestSuitesNames(testSuites);
|
|
59
|
+
var classExport = '}\n\nmodule.exports = JSONLoader;';
|
|
44
60
|
fs.writeFileSync(filePath, classInit + suitesNames + classExport);
|
|
45
61
|
};
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
62
|
+
var setConfigData = function setConfigData(directory, extension) {
|
|
63
|
+
var files = _getFiles(directory, extension);
|
|
64
|
+
var configFile = files.filter(function (file) {
|
|
65
|
+
return file.includes('config');
|
|
66
|
+
}).pop();
|
|
49
67
|
if (configFile) {
|
|
50
|
-
|
|
51
|
-
|
|
68
|
+
var filePath = "".concat(directory, "/").concat(configFile);
|
|
69
|
+
var data = JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
|
52
70
|
data.parallel = process.argv.includes('--parallel');
|
|
53
71
|
data.setPolicyWaitingTWB = process.argv.includes('--setPolicyWaitingTWB');
|
|
54
72
|
try {
|
|
55
|
-
|
|
73
|
+
var _process$env$VERIFICA;
|
|
74
|
+
data.verification = Boolean(JSON.parse((_process$env$VERIFICA = process.env.VERIFICATION) !== null && _process$env$VERIFICA !== void 0 ? _process$env$VERIFICA : data.verification));
|
|
56
75
|
} catch (error) {
|
|
57
76
|
// eslint-disable-next-line no-console
|
|
58
77
|
console.log(' [err] incorrect value of "VERIFICATION" .env variable!');
|
|
59
78
|
}
|
|
60
79
|
if (process.env.GATEWAY_URL) {
|
|
61
|
-
|
|
80
|
+
var value = process.env.GATEWAY_URL.match(/\b(?:localhost|dev|staging)\b/g);
|
|
62
81
|
if (value) {
|
|
63
82
|
data.environment = value.pop();
|
|
64
83
|
} else {
|
|
@@ -72,12 +91,12 @@ const setConfigData = (directory, extension) => {
|
|
|
72
91
|
fs.writeFileSync(filePath, JSON.stringify(data, null, 2), 'utf8');
|
|
73
92
|
}
|
|
74
93
|
};
|
|
75
|
-
|
|
76
|
-
|
|
94
|
+
var checkEnvExists = function checkEnvExists(directory, extension) {
|
|
95
|
+
var files = _getFiles(directory, extension);
|
|
77
96
|
if (!files.length) throw new Error('[err] .env.test file not exists in root directory!');
|
|
78
97
|
};
|
|
79
|
-
|
|
80
|
-
|
|
98
|
+
var generateTestDataFile = function generateTestDataFile(filePath) {
|
|
99
|
+
var emptyObj = {};
|
|
81
100
|
if (!fs.existsSync(filePath)) fs.writeFileSync(filePath, JSON.stringify(emptyObj, null, 2), 'utf8');
|
|
82
101
|
};
|
|
83
102
|
checkEnvExists(envDirectory, testExtension);
|
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
+
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
|
|
5
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
6
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
7
|
+
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
8
|
+
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
|
|
9
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
10
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
11
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
12
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
13
|
+
var fs = require('fs');
|
|
14
|
+
var path = require('path');
|
|
15
|
+
var YAML = require('js-yaml');
|
|
16
|
+
var JSONLoader = require('./JSONLoader');
|
|
17
|
+
var testSuites = JSONLoader.testSuitesNames;
|
|
18
|
+
var jobs = testSuites.map(function (suite) {
|
|
19
|
+
return _defineProperty({}, "e2e tests ".concat(suite), {
|
|
10
20
|
image: 'lines14/cypress-java-dind:latest',
|
|
11
21
|
stage: 'test',
|
|
12
22
|
variables: {
|
|
@@ -25,13 +35,13 @@ const jobs = testSuites.map(suite => ({
|
|
|
25
35
|
before_script: [
|
|
26
36
|
// eslint-disable-next-line no-template-curly-in-string
|
|
27
37
|
'echo "${ADP_NUXT_TEST}" | tr -d \'\\r\' > ./.env.test', 'docker login --username $USER --password $PASS registry.gitlab.com', 'service docker start', 'npm ci --prefix ./cypress', 'npm run lint --prefix ./cypress'],
|
|
28
|
-
script: ['npm run start:ci --prefix ./cypress',
|
|
38
|
+
script: ['npm run start:ci --prefix ./cypress', "file=".concat(suite, " npm run test --prefix ./cypress")],
|
|
29
39
|
artifacts: {
|
|
30
40
|
when: 'always',
|
|
31
41
|
expire_in: '1 month',
|
|
32
42
|
paths: ['cypress/artifacts', 'cypress/screenshots', 'cypress/videos', 'cypress/resources/data/configData.json', 'cypress/resources/data/testClients.json', 'cypress/resources/data/testCars.json']
|
|
33
43
|
}
|
|
34
|
-
}
|
|
35
|
-
})
|
|
36
|
-
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
var gitlabCIConfig = Object.assign.apply(Object, [{}].concat(_toConsumableArray(jobs)));
|
|
37
47
|
fs.writeFileSync(path.join(__dirname, '..', '..', '..', '..', '.split-config.yml'), YAML.dump(gitlabCIConfig));
|
package/dist/log/logger.js
CHANGED
|
@@ -1,62 +1,91 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
5
|
+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
6
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
7
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
8
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
3
9
|
function _classPrivateFieldLooseBase(e, t) { if (!{}.hasOwnProperty.call(e, t)) throw new TypeError("attempted to use private field on non-instance"); return e; }
|
|
4
10
|
var id = 0;
|
|
5
11
|
function _classPrivateFieldLooseKey(e) { return "__private_" + id++ + "_" + e; }
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
createWriteStream
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const logList = [];
|
|
12
|
+
var path = require('path');
|
|
13
|
+
var moment = require('moment');
|
|
14
|
+
var _require = require('fs'),
|
|
15
|
+
createWriteStream = _require.createWriteStream;
|
|
16
|
+
var JSONLoader = require('../data/JSONLoader');
|
|
17
|
+
var filePath = path.join(path.resolve(), 'artifacts', 'log.txt');
|
|
18
|
+
var timeList = [];
|
|
19
|
+
var logList = [];
|
|
15
20
|
var _title = /*#__PURE__*/_classPrivateFieldLooseKey("title");
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
var Logger = /*#__PURE__*/function () {
|
|
22
|
+
function Logger() {
|
|
23
|
+
_classCallCheck(this, Logger);
|
|
24
|
+
}
|
|
25
|
+
return _createClass(Logger, null, [{
|
|
26
|
+
key: "log",
|
|
27
|
+
value: function log(step, title) {
|
|
28
|
+
logList.push(" ".concat(step));
|
|
29
|
+
var timeStamp = moment().format().slice(0, 19).replace('T', ' ');
|
|
30
|
+
timeList.push("".concat(timeStamp));
|
|
31
|
+
if (title) _classPrivateFieldLooseBase(this, _title)[_title] = title;
|
|
32
|
+
if (!JSONLoader.configData.parallel) {
|
|
33
|
+
var stream = createWriteStream(filePath, {
|
|
34
|
+
flags: 'a',
|
|
35
|
+
autoClose: true
|
|
36
|
+
});
|
|
37
|
+
if (!title) stream.write("".concat(timeStamp, " ").concat(step, "\n"));
|
|
38
|
+
this.hideLogBodies(step);
|
|
39
|
+
}
|
|
40
|
+
return timeStamp;
|
|
41
|
+
}
|
|
42
|
+
}, {
|
|
43
|
+
key: "hideLogBodies",
|
|
44
|
+
value: function hideLogBodies(step) {
|
|
45
|
+
if (JSONLoader.configData.hiddenLogBodies && step.includes('[req]')) {
|
|
46
|
+
var words = step.split(' ');
|
|
47
|
+
var firstPart = words.slice(0, 3).join(' ');
|
|
48
|
+
var secondPart = words.slice(words.length - 2).join(' ');
|
|
49
|
+
console.log(" ".concat(firstPart, " ").concat(secondPart)); // eslint-disable-line no-console
|
|
50
|
+
} else {
|
|
51
|
+
console.log(" ".concat(step)); // eslint-disable-line no-console
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}, {
|
|
55
|
+
key: "logParallel",
|
|
56
|
+
value: function logParallel() {
|
|
57
|
+
var _this = this;
|
|
58
|
+
logList.forEach(function (step) {
|
|
59
|
+
return _this.hideLogBodies(step.trim());
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}, {
|
|
63
|
+
key: "logToFileParallel",
|
|
64
|
+
value: function logToFileParallel() {
|
|
65
|
+
var _this2 = this;
|
|
66
|
+
var zip = function zip(a, b) {
|
|
67
|
+
return a.map(function (k, i) {
|
|
68
|
+
return [k, b[i]];
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
var summaryList = zip(timeList, logList);
|
|
72
|
+
summaryList.shift();
|
|
73
|
+
var fileName = filePath.split('/').map(function (part, index, array) {
|
|
74
|
+
return index === array.length - 1 ? "".concat(_classPrivateFieldLooseBase(_this2, _title)[_title], ".").concat(part) : part;
|
|
75
|
+
}).join('/');
|
|
76
|
+
var stream = createWriteStream(fileName, {
|
|
24
77
|
flags: 'a',
|
|
25
78
|
autoClose: true
|
|
26
79
|
});
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (JSONLoader.configData.hiddenLogBodies && step.includes('[req]')) {
|
|
34
|
-
const words = step.split(' ');
|
|
35
|
-
const firstPart = words.slice(0, 3).join(' ');
|
|
36
|
-
const secondPart = words.slice(words.length - 2).join(' ');
|
|
37
|
-
console.log(` ${firstPart} ${secondPart}`); // eslint-disable-line no-console
|
|
38
|
-
} else {
|
|
39
|
-
console.log(` ${step}`); // eslint-disable-line no-console
|
|
80
|
+
summaryList.forEach(function (logString) {
|
|
81
|
+
return logString.forEach(function (logSubString, index) {
|
|
82
|
+
/* eslint no-unused-expressions: ["error", { "allowTernary": true }] */
|
|
83
|
+
index % 2 !== 0 ? stream.write("".concat(logSubString, "\n")) : stream.write("".concat(logSubString));
|
|
84
|
+
});
|
|
85
|
+
});
|
|
40
86
|
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
logList.forEach(step => this.hideLogBodies(step.trim()));
|
|
44
|
-
}
|
|
45
|
-
static logToFileParallel() {
|
|
46
|
-
const zip = (a, b) => a.map((k, i) => [k, b[i]]);
|
|
47
|
-
const summaryList = zip(timeList, logList);
|
|
48
|
-
summaryList.shift();
|
|
49
|
-
const fileName = filePath.split('/').map((part, index, array) => index === array.length - 1 ? `${_classPrivateFieldLooseBase(this, _title)[_title]}.${part}` : part).join('/');
|
|
50
|
-
const stream = createWriteStream(fileName, {
|
|
51
|
-
flags: 'a',
|
|
52
|
-
autoClose: true
|
|
53
|
-
});
|
|
54
|
-
summaryList.forEach(logString => logString.forEach((logSubString, index) => {
|
|
55
|
-
/* eslint no-unused-expressions: ["error", { "allowTernary": true }] */
|
|
56
|
-
index % 2 !== 0 ? stream.write(`${logSubString}\n`) : stream.write(`${logSubString}`);
|
|
57
|
-
}));
|
|
58
|
-
}
|
|
59
|
-
}
|
|
87
|
+
}]);
|
|
88
|
+
}();
|
|
60
89
|
Object.defineProperty(Logger, _title, {
|
|
61
90
|
writable: true,
|
|
62
91
|
value: void 0
|
|
@@ -1,110 +1,142 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
} while (finishDateUnix - startDateUnix < 86400 * 2);
|
|
15
|
-
const startDateObject = moment.unix(startDateUnix).startOf('day');
|
|
16
|
-
const finishDateObject = moment.unix(finishDateUnix).startOf('day');
|
|
17
|
-
const startDate = startDateObject.format(JSONLoader.testData.datesFormatDMY);
|
|
18
|
-
const finishDate = finishDateObject.format(JSONLoader.testData.datesFormatDMY);
|
|
19
|
-
const daysDifferenceIncluded = finishDateObject.diff(startDateObject, 'days') + 1;
|
|
20
|
-
const getAbsoluteMonth = date => {
|
|
21
|
-
const months = Number(moment(date, JSONLoader.testData.datesFormatDMY).format('MM'));
|
|
22
|
-
const years = Number(moment(date, JSONLoader.testData.datesFormatDMY).format('YYYY'));
|
|
23
|
-
return months + years * 12;
|
|
24
|
-
};
|
|
25
|
-
const currentMonth = getAbsoluteMonth(moment.unix(unixOne).format(JSONLoader.testData.datesFormatDMY));
|
|
26
|
-
const startMonth = getAbsoluteMonth(startDate);
|
|
27
|
-
const finishMonth = getAbsoluteMonth(finishDate);
|
|
28
|
-
let startMonthDifference = startMonth - currentMonth;
|
|
29
|
-
let finishMonthDifference = finishMonth - currentMonth;
|
|
30
|
-
if (nextDayObject.date() === 1) startMonthDifference += 1;
|
|
31
|
-
if (nextDayObject.date() === 1) finishMonthDifference += 1;
|
|
32
|
-
return {
|
|
33
|
-
startDate,
|
|
34
|
-
finishDate,
|
|
35
|
-
startMonthDifference,
|
|
36
|
-
finishMonthDifference,
|
|
37
|
-
daysDifferenceIncluded
|
|
38
|
-
};
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
5
|
+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
6
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
7
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
8
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
9
|
+
var moment = require('moment');
|
|
10
|
+
var JSONLoader = require('../data/JSONLoader');
|
|
11
|
+
var Randomizer = /*#__PURE__*/function () {
|
|
12
|
+
function Randomizer() {
|
|
13
|
+
_classCallCheck(this, Randomizer);
|
|
39
14
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
15
|
+
return _createClass(Randomizer, null, [{
|
|
16
|
+
key: "getRandomDatesIntervalFromTomorrow",
|
|
17
|
+
value: function getRandomDatesIntervalFromTomorrow(count, unitOfTime) {
|
|
18
|
+
var nextDayObject = moment().add(1, 'days').startOf('day');
|
|
19
|
+
var unixOne = nextDayObject.unix();
|
|
20
|
+
var unixTwo = moment(moment().add(1, 'days').startOf('day')).add(count, unitOfTime).unix();
|
|
21
|
+
var startDateUnix = moment.unix(this.getRandomFloat(unixOne, unixTwo)).unix();
|
|
22
|
+
var finishDateUnix;
|
|
23
|
+
do {
|
|
24
|
+
finishDateUnix = moment.unix(this.getRandomFloat(startDateUnix, unixTwo)).unix();
|
|
25
|
+
} while (finishDateUnix - startDateUnix < 86400 * 2);
|
|
26
|
+
var startDateObject = moment.unix(startDateUnix).startOf('day');
|
|
27
|
+
var finishDateObject = moment.unix(finishDateUnix).startOf('day');
|
|
28
|
+
var startDate = startDateObject.format(JSONLoader.testData.datesFormatDMY);
|
|
29
|
+
var finishDate = finishDateObject.format(JSONLoader.testData.datesFormatDMY);
|
|
30
|
+
var daysDifferenceIncluded = finishDateObject.diff(startDateObject, 'days') + 1;
|
|
31
|
+
var getAbsoluteMonth = function getAbsoluteMonth(date) {
|
|
32
|
+
var months = Number(moment(date, JSONLoader.testData.datesFormatDMY).format('MM'));
|
|
33
|
+
var years = Number(moment(date, JSONLoader.testData.datesFormatDMY).format('YYYY'));
|
|
34
|
+
return months + years * 12;
|
|
35
|
+
};
|
|
36
|
+
var currentMonth = getAbsoluteMonth(moment.unix(unixOne).format(JSONLoader.testData.datesFormatDMY));
|
|
37
|
+
var startMonth = getAbsoluteMonth(startDate);
|
|
38
|
+
var finishMonth = getAbsoluteMonth(finishDate);
|
|
39
|
+
var startMonthDifference = startMonth - currentMonth;
|
|
40
|
+
var finishMonthDifference = finishMonth - currentMonth;
|
|
41
|
+
if (nextDayObject.date() === 1) startMonthDifference += 1;
|
|
42
|
+
if (nextDayObject.date() === 1) finishMonthDifference += 1;
|
|
43
|
+
return {
|
|
44
|
+
startDate: startDate,
|
|
45
|
+
finishDate: finishDate,
|
|
46
|
+
startMonthDifference: startMonthDifference,
|
|
47
|
+
finishMonthDifference: finishMonthDifference,
|
|
48
|
+
daysDifferenceIncluded: daysDifferenceIncluded
|
|
49
|
+
};
|
|
51
50
|
}
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
}, {
|
|
52
|
+
key: "getRandomString",
|
|
53
|
+
value: function getRandomString() {
|
|
54
|
+
var hasLowerCase = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
55
|
+
var hasUpperCase = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
56
|
+
var hasNumber = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
57
|
+
var hasCyrillic = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
58
|
+
var chosenLetter = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
59
|
+
var minLength = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 1;
|
|
60
|
+
var maxLength = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : 10;
|
|
61
|
+
var upperCaseLetters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
62
|
+
var lowerCaseLetters = 'abcdefghijklmnopqrstuvwxyz';
|
|
63
|
+
var numbers = '0123456789';
|
|
64
|
+
var cyrillicLetters = 'абвгдеёжзийклмнопрстуфхцчшщъыьэюя';
|
|
65
|
+
var length = this.getRandomInteger(maxLength, minLength);
|
|
66
|
+
var randomString = '';
|
|
67
|
+
if (chosenLetter) randomString += chosenLetter;
|
|
68
|
+
var requiredCharacters = '';
|
|
69
|
+
if (hasLowerCase) {
|
|
70
|
+
requiredCharacters += lowerCaseLetters.charAt(Math.floor(Math.random() * lowerCaseLetters.length));
|
|
71
|
+
}
|
|
72
|
+
if (hasUpperCase) {
|
|
73
|
+
requiredCharacters += upperCaseLetters.charAt(Math.floor(Math.random() * upperCaseLetters.length));
|
|
74
|
+
}
|
|
75
|
+
if (hasNumber) {
|
|
76
|
+
requiredCharacters += numbers.charAt(Math.floor(Math.random() * numbers.length));
|
|
77
|
+
}
|
|
78
|
+
if (hasCyrillic) {
|
|
79
|
+
requiredCharacters += cyrillicLetters.charAt(Math.floor(Math.random() * cyrillicLetters.length));
|
|
80
|
+
}
|
|
81
|
+
randomString += requiredCharacters;
|
|
82
|
+
var characters = (hasLowerCase ? lowerCaseLetters : '') + (hasUpperCase ? upperCaseLetters : '') + (hasNumber ? numbers : '') + (hasCyrillic ? cyrillicLetters : '');
|
|
83
|
+
var charactersLength = characters.length;
|
|
84
|
+
var randomLength = length - randomString.length;
|
|
85
|
+
for (var i = 0; i < randomLength; i += 1) {
|
|
86
|
+
randomString += characters.charAt(Math.floor(Math.random() * charactersLength));
|
|
87
|
+
}
|
|
88
|
+
return this.stringShuffler(randomString);
|
|
54
89
|
}
|
|
55
|
-
|
|
56
|
-
|
|
90
|
+
}, {
|
|
91
|
+
key: "stringShuffler",
|
|
92
|
+
value: function stringShuffler(inputString) {
|
|
93
|
+
var array = inputString.split('');
|
|
94
|
+
var currentIndex = array.length;
|
|
95
|
+
var temporaryValue;
|
|
96
|
+
var randomIndex;
|
|
97
|
+
while (currentIndex !== 0) {
|
|
98
|
+
randomIndex = Math.floor(Math.random() * currentIndex);
|
|
99
|
+
currentIndex -= 1;
|
|
100
|
+
temporaryValue = array[currentIndex];
|
|
101
|
+
array[currentIndex] = array[randomIndex];
|
|
102
|
+
array[randomIndex] = temporaryValue;
|
|
103
|
+
}
|
|
104
|
+
return array.join('');
|
|
57
105
|
}
|
|
58
|
-
|
|
59
|
-
|
|
106
|
+
}, {
|
|
107
|
+
key: "getRandomInteger",
|
|
108
|
+
value: function getRandomInteger() {
|
|
109
|
+
var max = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 9;
|
|
110
|
+
var min = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
111
|
+
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
60
112
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
for (let i = 0; i < randomLength; i += 1) {
|
|
66
|
-
randomString += characters.charAt(Math.floor(Math.random() * charactersLength));
|
|
113
|
+
}, {
|
|
114
|
+
key: "getRandomFloat",
|
|
115
|
+
value: function getRandomFloat(min, max) {
|
|
116
|
+
return Math.random() * (max - min) + min;
|
|
67
117
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
static getRandomFloat(min, max) {
|
|
88
|
-
return Math.random() * (max - min) + min;
|
|
89
|
-
}
|
|
90
|
-
static getRandomElementByText(baseElements, exceptionsList = []) {
|
|
91
|
-
const exceptions = exceptionsList ?? [];
|
|
92
|
-
const baseElementsList = baseElements.slice(0, baseElements.length);
|
|
93
|
-
let element;
|
|
94
|
-
if (exceptions.length > 0) {
|
|
95
|
-
while (true) {
|
|
96
|
-
// eslint-disable-line no-constant-condition
|
|
97
|
-
element = baseElementsList[Math.floor(Math.random() * baseElementsList.length)];
|
|
98
|
-
if (!exceptions.includes(element) && element !== '') break;
|
|
99
|
-
}
|
|
100
|
-
} else {
|
|
101
|
-
while (true) {
|
|
102
|
-
// eslint-disable-line no-constant-condition
|
|
103
|
-
element = baseElementsList[Math.floor(Math.random() * baseElementsList.length)];
|
|
104
|
-
if (element !== '') break;
|
|
118
|
+
}, {
|
|
119
|
+
key: "getRandomElementByText",
|
|
120
|
+
value: function getRandomElementByText(baseElements) {
|
|
121
|
+
var exceptionsList = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
122
|
+
var exceptions = exceptionsList !== null && exceptionsList !== void 0 ? exceptionsList : [];
|
|
123
|
+
var baseElementsList = baseElements.slice(0, baseElements.length);
|
|
124
|
+
var element;
|
|
125
|
+
if (exceptions.length > 0) {
|
|
126
|
+
while (true) {
|
|
127
|
+
// eslint-disable-line no-constant-condition
|
|
128
|
+
element = baseElementsList[Math.floor(Math.random() * baseElementsList.length)];
|
|
129
|
+
if (!exceptions.includes(element) && element !== '') break;
|
|
130
|
+
}
|
|
131
|
+
} else {
|
|
132
|
+
while (true) {
|
|
133
|
+
// eslint-disable-line no-constant-condition
|
|
134
|
+
element = baseElementsList[Math.floor(Math.random() * baseElementsList.length)];
|
|
135
|
+
if (element !== '') break;
|
|
136
|
+
}
|
|
105
137
|
}
|
|
138
|
+
return element;
|
|
106
139
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
140
|
+
}]);
|
|
141
|
+
}();
|
|
110
142
|
module.exports = Randomizer;
|
package/dist/str/strUtils.js
CHANGED
|
@@ -1,11 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
5
|
+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
6
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
7
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
8
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
9
|
+
var StrUtils = /*#__PURE__*/function () {
|
|
10
|
+
function StrUtils() {
|
|
11
|
+
_classCallCheck(this, StrUtils);
|
|
6
12
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
13
|
+
return _createClass(StrUtils, null, [{
|
|
14
|
+
key: "toTitleCase",
|
|
15
|
+
value: function toTitleCase(str) {
|
|
16
|
+
return str.replace(/\w\S*/g, function (txt) {
|
|
17
|
+
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}, {
|
|
21
|
+
key: "removeAllNonNumbersFromString",
|
|
22
|
+
value: function removeAllNonNumbersFromString(str) {
|
|
23
|
+
return str.replace(/\D/g, '');
|
|
24
|
+
}
|
|
25
|
+
}]);
|
|
26
|
+
}();
|
|
11
27
|
module.exports = StrUtils;
|