randex 0.21.0 → 0.23.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/README.md +93 -93
- package/lib/custom/email.d.ts +0 -3
- package/lib/custom/email.js +0 -41
- package/lib/custom/filename.d.ts +0 -4
- package/lib/custom/filename.js +0 -41
- package/lib/custom/fullname.d.ts +0 -5
- package/lib/custom/fullname.js +0 -33
- package/lib/custom/index.d.ts +41 -5
- package/lib/custom/index.js +309 -5
- package/lib/custom/number.d.ts +0 -3
- package/lib/custom/number.js +0 -37
- package/lib/custom/random.d.ts +5 -0
- package/lib/custom/random.js +2 -0
- package/lib/custom/singleName.d.ts +5 -0
- package/lib/custom/singleName.js +2 -0
- package/lib/custom/username.d.ts +0 -1
- package/lib/custom/username.js +0 -10
- package/lib/index.d.ts +3 -1
- package/lib/index.js +4 -1
- package/lib/test/array-item.test.js +2 -2
- package/lib/test/array.test.js +2 -2
- package/lib/test/email.test.js +8 -8
- package/lib/test/filename.test.js +10 -10
- package/lib/test/fullname.test.js +1 -1
- package/lib/test/markdown.test.js +34 -35
- package/lib/test/name.test.js +10 -10
- package/lib/test/number-array.test.js +5 -5
- package/lib/test/number.test.js +6 -6
- package/lib/test/params.test.js +15 -15
- package/lib/test/random.test.js +11 -11
- package/lib/test/username.test.js +8 -8
- package/package.json +1 -1
- package/lib/basic/index.d.ts +0 -2
- package/lib/basic/index.js +0 -83
- package/lib/custom/array-item.d.ts +0 -2
- package/lib/custom/array-item.js +0 -18
- package/lib/custom/array.d.ts +0 -1
- package/lib/custom/array.js +0 -21
- package/lib/custom/bool.d.ts +0 -1
- package/lib/custom/bool.js +0 -7
- package/lib/custom/name.d.ts +0 -9
- package/lib/custom/name.js +0 -30
- package/lib/custom/number-array.d.ts +0 -2
- package/lib/custom/number-array.js +0 -30
|
@@ -1,56 +1,55 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var basic_1 = require("../basic");
|
|
4
3
|
var custom_1 = require("../custom");
|
|
5
4
|
describe("markdown", function () {
|
|
6
5
|
it("random", function () {
|
|
7
|
-
var value =
|
|
6
|
+
var value = custom_1.Randex.random({
|
|
8
7
|
set: "english",
|
|
9
8
|
length: 3,
|
|
10
9
|
});
|
|
11
10
|
expect(value.length).toBe(3);
|
|
12
|
-
value =
|
|
11
|
+
value = custom_1.Randex.random(["english", 3]);
|
|
13
12
|
expect(value.length).toBe(3);
|
|
14
13
|
//
|
|
15
|
-
value =
|
|
14
|
+
value = custom_1.Randex.random({
|
|
16
15
|
set: ["english", "lower"],
|
|
17
16
|
length: 3,
|
|
18
17
|
});
|
|
19
18
|
expect(value.length).toBe(3);
|
|
20
|
-
value =
|
|
19
|
+
value = custom_1.Randex.random([["english", "lower"], 3]);
|
|
21
20
|
expect(value.length).toBe(3);
|
|
22
21
|
//
|
|
23
|
-
value =
|
|
22
|
+
value = custom_1.Randex.random({
|
|
24
23
|
set: "english",
|
|
25
24
|
length: [1, 3],
|
|
26
25
|
});
|
|
27
26
|
expect(value.length).toBeLessThanOrEqual(3);
|
|
28
|
-
value =
|
|
27
|
+
value = custom_1.Randex.random(["english", [1, 3]]);
|
|
29
28
|
expect(value.length).toBeLessThanOrEqual(3);
|
|
30
29
|
//
|
|
31
|
-
value =
|
|
30
|
+
value = custom_1.Randex.random({
|
|
32
31
|
set: "number",
|
|
33
32
|
length: 3,
|
|
34
33
|
});
|
|
35
34
|
expect(value.length).toBe(3);
|
|
36
|
-
value =
|
|
35
|
+
value = custom_1.Randex.random(["number", 3]);
|
|
37
36
|
expect(value.length).toBe(3);
|
|
38
37
|
//
|
|
39
|
-
value =
|
|
38
|
+
value = custom_1.Randex.random({
|
|
40
39
|
range: "abc123",
|
|
41
40
|
length: 3,
|
|
42
41
|
});
|
|
43
42
|
expect(value.length).toBe(3);
|
|
44
43
|
//
|
|
45
|
-
value =
|
|
44
|
+
value = custom_1.Randex.random({
|
|
46
45
|
set: ["english", "number"],
|
|
47
46
|
length: 3,
|
|
48
47
|
});
|
|
49
48
|
expect(value.length).toBe(3);
|
|
50
|
-
value =
|
|
49
|
+
value = custom_1.Randex.random([["english", "number"], 3]);
|
|
51
50
|
expect(value.length).toBe(3);
|
|
52
51
|
//
|
|
53
|
-
value =
|
|
52
|
+
value = custom_1.Randex.random({
|
|
54
53
|
set: "english",
|
|
55
54
|
length: 2,
|
|
56
55
|
}, {
|
|
@@ -58,61 +57,61 @@ describe("markdown", function () {
|
|
|
58
57
|
length: 2,
|
|
59
58
|
});
|
|
60
59
|
expect(value.length).toBe(4);
|
|
61
|
-
value =
|
|
60
|
+
value = custom_1.Randex.random(["english", 2], [["english", "number"], 2]);
|
|
62
61
|
expect(value.length).toBe(4);
|
|
63
62
|
});
|
|
64
63
|
it("randomFileName", function () {
|
|
65
|
-
var value =
|
|
66
|
-
value =
|
|
64
|
+
var value = custom_1.Randex.fileName();
|
|
65
|
+
value = custom_1.Randex.fileName({
|
|
67
66
|
extension: "txt",
|
|
68
67
|
});
|
|
69
|
-
value =
|
|
70
|
-
value =
|
|
68
|
+
value = custom_1.Randex.fileName("txt");
|
|
69
|
+
value = custom_1.Randex.fileName({
|
|
71
70
|
fileNameLength: [7, 10],
|
|
72
71
|
extensionLength: 5,
|
|
73
72
|
});
|
|
74
|
-
value =
|
|
75
|
-
value =
|
|
73
|
+
value = custom_1.Randex.fileName([7, 10], 5);
|
|
74
|
+
value = custom_1.Randex.fileName({
|
|
76
75
|
fileNameLength: 8,
|
|
77
76
|
extension: "xml",
|
|
78
77
|
});
|
|
79
|
-
value =
|
|
78
|
+
value = custom_1.Randex.fileName(8, "xml");
|
|
80
79
|
expect(value).toBeTruthy();
|
|
81
80
|
});
|
|
82
81
|
it("randomUsername", function () {
|
|
83
|
-
var value =
|
|
82
|
+
var value = custom_1.Randex.username();
|
|
84
83
|
expect(value).toBeTruthy();
|
|
85
84
|
});
|
|
86
85
|
it("randomEmail", function () {
|
|
87
|
-
var value =
|
|
88
|
-
value =
|
|
86
|
+
var value = custom_1.Randex.email();
|
|
87
|
+
value = custom_1.Randex.email({
|
|
89
88
|
prefixLength: 8,
|
|
90
89
|
});
|
|
91
|
-
value =
|
|
92
|
-
value =
|
|
90
|
+
value = custom_1.Randex.email(8);
|
|
91
|
+
value = custom_1.Randex.email({
|
|
93
92
|
prefixLength: 8,
|
|
94
93
|
lowDomainLength: 4,
|
|
95
94
|
hightDomainLength: 2,
|
|
96
95
|
});
|
|
97
|
-
value =
|
|
98
|
-
value =
|
|
96
|
+
value = custom_1.Randex.email(8, 4, 2);
|
|
97
|
+
value = custom_1.Randex.email({
|
|
99
98
|
domain: "test.com",
|
|
100
99
|
});
|
|
101
|
-
value =
|
|
100
|
+
value = custom_1.Randex.email("test.com");
|
|
102
101
|
expect(value).toBeTruthy();
|
|
103
102
|
});
|
|
104
|
-
it("
|
|
105
|
-
var value =
|
|
103
|
+
it("singleName", function () {
|
|
104
|
+
var value = custom_1.Randex.singleName();
|
|
106
105
|
expect(value).toBeTruthy();
|
|
107
|
-
value =
|
|
106
|
+
value = custom_1.Randex.singleName({ alphabet: "french" });
|
|
108
107
|
expect(value).toBeTruthy();
|
|
109
|
-
value =
|
|
108
|
+
value = custom_1.Randex.singleName({ length: 5 });
|
|
110
109
|
expect(value).toBeTruthy();
|
|
111
|
-
value =
|
|
110
|
+
value = custom_1.Randex.singleName({ length: [2, 5] });
|
|
112
111
|
expect(value).toBeTruthy();
|
|
113
112
|
});
|
|
114
113
|
it("randomFullName", function () {
|
|
115
|
-
var value =
|
|
114
|
+
var value = custom_1.Randex.fullName();
|
|
116
115
|
expect(value).toBeTruthy();
|
|
117
116
|
});
|
|
118
117
|
});
|
package/lib/test/name.test.js
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var
|
|
3
|
+
var custom_1 = require("../custom");
|
|
4
4
|
var test_util_1 = require("./test-util");
|
|
5
5
|
describe("randomName", function () {
|
|
6
6
|
it("simple", function () {
|
|
7
7
|
test_util_1.TestUtil.loop(function () {
|
|
8
|
-
var value =
|
|
8
|
+
var value = custom_1.Randex.singleName();
|
|
9
9
|
expect(test_util_1.TestUtil.isNameValid(value)).toBeTruthy();
|
|
10
10
|
});
|
|
11
11
|
});
|
|
12
12
|
it("options: length", function () {
|
|
13
|
-
var value =
|
|
13
|
+
var value = custom_1.Randex.singleName({ length: 5 });
|
|
14
14
|
expect(value.length).toBe(5);
|
|
15
|
-
value =
|
|
15
|
+
value = custom_1.Randex.singleName(5);
|
|
16
16
|
expect(value.length).toBe(5);
|
|
17
17
|
//
|
|
18
|
-
value =
|
|
18
|
+
value = custom_1.Randex.singleName({ length: [5, 5] });
|
|
19
19
|
expect(value.length).toBe(5);
|
|
20
|
-
value =
|
|
20
|
+
value = custom_1.Randex.singleName([5, 5]);
|
|
21
21
|
expect(value.length).toBe(5);
|
|
22
22
|
//
|
|
23
|
-
value =
|
|
23
|
+
value = custom_1.Randex.singleName({ length: [1, 5] });
|
|
24
24
|
expect(test_util_1.TestUtil.inNumberRange(value.length, [1, 5])).toBeTruthy();
|
|
25
|
-
value =
|
|
25
|
+
value = custom_1.Randex.singleName([1, 5]);
|
|
26
26
|
expect(test_util_1.TestUtil.inNumberRange(value.length, [1, 5])).toBeTruthy();
|
|
27
27
|
});
|
|
28
28
|
it("options: alphabet", function () {
|
|
29
|
-
var value =
|
|
29
|
+
var value = custom_1.Randex.singleName({ alphabet: "russian", length: 5 });
|
|
30
30
|
expect(value.length).toBe(5);
|
|
31
|
-
value =
|
|
31
|
+
value = custom_1.Randex.singleName("french", 10);
|
|
32
32
|
expect(value.length).toBe(10);
|
|
33
33
|
});
|
|
34
34
|
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var
|
|
3
|
+
var custom_1 = require("../custom");
|
|
4
4
|
function testNumber(min, max, count) {
|
|
5
|
-
var value =
|
|
5
|
+
var value = custom_1.Randex.numberArray([min, max], count);
|
|
6
6
|
var uniqueResult = [];
|
|
7
7
|
var _loop_1 = function (i) {
|
|
8
8
|
var uniqueValue = value[i];
|
|
@@ -31,17 +31,17 @@ describe("randomNumberArray", function () {
|
|
|
31
31
|
var min = 5;
|
|
32
32
|
var max = 10;
|
|
33
33
|
var count = max - min + 1;
|
|
34
|
-
var value =
|
|
34
|
+
var value = custom_1.Randex.numberArray([min, max], count);
|
|
35
35
|
expect(value.length).toBe(count);
|
|
36
36
|
// max length limit
|
|
37
|
-
value =
|
|
37
|
+
value = custom_1.Randex.numberArray([min, max], count + 10);
|
|
38
38
|
expect(value.length).toBe(count);
|
|
39
39
|
});
|
|
40
40
|
it("range: fill all possible values", function () {
|
|
41
41
|
var min = 5;
|
|
42
42
|
var max = 10;
|
|
43
43
|
var count = max - min + 1;
|
|
44
|
-
var value =
|
|
44
|
+
var value = custom_1.Randex.numberArray([min, max], count);
|
|
45
45
|
expect(value.length).toBe(count);
|
|
46
46
|
var _loop_2 = function (i) {
|
|
47
47
|
expect(value.find(function (x) { return x === i; })).toBeTruthy();
|
package/lib/test/number.test.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var
|
|
3
|
+
var custom_1 = require("../custom");
|
|
4
4
|
var test_util_1 = require("./test-util");
|
|
5
5
|
function testNumber(max) {
|
|
6
|
-
var value =
|
|
6
|
+
var value = custom_1.Randex.number(max);
|
|
7
7
|
expect(value).toBeGreaterThanOrEqual(0);
|
|
8
8
|
expect(value).toBeLessThanOrEqual(max);
|
|
9
9
|
}
|
|
10
10
|
function testNumberWithArray(range, two) {
|
|
11
11
|
if (two === void 0) { two = false; }
|
|
12
12
|
var min = range[0], max = range[1];
|
|
13
|
-
var value = two ?
|
|
13
|
+
var value = two ? custom_1.Randex.number(range) : custom_1.Randex.number(min, max);
|
|
14
14
|
expect(value).toBeGreaterThanOrEqual(min);
|
|
15
15
|
expect(value).toBeLessThanOrEqual(max);
|
|
16
16
|
}
|
|
@@ -24,7 +24,7 @@ describe("randomNumber", function () {
|
|
|
24
24
|
var max = 4;
|
|
25
25
|
var result = {};
|
|
26
26
|
test_util_1.TestUtil.loop(function () {
|
|
27
|
-
var value =
|
|
27
|
+
var value = custom_1.Randex.number(max);
|
|
28
28
|
result[value] = (result[value] || 0) + 1;
|
|
29
29
|
});
|
|
30
30
|
for (var i = 0; i <= max; i++) {
|
|
@@ -44,7 +44,7 @@ describe("randomNumber", function () {
|
|
|
44
44
|
it("two numbers with decimals", function () {
|
|
45
45
|
var count = 0;
|
|
46
46
|
test_util_1.TestUtil.loop(function () {
|
|
47
|
-
var value =
|
|
47
|
+
var value = custom_1.Randex.number(1, 10, { decimals: 2 });
|
|
48
48
|
if (/\.\d{2}$/g.test(value.toString())) {
|
|
49
49
|
count++;
|
|
50
50
|
}
|
|
@@ -54,7 +54,7 @@ describe("randomNumber", function () {
|
|
|
54
54
|
it("a number with decimals", function () {
|
|
55
55
|
var count = 0;
|
|
56
56
|
test_util_1.TestUtil.loop(function () {
|
|
57
|
-
var value =
|
|
57
|
+
var value = custom_1.Randex.number(10, { decimals: 2 });
|
|
58
58
|
if (/\.\d{2}$/g.test(value.toString())) {
|
|
59
59
|
count++;
|
|
60
60
|
}
|
package/lib/test/params.test.js
CHANGED
|
@@ -1,51 +1,51 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var basic_1 = require("../basic");
|
|
4
3
|
var test_util_1 = require("./test-util");
|
|
4
|
+
var custom_1 = require("../custom");
|
|
5
5
|
describe("random params", function () {
|
|
6
6
|
it("array 1", function () {
|
|
7
7
|
var set = "english";
|
|
8
|
-
var result1 =
|
|
9
|
-
var result2 =
|
|
8
|
+
var result1 = custom_1.Randex.random({ set: set });
|
|
9
|
+
var result2 = custom_1.Randex.random(set);
|
|
10
10
|
test_util_1.TestUtil.testInSet(result1, set);
|
|
11
11
|
test_util_1.TestUtil.testInSet(result2, set);
|
|
12
12
|
});
|
|
13
13
|
it("single: array", function () {
|
|
14
14
|
var set = ["number", "english"];
|
|
15
|
-
var result1 =
|
|
16
|
-
var result2 =
|
|
15
|
+
var result1 = custom_1.Randex.random({ set: set });
|
|
16
|
+
var result2 = custom_1.Randex.random(set);
|
|
17
17
|
test_util_1.TestUtil.testInSet(result1, set);
|
|
18
18
|
test_util_1.TestUtil.testInSet(result2, set);
|
|
19
19
|
});
|
|
20
20
|
it("single: array, length", function () {
|
|
21
21
|
var set = ["number", "english"];
|
|
22
22
|
var length = 3;
|
|
23
|
-
var result1 =
|
|
24
|
-
var result2 =
|
|
23
|
+
var result1 = custom_1.Randex.random({ set: set, length: length });
|
|
24
|
+
var result2 = custom_1.Randex.random([set, length]);
|
|
25
25
|
test_util_1.TestUtil.testInSet(result1, set, length);
|
|
26
26
|
test_util_1.TestUtil.testInSet(result2, set, length);
|
|
27
27
|
});
|
|
28
28
|
it("single: array, length as array", function () {
|
|
29
29
|
var set = ["number", "english"];
|
|
30
30
|
var length = [1, 4];
|
|
31
|
-
var result1 =
|
|
32
|
-
var result2 =
|
|
31
|
+
var result1 = custom_1.Randex.random({ set: set, length: length });
|
|
32
|
+
var result2 = custom_1.Randex.random([set, length]);
|
|
33
33
|
test_util_1.TestUtil.testInSet(result1, set, length);
|
|
34
34
|
test_util_1.TestUtil.testInSet(result2, set, length);
|
|
35
35
|
});
|
|
36
36
|
it("array 2 (range)", function () {
|
|
37
37
|
var set = "number";
|
|
38
38
|
var range = "abcdefghijklmnopqrstuvwxyz";
|
|
39
|
-
var result1 =
|
|
40
|
-
var result2 =
|
|
39
|
+
var result1 = custom_1.Randex.random({ set: set, range: range });
|
|
40
|
+
var result2 = custom_1.Randex.random([set, range]);
|
|
41
41
|
test_util_1.TestUtil.testInBoth(result1, set, range);
|
|
42
42
|
test_util_1.TestUtil.testInBoth(result2, set, range);
|
|
43
43
|
});
|
|
44
44
|
it("array 2 (length)", function () {
|
|
45
45
|
var set = "english";
|
|
46
46
|
var length = 3;
|
|
47
|
-
var result1 =
|
|
48
|
-
var result2 =
|
|
47
|
+
var result1 = custom_1.Randex.random({ set: set, length: length });
|
|
48
|
+
var result2 = custom_1.Randex.random([set, length]);
|
|
49
49
|
test_util_1.TestUtil.testInSet(result1, set, length);
|
|
50
50
|
test_util_1.TestUtil.testInSet(result2, set, length);
|
|
51
51
|
});
|
|
@@ -53,8 +53,8 @@ describe("random params", function () {
|
|
|
53
53
|
var set = "number";
|
|
54
54
|
var range = "abcdefghijklmnopqrstuvwxyz";
|
|
55
55
|
var length = 3;
|
|
56
|
-
var result1 =
|
|
57
|
-
var result2 =
|
|
56
|
+
var result1 = custom_1.Randex.random({ set: set, range: range, length: length });
|
|
57
|
+
var result2 = custom_1.Randex.random([set, range, length]);
|
|
58
58
|
test_util_1.TestUtil.testInBoth(result1, set, range, length);
|
|
59
59
|
test_util_1.TestUtil.testInBoth(result2, set, range, length);
|
|
60
60
|
});
|
package/lib/test/random.test.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var basic_1 = require("../basic");
|
|
4
3
|
var test_util_1 = require("./test-util");
|
|
4
|
+
var custom_1 = require("../custom");
|
|
5
5
|
function inSet(set, length) {
|
|
6
6
|
if (length === void 0) { length = 1; }
|
|
7
|
-
var result =
|
|
7
|
+
var result = custom_1.Randex.random({ set: set, length: length });
|
|
8
8
|
test_util_1.TestUtil.testInSet(result, set, length);
|
|
9
9
|
}
|
|
10
10
|
function inRange(range, length) {
|
|
11
11
|
if (length === void 0) { length = 1; }
|
|
12
|
-
var result =
|
|
12
|
+
var result = custom_1.Randex.random({ range: range, length: length });
|
|
13
13
|
test_util_1.TestUtil.testInRange(result, range, length);
|
|
14
14
|
}
|
|
15
15
|
describe("random", function () {
|
|
@@ -30,7 +30,7 @@ describe("random", function () {
|
|
|
30
30
|
var length = [0, 4];
|
|
31
31
|
var result = {};
|
|
32
32
|
test_util_1.TestUtil.loop(function () {
|
|
33
|
-
var l =
|
|
33
|
+
var l = custom_1.Randex.random({ set: "english", length: length }).length;
|
|
34
34
|
result[l] = (result[l] || 0) + 1;
|
|
35
35
|
});
|
|
36
36
|
for (var i = 0; i <= 4; i++) {
|
|
@@ -41,7 +41,7 @@ describe("random", function () {
|
|
|
41
41
|
var length = [5, 8];
|
|
42
42
|
var result = {};
|
|
43
43
|
test_util_1.TestUtil.loop(function () {
|
|
44
|
-
var l =
|
|
44
|
+
var l = custom_1.Randex.random({ set: "english", length: length }).length;
|
|
45
45
|
result[l] = (result[l] || 0) + 1;
|
|
46
46
|
});
|
|
47
47
|
for (var i = 5; i <= 8; i++) {
|
|
@@ -55,16 +55,16 @@ describe("random", function () {
|
|
|
55
55
|
inSet("english", [0, 1]);
|
|
56
56
|
});
|
|
57
57
|
it("length: alphabet", function () {
|
|
58
|
-
var value =
|
|
58
|
+
var value = custom_1.Randex.random("english");
|
|
59
59
|
expect(value.length).toBe(1);
|
|
60
|
-
value =
|
|
60
|
+
value = custom_1.Randex.random(["english", "l"]);
|
|
61
61
|
expect(value.length).toBe(1);
|
|
62
62
|
});
|
|
63
63
|
it("alphabet: upper", function () {
|
|
64
64
|
test_util_1.TestUtil.loop(function () {
|
|
65
|
-
var value =
|
|
65
|
+
var value = custom_1.Randex.random(["english", "u"]);
|
|
66
66
|
expect(test_util_1.TestUtil.isUpperCharValid(value, 1)).toBeTruthy();
|
|
67
|
-
value =
|
|
67
|
+
value = custom_1.Randex.random([
|
|
68
68
|
["english", "u"],
|
|
69
69
|
[1, 3],
|
|
70
70
|
]);
|
|
@@ -73,9 +73,9 @@ describe("random", function () {
|
|
|
73
73
|
});
|
|
74
74
|
it("alphabet: lower", function () {
|
|
75
75
|
test_util_1.TestUtil.loop(function () {
|
|
76
|
-
var value =
|
|
76
|
+
var value = custom_1.Randex.random(["english", "l"]);
|
|
77
77
|
expect(test_util_1.TestUtil.isLowerCharValid(value, 1)).toBeTruthy();
|
|
78
|
-
value =
|
|
78
|
+
value = custom_1.Randex.random([
|
|
79
79
|
["english", "lower"],
|
|
80
80
|
[1, 3],
|
|
81
81
|
]);
|
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var
|
|
3
|
+
var custom_1 = require("../custom");
|
|
4
4
|
var test_util_1 = require("./test-util");
|
|
5
5
|
describe("randomEmail", function () {
|
|
6
6
|
it("simple", function () {
|
|
7
7
|
test_util_1.TestUtil.loop(function () {
|
|
8
|
-
var value =
|
|
8
|
+
var value = custom_1.Randex.username();
|
|
9
9
|
expect(test_util_1.TestUtil.isUsernameValid(value)).toBeTruthy();
|
|
10
10
|
});
|
|
11
11
|
});
|
|
12
12
|
it("options", function () {
|
|
13
|
-
var value =
|
|
13
|
+
var value = custom_1.Randex.username({ length: 5 });
|
|
14
14
|
expect(value.length).toBe(5);
|
|
15
|
-
value =
|
|
15
|
+
value = custom_1.Randex.username(5);
|
|
16
16
|
expect(value.length).toBe(5);
|
|
17
17
|
//
|
|
18
|
-
value =
|
|
18
|
+
value = custom_1.Randex.username({ length: [5, 5] });
|
|
19
19
|
expect(value.length).toBe(5);
|
|
20
|
-
value =
|
|
20
|
+
value = custom_1.Randex.username([5, 5]);
|
|
21
21
|
expect(value.length).toBe(5);
|
|
22
22
|
//
|
|
23
|
-
value =
|
|
23
|
+
value = custom_1.Randex.username({ length: [1, 5] });
|
|
24
24
|
expect(test_util_1.TestUtil.inNumberRange(value.length, [1, 5])).toBeTruthy();
|
|
25
|
-
value =
|
|
25
|
+
value = custom_1.Randex.username([1, 5]);
|
|
26
26
|
expect(test_util_1.TestUtil.inNumberRange(value.length, [1, 5])).toBeTruthy();
|
|
27
27
|
});
|
|
28
28
|
});
|
package/package.json
CHANGED
package/lib/basic/index.d.ts
DELETED
package/lib/basic/index.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.random = void 0;
|
|
4
|
-
var set_1 = require("./set");
|
|
5
|
-
var type_1 = require("./type");
|
|
6
|
-
function randomString(params) {
|
|
7
|
-
var length = params.length, range = params.range;
|
|
8
|
-
var result = "";
|
|
9
|
-
var currentLength = 0;
|
|
10
|
-
if (typeof length === "number") {
|
|
11
|
-
currentLength = length;
|
|
12
|
-
}
|
|
13
|
-
else if (Array.isArray(length)) {
|
|
14
|
-
var min = length[0], max = length[1];
|
|
15
|
-
currentLength = min + set_1.RandexSetUtil.randomNumber(max - min + 1);
|
|
16
|
-
}
|
|
17
|
-
for (var i = 0; i < currentLength; i++) {
|
|
18
|
-
var index = set_1.RandexSetUtil.randomNumber(range.length - 1);
|
|
19
|
-
if (range.length >= index || range.length <= index) {
|
|
20
|
-
result += range[index];
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return result;
|
|
24
|
-
}
|
|
25
|
-
function toContent(options) {
|
|
26
|
-
if (type_1.RandexTypeParser.isSet(options)) {
|
|
27
|
-
return {
|
|
28
|
-
set: options,
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
else if (type_1.RandexTypeParser.isPartArray(options)) {
|
|
32
|
-
if (options.length === 2) {
|
|
33
|
-
var set = options[0], rangeOrLength = options[1];
|
|
34
|
-
return type_1.RandexTypeParser.isLength(rangeOrLength)
|
|
35
|
-
? {
|
|
36
|
-
set: set,
|
|
37
|
-
length: rangeOrLength,
|
|
38
|
-
}
|
|
39
|
-
: {
|
|
40
|
-
set: set,
|
|
41
|
-
range: rangeOrLength,
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
else if (options.length === 3) {
|
|
45
|
-
var set = options[0], range = options[1], length_1 = options[2];
|
|
46
|
-
return {
|
|
47
|
-
set: set,
|
|
48
|
-
range: range,
|
|
49
|
-
length: length_1,
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return options;
|
|
54
|
-
}
|
|
55
|
-
function toRangeOptions(options) {
|
|
56
|
-
var fullRange = "";
|
|
57
|
-
var set = options.set, range = options.range, _a = options.length, length = _a === void 0 ? 1 : _a;
|
|
58
|
-
if (range) {
|
|
59
|
-
fullRange += range;
|
|
60
|
-
}
|
|
61
|
-
if (set) {
|
|
62
|
-
fullRange += set_1.RandexSetUtil.toRange(set);
|
|
63
|
-
}
|
|
64
|
-
return {
|
|
65
|
-
range: fullRange,
|
|
66
|
-
length: length,
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
function random() {
|
|
70
|
-
var options = [];
|
|
71
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
72
|
-
options[_i] = arguments[_i];
|
|
73
|
-
}
|
|
74
|
-
var result = "";
|
|
75
|
-
for (var _a = 0, options_1 = options; _a < options_1.length; _a++) {
|
|
76
|
-
var option = options_1[_a];
|
|
77
|
-
var content = toContent(option);
|
|
78
|
-
var p = toRangeOptions(content);
|
|
79
|
-
result += randomString(p);
|
|
80
|
-
}
|
|
81
|
-
return result;
|
|
82
|
-
}
|
|
83
|
-
exports.random = random;
|
package/lib/custom/array-item.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.randomArrayItem = void 0;
|
|
4
|
-
var number_1 = require("./number");
|
|
5
|
-
function randomArrayItem(array, defaultValue) {
|
|
6
|
-
if (array === null || array === void 0 ? void 0 : array.length) {
|
|
7
|
-
var arrayCount = array.length - 1;
|
|
8
|
-
var index = (0, number_1.randomNumber)(0, arrayCount);
|
|
9
|
-
return array[index];
|
|
10
|
-
}
|
|
11
|
-
else if (defaultValue) {
|
|
12
|
-
return defaultValue;
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
throw "Array is empty";
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
exports.randomArrayItem = randomArrayItem;
|
package/lib/custom/array.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function randomArray<T>(array: T[], count: number): T[];
|
package/lib/custom/array.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.randomArray = void 0;
|
|
4
|
-
var number_1 = require("./number");
|
|
5
|
-
function randomArray(array, count) {
|
|
6
|
-
var result = [];
|
|
7
|
-
var maxCount = array.length;
|
|
8
|
-
var uniqueArray = [];
|
|
9
|
-
for (var i = 0; i < array.length; i++) {
|
|
10
|
-
uniqueArray.push(array[i]);
|
|
11
|
-
}
|
|
12
|
-
for (var i = 0; i < count && i < maxCount; i++) {
|
|
13
|
-
var arrayCount = uniqueArray.length - 1;
|
|
14
|
-
var index = (0, number_1.randomNumber)(arrayCount);
|
|
15
|
-
var value = uniqueArray[index];
|
|
16
|
-
result.push(value);
|
|
17
|
-
uniqueArray.splice(index, 1);
|
|
18
|
-
}
|
|
19
|
-
return result;
|
|
20
|
-
}
|
|
21
|
-
exports.randomArray = randomArray;
|
package/lib/custom/bool.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function randomBool(): boolean;
|
package/lib/custom/bool.js
DELETED
package/lib/custom/name.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { RandexAlphabet, RandexLength } from "../interfaces";
|
|
2
|
-
export interface RandexNameOptions {
|
|
3
|
-
alphabet?: RandexAlphabet;
|
|
4
|
-
length?: RandexLength;
|
|
5
|
-
}
|
|
6
|
-
export declare function randomName(options?: RandexNameOptions): any;
|
|
7
|
-
export declare function randomName(length: RandexLength): any;
|
|
8
|
-
export declare function randomName(alphabet?: RandexAlphabet): any;
|
|
9
|
-
export declare function randomName(alphabet: RandexAlphabet, length: RandexLength): any;
|