randex 1.2.0 → 1.4.0
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/.vscode/settings.json +1 -1
- package/eslint.config.js +29 -0
- package/lib/basic/set.js +48 -51
- package/lib/basic/type.js +27 -34
- package/lib/custom/bool.js +1 -2
- package/lib/custom/email.js +8 -9
- package/lib/custom/filenameX.js +7 -8
- package/lib/custom/fullnameX.js +7 -8
- package/lib/custom/index.d.ts +9 -8
- package/lib/custom/index.js +63 -49
- package/lib/custom/number.js +11 -12
- package/lib/custom/phrase.js +11 -12
- package/lib/custom/random.js +23 -29
- package/lib/custom/sentence.js +13 -14
- package/lib/custom/singleName.js +7 -8
- package/lib/custom/username.js +6 -7
- package/lib/custom/word.js +9 -10
- package/lib/index.js +1 -2
- package/lib/test/array.test.js +10 -13
- package/lib/test/arrayItem.test.js +17 -0
- package/lib/test/email.test.js +35 -35
- package/lib/test/filename.test.js +38 -38
- package/lib/test/fullname.test.js +7 -7
- package/lib/test/markdown.test.js +14 -14
- package/lib/test/name.test.js +13 -13
- package/lib/test/number.many.test.js +21 -24
- package/lib/test/number.test.js +26 -27
- package/lib/test/params.test.js +51 -51
- package/lib/test/phrase.test.js +22 -22
- package/lib/test/random.test.js +36 -38
- package/lib/test/sentence.test.js +22 -22
- package/lib/test/{set-util.test.js → setUtil.test.js} +7 -7
- package/lib/test/shuffle.test.d.ts +1 -0
- package/lib/test/shuffle.test.js +14 -0
- package/lib/test/spreader.test.js +13 -12
- package/lib/test/testUtil.js +121 -0
- package/lib/test/type.test.js +11 -14
- package/lib/test/username.test.js +11 -11
- package/lib/test/word.test.js +16 -16
- package/lib/utils/spreader.d.ts +1 -0
- package/lib/utils/spreader.js +19 -25
- package/package.json +4 -4
- package/.eslintignore +0 -3
- package/.eslintrc.js +0 -3
- package/lib/test/array-item.test.js +0 -18
- package/lib/test/test-util.js +0 -134
- /package/lib/test/{array-item.test.d.ts → arrayItem.test.d.ts} +0 -0
- /package/lib/test/{set-util.test.d.ts → setUtil.test.d.ts} +0 -0
- /package/lib/test/{test-util.d.ts → testUtil.d.ts} +0 -0
package/.vscode/settings.json
CHANGED
package/eslint.config.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const { defineConfig, globalIgnores } = require("eslint/config");
|
|
2
|
+
const configs = require("eslint-config-varp");
|
|
3
|
+
|
|
4
|
+
module.exports = defineConfig([
|
|
5
|
+
{
|
|
6
|
+
extends: [configs.eslint.base, configs.eslint.typescript],
|
|
7
|
+
rules: {
|
|
8
|
+
"@typescript-eslint/no-explicit-any": "off",
|
|
9
|
+
"prefer-destructuring": "off",
|
|
10
|
+
"sonarjs/cognitive-complexity": ["error", 30],
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
// {
|
|
14
|
+
// files: ["src/**/*"],
|
|
15
|
+
// rules: {
|
|
16
|
+
// "check-file/filename-naming-convention": [
|
|
17
|
+
// "error",
|
|
18
|
+
// {
|
|
19
|
+
// "**/*.{ts,tsx}": "CAMEL_CASE",
|
|
20
|
+
// },
|
|
21
|
+
// {
|
|
22
|
+
// ignoreMiddleExtensions: true,
|
|
23
|
+
// },
|
|
24
|
+
// ],
|
|
25
|
+
// "check-file/folder-naming-convention": ["error", { "src/**/": "CAMEL_CASE" }],
|
|
26
|
+
// },
|
|
27
|
+
// },
|
|
28
|
+
globalIgnores(["lib", "node_modules"]),
|
|
29
|
+
]);
|
package/lib/basic/set.js
CHANGED
|
@@ -1,23 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RandexSetUtil = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
4
|
+
const type_1 = require("./type");
|
|
5
|
+
const hex = "0123456789ABCDEFabcdef";
|
|
6
|
+
const symbol = '[-!$%^&*()_+|~=`{}[]:";<>?,./]' + "'";
|
|
7
|
+
const number = "0123456789";
|
|
8
|
+
const binary = "01";
|
|
9
|
+
const englishLower = "abcdefghijklmnopqrstuvwxyz";
|
|
10
|
+
const englishUpper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
11
|
+
const frenchLower = "abcdefghijklmnopqrstuvwxyzàâæçèéêëîïôœùûü";
|
|
12
|
+
const frenchUpper = "ABCDEFGHIJKLMNOPQRSTUVWXYZÀÂÆÇÈÉÊËÎÏÔŒÙÛÜ";
|
|
13
|
+
const spanishLower = "abcdefghijklmnopqrstuvwxyzñ";
|
|
14
|
+
const spanishUpper = "ABCDEFGHIJKLMNOPQRSTUVWXYZÑ";
|
|
15
|
+
const russianLower = "абвгдеёжзийклмнопрстуфхцчшщъыьэюя";
|
|
16
|
+
const russianUpper = "АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ";
|
|
17
|
+
class RandexSetUtil {
|
|
18
|
+
static defaultFileNameLength = [3, 10];
|
|
19
|
+
static defaultExtensionLength = [2, 5];
|
|
20
|
+
static fileNameExtraChars = ""; //"-_.";
|
|
21
|
+
static defaultEmailPrefixLength = [6, 10];
|
|
22
|
+
static defaultHightDomainEmailLength = [1, 6];
|
|
23
|
+
static defaultLowDomainEmailLength = [2, 4];
|
|
24
|
+
static toSingleRange(itemSet) {
|
|
21
25
|
if (Array.isArray(itemSet)) {
|
|
22
26
|
return RandexSetUtil.toAlphabetRange(itemSet);
|
|
23
27
|
}
|
|
@@ -36,8 +40,8 @@ var RandexSetUtil = /** @class */ (function () {
|
|
|
36
40
|
default:
|
|
37
41
|
return "";
|
|
38
42
|
}
|
|
39
|
-
}
|
|
40
|
-
|
|
43
|
+
}
|
|
44
|
+
static toAlphabetCase(cas, lowerWord, upperWord) {
|
|
41
45
|
switch (cas) {
|
|
42
46
|
case "lower":
|
|
43
47
|
case "l":
|
|
@@ -48,9 +52,9 @@ var RandexSetUtil = /** @class */ (function () {
|
|
|
48
52
|
default:
|
|
49
53
|
return lowerWord + upperWord;
|
|
50
54
|
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
55
|
+
}
|
|
56
|
+
static toAlphabetRange(set) {
|
|
57
|
+
const [alphabet, aCase] = set;
|
|
54
58
|
switch (alphabet) {
|
|
55
59
|
case "english":
|
|
56
60
|
return RandexSetUtil.toAlphabetCase(aCase, englishLower, englishUpper);
|
|
@@ -63,9 +67,9 @@ var RandexSetUtil = /** @class */ (function () {
|
|
|
63
67
|
case "russian":
|
|
64
68
|
return RandexSetUtil.toAlphabetCase(aCase, russianLower, russianUpper);
|
|
65
69
|
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
70
|
+
}
|
|
71
|
+
static toRange(set) {
|
|
72
|
+
let result = "";
|
|
69
73
|
if (type_1.RandexTypeParser.isSetSingle(set)) {
|
|
70
74
|
result += RandexSetUtil.toSingleRange(set);
|
|
71
75
|
}
|
|
@@ -73,16 +77,16 @@ var RandexSetUtil = /** @class */ (function () {
|
|
|
73
77
|
result += set.map(RandexSetUtil.toSingleRange).join("");
|
|
74
78
|
}
|
|
75
79
|
return result;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
80
|
+
}
|
|
81
|
+
static getLength(reservedChars, length, defaultLength) {
|
|
82
|
+
let result = defaultLength;
|
|
79
83
|
if (typeof length === "number" && length > reservedChars) {
|
|
80
84
|
result = length - reservedChars;
|
|
81
85
|
}
|
|
82
86
|
else if (Array.isArray(length)) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
87
|
+
const [min, max] = length;
|
|
88
|
+
const dMin = min - reservedChars;
|
|
89
|
+
const dMax = max - reservedChars;
|
|
86
90
|
if (dMin >= 0 && dMax >= 0) {
|
|
87
91
|
if (dMin < dMax) {
|
|
88
92
|
return [dMin, dMax];
|
|
@@ -93,29 +97,22 @@ var RandexSetUtil = /** @class */ (function () {
|
|
|
93
97
|
}
|
|
94
98
|
}
|
|
95
99
|
return result;
|
|
96
|
-
}
|
|
97
|
-
|
|
100
|
+
}
|
|
101
|
+
static randomSingleNumber(length) {
|
|
98
102
|
return Math.floor(Math.random() * length);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
+
}
|
|
104
|
+
static randomRangeNumber(min, max) {
|
|
105
|
+
const minN = Math.min(min, max);
|
|
106
|
+
const maxN = Math.max(min, max);
|
|
103
107
|
return RandexSetUtil.randomSingleNumber(maxN - minN + 1) + minN;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
for (
|
|
108
|
+
}
|
|
109
|
+
static many(count, callback) {
|
|
110
|
+
const result = [];
|
|
111
|
+
const length = Array.isArray(count) ? RandexSetUtil.randomRangeNumber(count[0], count[1]) : count;
|
|
112
|
+
for (let i = 0; i < length; i++) {
|
|
109
113
|
result.push(callback());
|
|
110
114
|
}
|
|
111
115
|
return result;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
RandexSetUtil.defaultExtensionLength = [2, 5];
|
|
115
|
-
RandexSetUtil.fileNameExtraChars = ""; //"-_.";
|
|
116
|
-
RandexSetUtil.defaultEmailPrefixLength = [6, 10];
|
|
117
|
-
RandexSetUtil.defaultHightDomainEmailLength = [1, 6];
|
|
118
|
-
RandexSetUtil.defaultLowDomainEmailLength = [2, 4];
|
|
119
|
-
return RandexSetUtil;
|
|
120
|
-
}());
|
|
116
|
+
}
|
|
117
|
+
}
|
|
121
118
|
exports.RandexSetUtil = RandexSetUtil;
|
package/lib/basic/type.js
CHANGED
|
@@ -1,33 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RandexTypeParser = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
RandexTypeParser.inRange = function (value, range) {
|
|
8
|
-
var min = range[0], max = range[1];
|
|
4
|
+
class RandexTypeParser {
|
|
5
|
+
static inRange(value, range) {
|
|
6
|
+
const [min, max] = range;
|
|
9
7
|
return value >= min && value <= max;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
return typeof value === "string" && !!expects.find(function (x) { return x === value; });
|
|
17
|
-
};
|
|
18
|
-
RandexTypeParser.inCase = function (value) {
|
|
8
|
+
}
|
|
9
|
+
static inLiteral(value, ...expects) {
|
|
10
|
+
return typeof value === "string" && !!expects.find(x => x === value);
|
|
11
|
+
}
|
|
12
|
+
static inCase(value) {
|
|
19
13
|
return RandexTypeParser.inLiteral(value, "default", "lower", "upper", "l", "u");
|
|
20
|
-
}
|
|
21
|
-
|
|
14
|
+
}
|
|
15
|
+
static inAlphabet(value) {
|
|
22
16
|
return (typeof value === "string" &&
|
|
23
17
|
RandexTypeParser.inLiteral(value, "english", "french", "spanish", // "german",
|
|
24
18
|
"russian"));
|
|
25
|
-
}
|
|
26
|
-
|
|
19
|
+
}
|
|
20
|
+
static inSet(value) {
|
|
27
21
|
return RandexTypeParser.inAlphabet(value) || RandexTypeParser.inLiteral(value, "hex", "symbol", "number", "binary");
|
|
28
|
-
}
|
|
22
|
+
}
|
|
29
23
|
// RandomLength
|
|
30
|
-
|
|
24
|
+
static isLength(value) {
|
|
31
25
|
if (typeof value === "number") {
|
|
32
26
|
return true;
|
|
33
27
|
}
|
|
@@ -35,14 +29,14 @@ var RandexTypeParser = /** @class */ (function () {
|
|
|
35
29
|
return typeof value[0] === "number" && typeof value[1] === "number";
|
|
36
30
|
}
|
|
37
31
|
return false;
|
|
38
|
-
}
|
|
32
|
+
}
|
|
39
33
|
// RandomItemSet
|
|
40
|
-
|
|
34
|
+
static isSetSingle(value) {
|
|
41
35
|
if (typeof value === "string") {
|
|
42
36
|
return RandexTypeParser.inSet(value);
|
|
43
37
|
}
|
|
44
38
|
else if (Array.isArray(value) && value.length === 2) {
|
|
45
|
-
|
|
39
|
+
const [alphabet, aCase] = value;
|
|
46
40
|
if (typeof alphabet === "string" && typeof aCase === "string") {
|
|
47
41
|
if (RandexTypeParser.inAlphabet(alphabet) && RandexTypeParser.inCase(aCase)) {
|
|
48
42
|
return true;
|
|
@@ -50,30 +44,29 @@ var RandexTypeParser = /** @class */ (function () {
|
|
|
50
44
|
}
|
|
51
45
|
}
|
|
52
46
|
return false;
|
|
53
|
-
}
|
|
54
|
-
|
|
47
|
+
}
|
|
48
|
+
static isSet(value) {
|
|
55
49
|
if (RandexTypeParser.isSetSingle(value)) {
|
|
56
50
|
return true;
|
|
57
51
|
}
|
|
58
52
|
else if (Array.isArray(value)) {
|
|
59
|
-
|
|
53
|
+
const sets = value.filter(x => RandexTypeParser.isSetSingle(x));
|
|
60
54
|
return sets.length === value.length;
|
|
61
55
|
}
|
|
62
56
|
return false;
|
|
63
|
-
}
|
|
64
|
-
|
|
57
|
+
}
|
|
58
|
+
static isPartArray(value) {
|
|
65
59
|
if (Array.isArray(value) && RandexTypeParser.inRange(value.length, [2, 3])) {
|
|
66
60
|
if (value.length === 2) {
|
|
67
|
-
|
|
61
|
+
const [set, rangeOrLength] = value;
|
|
68
62
|
return RandexTypeParser.isSet(set) && (RandexTypeParser.isLength(rangeOrLength) || typeof rangeOrLength === "string");
|
|
69
63
|
}
|
|
70
64
|
else if (value.length === 3) {
|
|
71
|
-
|
|
72
|
-
return RandexTypeParser.isSet(set) && typeof range === "string" && RandexTypeParser.isLength(
|
|
65
|
+
const [set, range, length] = value;
|
|
66
|
+
return RandexTypeParser.isSet(set) && typeof range === "string" && RandexTypeParser.isLength(length);
|
|
73
67
|
}
|
|
74
68
|
}
|
|
75
69
|
return false;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
}());
|
|
70
|
+
}
|
|
71
|
+
}
|
|
79
72
|
exports.RandexTypeParser = RandexTypeParser;
|
package/lib/custom/bool.js
CHANGED
package/lib/custom/email.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.randexEmail =
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
exports.randexEmail = randexEmail;
|
|
4
|
+
const set_1 = require("../basic/set");
|
|
5
|
+
const type_1 = require("../basic/type");
|
|
6
|
+
const random_1 = require("./random");
|
|
7
7
|
function randexEmail(p1, p2, p3) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
let prefixLength = set_1.RandexSetUtil.defaultEmailPrefixLength;
|
|
9
|
+
let hightDomainLength = set_1.RandexSetUtil.defaultHightDomainEmailLength;
|
|
10
|
+
let lowDomainLength = set_1.RandexSetUtil.defaultLowDomainEmailLength;
|
|
11
|
+
let domain = "";
|
|
12
12
|
if (type_1.RandexTypeParser.isLength(p1)) {
|
|
13
13
|
prefixLength = p1;
|
|
14
14
|
if (type_1.RandexTypeParser.isLength(p2)) {
|
|
@@ -40,4 +40,3 @@ function randexEmail(p1, p2, p3) {
|
|
|
40
40
|
}
|
|
41
41
|
return (0, random_1.randexRandom)([[["english", "l"], "number"], prefixLength]) + "@" + domain;
|
|
42
42
|
}
|
|
43
|
-
exports.randexEmail = randexEmail;
|
package/lib/custom/filenameX.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.randexFileName =
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
exports.randexFileName = randexFileName;
|
|
4
|
+
const set_1 = require("../basic/set");
|
|
5
|
+
const type_1 = require("../basic/type");
|
|
6
|
+
const random_1 = require("./random");
|
|
7
7
|
function randexFileName(p1, p2) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
let fileNameLength = set_1.RandexSetUtil.defaultFileNameLength;
|
|
9
|
+
let extensionLength = set_1.RandexSetUtil.defaultExtensionLength;
|
|
10
|
+
let extension = "";
|
|
11
11
|
if (type_1.RandexTypeParser.isLength(p1)) {
|
|
12
12
|
fileNameLength = p1;
|
|
13
13
|
if (type_1.RandexTypeParser.isLength(p2)) {
|
|
@@ -40,4 +40,3 @@ function randexFileName(p1, p2) {
|
|
|
40
40
|
"." +
|
|
41
41
|
(extension ? extension.replace(/^\./, "") : (0, random_1.randexRandom)([["english", "l"], extensionLength])));
|
|
42
42
|
}
|
|
43
|
-
exports.randexFileName = randexFileName;
|
package/lib/custom/fullnameX.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.randexFullName =
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
exports.randexFullName = randexFullName;
|
|
4
|
+
const type_1 = require("../basic/type");
|
|
5
|
+
const singleName_1 = require("./singleName");
|
|
6
6
|
function randexFullName(p1, p2, p3) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
let firstLength = 0;
|
|
8
|
+
let secondLength = 0;
|
|
9
|
+
let alphabet = "english";
|
|
10
10
|
if (type_1.RandexTypeParser.isLength(p1)) {
|
|
11
11
|
firstLength = secondLength = p1;
|
|
12
12
|
}
|
|
@@ -30,6 +30,5 @@ function randexFullName(p1, p2, p3) {
|
|
|
30
30
|
secondLength = p1.secondLength;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
return (0, singleName_1.randexSingleName)({ length: firstLength, alphabet
|
|
33
|
+
return (0, singleName_1.randexSingleName)({ length: firstLength, alphabet }) + " " + (0, singleName_1.randexSingleName)({ length: secondLength, alphabet });
|
|
34
34
|
}
|
|
35
|
-
exports.randexFullName = randexFullName;
|
package/lib/custom/index.d.ts
CHANGED
|
@@ -25,28 +25,29 @@ export declare class Randex {
|
|
|
25
25
|
static word: typeof randexWord;
|
|
26
26
|
static sentence: typeof randexSentence;
|
|
27
27
|
static phrase: typeof randexPhrase;
|
|
28
|
+
static shuffle<T>(array: T[]): T[];
|
|
28
29
|
static many(count: RandexNumberRange): {
|
|
29
30
|
word: {
|
|
30
|
-
(options?: import("../interfaces").RandexWordOptions
|
|
31
|
+
(options?: import("../interfaces").RandexWordOptions): string[];
|
|
31
32
|
(length: RandexNumberRange): string[];
|
|
32
|
-
(alphabet?: import("../interfaces").RandexAlphabet
|
|
33
|
+
(alphabet?: import("../interfaces").RandexAlphabet): string[];
|
|
33
34
|
(alphabet: import("../interfaces").RandexAlphabet, length: RandexNumberRange): string[];
|
|
34
35
|
};
|
|
35
36
|
phrase: {
|
|
36
|
-
(options?: import("../interfaces").RandexPhraseOptions
|
|
37
|
+
(options?: import("../interfaces").RandexPhraseOptions): string[];
|
|
37
38
|
(words: RandexNumberRange): string[];
|
|
38
|
-
(alphabet?: import("../interfaces").RandexAlphabet
|
|
39
|
+
(alphabet?: import("../interfaces").RandexAlphabet): string[];
|
|
39
40
|
(alphabet: import("../interfaces").RandexAlphabet, words: RandexNumberRange): string[];
|
|
40
41
|
};
|
|
41
42
|
sentence: {
|
|
42
|
-
(options?: import("../interfaces").RandexSentenceOptions
|
|
43
|
+
(options?: import("../interfaces").RandexSentenceOptions): string[];
|
|
43
44
|
(words: RandexNumberRange): string[];
|
|
44
|
-
(alphabet?: import("../interfaces").RandexAlphabet
|
|
45
|
+
(alphabet?: import("../interfaces").RandexAlphabet): string[];
|
|
45
46
|
(alphabet: import("../interfaces").RandexAlphabet, words: RandexNumberRange): string[];
|
|
46
47
|
};
|
|
47
48
|
number: {
|
|
48
|
-
(length: RandexNumberRange, options?: import("../interfaces").RandomNumberOptions
|
|
49
|
-
(from: number, to: number, options?: import("../interfaces").RandomNumberOptions
|
|
49
|
+
(length: RandexNumberRange, options?: import("../interfaces").RandomNumberOptions): number[];
|
|
50
|
+
(from: number, to: number, options?: import("../interfaces").RandomNumberOptions): number[];
|
|
50
51
|
};
|
|
51
52
|
};
|
|
52
53
|
static spread<TItem>(array: TItem[], count: number): TItem[];
|
package/lib/custom/index.js
CHANGED
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Randex = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
var index = Randex.number(0, arrayCount);
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
const bool_1 = require("./bool");
|
|
6
|
+
const email_1 = require("./email");
|
|
7
|
+
const filenameX_1 = require("./filenameX");
|
|
8
|
+
const fullnameX_1 = require("./fullnameX");
|
|
9
|
+
const number_1 = require("./number");
|
|
10
|
+
const phrase_1 = require("./phrase");
|
|
11
|
+
const random_1 = require("./random");
|
|
12
|
+
const sentence_1 = require("./sentence");
|
|
13
|
+
const singleName_1 = require("./singleName");
|
|
14
|
+
const username_1 = require("./username");
|
|
15
|
+
const word_1 = require("./word");
|
|
16
|
+
class Randex {
|
|
17
|
+
static random = random_1.randexRandom;
|
|
18
|
+
static arrayItem(array, defaultValue) {
|
|
19
|
+
if (array?.length) {
|
|
20
|
+
const arrayCount = array.length - 1;
|
|
21
|
+
const index = Randex.number(0, arrayCount);
|
|
23
22
|
return array[index];
|
|
24
23
|
}
|
|
25
24
|
else if (defaultValue) {
|
|
@@ -28,41 +27,56 @@ var Randex = /** @class */ (function () {
|
|
|
28
27
|
else {
|
|
29
28
|
throw "Array is empty";
|
|
30
29
|
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
for (
|
|
30
|
+
}
|
|
31
|
+
static array(array, count) {
|
|
32
|
+
const result = [];
|
|
33
|
+
const maxCount = array.length;
|
|
34
|
+
const uniqueArray = [];
|
|
35
|
+
for (let i = 0; i < array.length; i++) {
|
|
37
36
|
uniqueArray.push(array[i]);
|
|
38
37
|
}
|
|
39
|
-
for (
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
for (let i = 0; i < count && i < maxCount; i++) {
|
|
39
|
+
const arrayCount = uniqueArray.length - 1;
|
|
40
|
+
const index = Randex.number(arrayCount);
|
|
41
|
+
const value = uniqueArray[index];
|
|
43
42
|
result.push(value);
|
|
44
43
|
uniqueArray.splice(index, 1);
|
|
45
44
|
}
|
|
46
45
|
return result;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
46
|
+
}
|
|
47
|
+
static bool = bool_1.randexBool;
|
|
48
|
+
static email = email_1.randexEmail;
|
|
49
|
+
static fileName = filenameX_1.randexFileName;
|
|
50
|
+
static fullName = fullnameX_1.randexFullName;
|
|
51
|
+
static singleName = singleName_1.randexSingleName;
|
|
52
|
+
static number = number_1.randexNumber;
|
|
53
|
+
static username = username_1.randexUsername;
|
|
54
|
+
static word = word_1.randexWord;
|
|
55
|
+
static sentence = sentence_1.randexSentence;
|
|
56
|
+
static phrase = phrase_1.randexPhrase;
|
|
57
|
+
static shuffle(array) {
|
|
58
|
+
let currentIndex = array.length;
|
|
59
|
+
// While there remain elements to shuffle...
|
|
60
|
+
while (currentIndex != 0) {
|
|
61
|
+
// Pick a remaining element...
|
|
62
|
+
const randomIndex = Math.floor(Math.random() * currentIndex);
|
|
63
|
+
currentIndex--;
|
|
64
|
+
// And swap it with the current element.
|
|
65
|
+
[array[currentIndex], array[randomIndex]] = [array[randomIndex], array[currentIndex]];
|
|
66
|
+
}
|
|
67
|
+
return array;
|
|
68
|
+
}
|
|
69
|
+
static many(count) {
|
|
70
|
+
return {
|
|
71
|
+
word: (0, word_1.randexManyWord)(count),
|
|
72
|
+
phrase: (0, phrase_1.randexManyPhrase)(count),
|
|
73
|
+
sentence: (0, sentence_1.randexManySentence)(count),
|
|
74
|
+
number: (0, number_1.randexManyNumber)(count),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
static spread(array, count) {
|
|
78
|
+
const picker = new utils_1.RandexSpreader(array);
|
|
53
79
|
return picker.spread(count);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
Randex.bool = bool_1.randexBool;
|
|
57
|
-
Randex.email = email_1.randexEmail;
|
|
58
|
-
Randex.fileName = filenameX_1.randexFileName;
|
|
59
|
-
Randex.fullName = fullnameX_1.randexFullName;
|
|
60
|
-
Randex.singleName = singleName_1.randexSingleName;
|
|
61
|
-
Randex.number = number_1.randexNumber;
|
|
62
|
-
Randex.username = username_1.randexUsername;
|
|
63
|
-
Randex.word = word_1.randexWord;
|
|
64
|
-
Randex.sentence = sentence_1.randexSentence;
|
|
65
|
-
Randex.phrase = phrase_1.randexPhrase;
|
|
66
|
-
return Randex;
|
|
67
|
-
}());
|
|
80
|
+
}
|
|
81
|
+
}
|
|
68
82
|
exports.Randex = Randex;
|
package/lib/custom/number.js
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
3
|
+
exports.randexNumber = randexNumber;
|
|
4
|
+
exports.randexManyNumber = randexManyNumber;
|
|
5
|
+
const set_1 = require("../basic/set");
|
|
5
6
|
function getNumberBase(decimals) {
|
|
6
7
|
return decimals === 1 ? 10 : Math.pow(10, decimals);
|
|
7
8
|
}
|
|
8
9
|
function getNumberValue(value, decimals) {
|
|
9
|
-
|
|
10
|
+
let result = value;
|
|
10
11
|
if (typeof decimals === "number") {
|
|
11
12
|
result = result * getNumberBase(decimals);
|
|
12
13
|
}
|
|
13
14
|
return result;
|
|
14
15
|
}
|
|
15
16
|
function innerRandomNumber(from, to, decimals) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
const fromV = getNumberValue(from, decimals);
|
|
18
|
+
const toV = getNumberValue(to, decimals);
|
|
19
|
+
let result = set_1.RandexSetUtil.randomRangeNumber(fromV, toV);
|
|
19
20
|
if (typeof decimals === "number") {
|
|
20
21
|
result = result / getNumberBase(decimals);
|
|
21
22
|
}
|
|
@@ -23,24 +24,22 @@ function innerRandomNumber(from, to, decimals) {
|
|
|
23
24
|
}
|
|
24
25
|
function randexNumber(p1, p2, p3) {
|
|
25
26
|
if (typeof p1 === "number" && typeof p2 === "number") {
|
|
26
|
-
return innerRandomNumber(p1, p2, p3
|
|
27
|
+
return innerRandomNumber(p1, p2, p3?.decimals);
|
|
27
28
|
}
|
|
28
29
|
else {
|
|
29
|
-
|
|
30
|
+
const decimals = p2?.decimals;
|
|
30
31
|
if (typeof p1 === "number") {
|
|
31
32
|
return innerRandomNumber(0, p1, decimals);
|
|
32
33
|
}
|
|
33
34
|
else {
|
|
34
|
-
|
|
35
|
+
const [min, max] = p1;
|
|
35
36
|
return innerRandomNumber(min, max, decimals);
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
39
|
}
|
|
39
|
-
exports.randexNumber = randexNumber;
|
|
40
40
|
function randexManyNumber(count) {
|
|
41
41
|
function many(p1, p2, p3) {
|
|
42
|
-
return set_1.RandexSetUtil.many(count,
|
|
42
|
+
return set_1.RandexSetUtil.many(count, () => randexNumber(p1, p2, p3));
|
|
43
43
|
}
|
|
44
44
|
return many;
|
|
45
45
|
}
|
|
46
|
-
exports.randexManyNumber = randexManyNumber;
|