randex 0.21.0 → 0.22.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.
Files changed (43) hide show
  1. package/lib/custom/email.d.ts +0 -3
  2. package/lib/custom/email.js +0 -41
  3. package/lib/custom/filename.d.ts +0 -4
  4. package/lib/custom/filename.js +0 -41
  5. package/lib/custom/fullname.d.ts +0 -5
  6. package/lib/custom/fullname.js +0 -33
  7. package/lib/custom/index.d.ts +41 -5
  8. package/lib/custom/index.js +309 -5
  9. package/lib/custom/number.d.ts +0 -3
  10. package/lib/custom/number.js +0 -37
  11. package/lib/custom/random.d.ts +5 -0
  12. package/lib/custom/random.js +2 -0
  13. package/lib/custom/singleName.d.ts +5 -0
  14. package/lib/custom/singleName.js +2 -0
  15. package/lib/custom/username.d.ts +0 -1
  16. package/lib/custom/username.js +0 -10
  17. package/lib/index.d.ts +3 -1
  18. package/lib/index.js +4 -1
  19. package/lib/test/array-item.test.js +2 -2
  20. package/lib/test/array.test.js +2 -2
  21. package/lib/test/email.test.js +8 -8
  22. package/lib/test/filename.test.js +10 -10
  23. package/lib/test/fullname.test.js +1 -1
  24. package/lib/test/markdown.test.js +34 -35
  25. package/lib/test/name.test.js +10 -10
  26. package/lib/test/number-array.test.js +5 -5
  27. package/lib/test/number.test.js +6 -6
  28. package/lib/test/params.test.js +15 -15
  29. package/lib/test/random.test.js +11 -11
  30. package/lib/test/username.test.js +8 -8
  31. package/package.json +1 -1
  32. package/lib/basic/index.d.ts +0 -2
  33. package/lib/basic/index.js +0 -83
  34. package/lib/custom/array-item.d.ts +0 -2
  35. package/lib/custom/array-item.js +0 -18
  36. package/lib/custom/array.d.ts +0 -1
  37. package/lib/custom/array.js +0 -21
  38. package/lib/custom/bool.d.ts +0 -1
  39. package/lib/custom/bool.js +0 -7
  40. package/lib/custom/name.d.ts +0 -9
  41. package/lib/custom/name.js +0 -30
  42. package/lib/custom/number-array.d.ts +0 -2
  43. package/lib/custom/number-array.js +0 -30
@@ -10,7 +10,4 @@ interface DomainEmailOptions {
10
10
  domain?: string;
11
11
  }
12
12
  export type RandexEmailOptions = BasicEmailOptions & (DomainLengthEmailOptions | DomainEmailOptions);
13
- export declare function randomEmail(options?: RandexEmailOptions): any;
14
- export declare function randomEmail(prefixLength: RandexLength, lowDomainLength?: RandexLength, hightDomainLength?: RandexLength): any;
15
- export declare function randomEmail(domain: string): any;
16
13
  export {};
@@ -1,43 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.randomEmail = void 0;
4
- var basic_1 = require("../basic");
5
- var set_1 = require("../basic/set");
6
- var type_1 = require("../basic/type");
7
- function randomEmail(p1, p2, p3) {
8
- var prefixLength = set_1.RandexSetUtil.defaultEmailPrefixLength;
9
- var hightDomainLength = set_1.RandexSetUtil.defaultHightDomainEmailLength;
10
- var lowDomainLength = set_1.RandexSetUtil.defaultLowDomainEmailLength;
11
- var domain = "";
12
- if (type_1.RandexTypeParser.isLength(p1)) {
13
- prefixLength = p1;
14
- if (type_1.RandexTypeParser.isLength(p2)) {
15
- lowDomainLength = p2;
16
- }
17
- if (type_1.RandexTypeParser.isLength(p3)) {
18
- hightDomainLength = p3;
19
- }
20
- }
21
- else if (typeof p1 === "string") {
22
- domain = p1;
23
- }
24
- else if (typeof p1 === "object") {
25
- if (p1.prefixLength) {
26
- prefixLength = p1.prefixLength;
27
- }
28
- if (p1.hightDomainLength) {
29
- hightDomainLength = p1.hightDomainLength;
30
- }
31
- if (p1.lowDomainLength) {
32
- lowDomainLength = p1.lowDomainLength;
33
- }
34
- if (p1.domain) {
35
- domain = p1.domain;
36
- }
37
- }
38
- if (!domain) {
39
- domain = (0, basic_1.random)([["english", "l"], lowDomainLength]) + "." + (0, basic_1.random)([["english", "l"], hightDomainLength]);
40
- }
41
- return (0, basic_1.random)([[["english", "l"], "number"], prefixLength]) + "@" + domain;
42
- }
43
- exports.randomEmail = randomEmail;
@@ -9,8 +9,4 @@ interface ExtensionFileNameOptions {
9
9
  extension?: string;
10
10
  }
11
11
  export type RandexFileNameOptions = BasicFileNameOptions & (ExtensionFileNameOptions | ExtensionLengthFileNameOptions);
12
- export declare function randomFileName(options?: RandexFileNameOptions): any;
13
- export declare function randomFileName(fileNameLength: RandexLength, extensionLength?: RandexLength): any;
14
- export declare function randomFileName(fileNameLength: RandexLength, extension: string): any;
15
- export declare function randomFileName(extension: string): any;
16
12
  export {};
@@ -1,43 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.randomFileName = void 0;
4
- var basic_1 = require("../basic");
5
- var set_1 = require("../basic/set");
6
- var type_1 = require("../basic/type");
7
- function randomFileName(p1, p2) {
8
- var fileNameLength = set_1.RandexSetUtil.defaultFileNameLength;
9
- var extensionLength = set_1.RandexSetUtil.defaultExtensionLength;
10
- var extension = "";
11
- if (type_1.RandexTypeParser.isLength(p1)) {
12
- fileNameLength = p1;
13
- if (type_1.RandexTypeParser.isLength(p2)) {
14
- extensionLength = p2;
15
- }
16
- else if (typeof p2 === "string") {
17
- extension = p2;
18
- }
19
- }
20
- else if (typeof p1 === "string") {
21
- extension = p1;
22
- }
23
- else if (typeof p1 === "object") {
24
- if (p1.fileNameLength) {
25
- fileNameLength = p1.fileNameLength;
26
- }
27
- if (p1.extensionLength) {
28
- extensionLength = p1.extensionLength;
29
- }
30
- if (p1.extension) {
31
- extension = p1.extension;
32
- }
33
- }
34
- fileNameLength = set_1.RandexSetUtil.getLength(1, fileNameLength, fileNameLength);
35
- if (!extension) {
36
- extension = (0, basic_1.random)([["english", "l"], extensionLength]);
37
- }
38
- return ((0, basic_1.random)([["english", "number"], set_1.RandexSetUtil.fileNameExtraChars, fileNameLength]) +
39
- (0, basic_1.random)(["english", "number"]) +
40
- "." +
41
- (extension ? extension.replace(/^\./, "") : (0, basic_1.random)([["english", "l"], extensionLength])));
42
- }
43
- exports.randomFileName = randomFileName;
@@ -4,8 +4,3 @@ export interface RandexFullNameOptions {
4
4
  firstLength?: RandexLength;
5
5
  secondLength?: RandexLength;
6
6
  }
7
- export declare function randomFullName(options?: RandexFullNameOptions): any;
8
- export declare function randomFullName(length: RandexLength): any;
9
- export declare function randomFullName(alphabet?: RandexAlphabet): any;
10
- export declare function randomFullName(alphabet: RandexAlphabet, length: RandexLength): any;
11
- export declare function randomFullName(alphabet: RandexAlphabet, firstLength: RandexLength, secondLength: RandexLength): any;
@@ -1,35 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.randomFullName = void 0;
4
- var type_1 = require("../basic/type");
5
- var name_1 = require("./name");
6
- function randomFullName(p1, p2, p3) {
7
- var firstLength = 0;
8
- var secondLength = 0;
9
- var alphabet = "english";
10
- if (type_1.RandexTypeParser.isLength(p1)) {
11
- firstLength = secondLength = p1;
12
- }
13
- else if (type_1.RandexTypeParser.inAlphabet(p1)) {
14
- alphabet = p1;
15
- if (type_1.RandexTypeParser.isLength(p2)) {
16
- firstLength = secondLength = p2;
17
- }
18
- if (type_1.RandexTypeParser.isLength(p3)) {
19
- secondLength = p3;
20
- }
21
- }
22
- else if (typeof p1 === "object") {
23
- if (p1.alphabet) {
24
- alphabet = p1.alphabet;
25
- }
26
- if (p1.firstLength) {
27
- firstLength = p1.firstLength;
28
- }
29
- if (p1.secondLength) {
30
- secondLength = p1.secondLength;
31
- }
32
- }
33
- return (0, name_1.randomName)({ length: firstLength, alphabet: alphabet }) + " " + (0, name_1.randomName)({ length: secondLength, alphabet: alphabet });
34
- }
35
- exports.randomFullName = randomFullName;
@@ -1,10 +1,46 @@
1
+ import { RandexAlphabet, RandexContentOptions, RandexLength } from "../interfaces";
2
+ import { RandexEmailOptions } from "./email";
3
+ import { RandexFileNameOptions } from "./filename";
4
+ import { RandexSingleNameOptions } from "./singleName";
5
+ import { RandomNumberOptions } from "./number";
6
+ import { RandexUsernameOptions } from "./username";
7
+ import { RandexFullNameOptions } from "./fullname";
1
8
  export * from "./email";
2
9
  export * from "./filename";
3
- export * from "./name";
10
+ export * from "./singleName";
4
11
  export * from "./username";
5
12
  export * from "./fullname";
6
13
  export * from "./number";
7
- export * from "./number-array";
8
- export * from "./array";
9
- export * from "./array-item";
10
- export * from "./bool";
14
+ export declare class Randex {
15
+ private static randomString;
16
+ private static toContent;
17
+ private static toRangeOptions;
18
+ static random(...options: RandexContentOptions[]): string;
19
+ static arrayItem<T>(array: T[]): T;
20
+ static arrayItem<T>(array: T[], defaultValue: T): T;
21
+ static array<T>(array: T[], count: number): T[];
22
+ static bool(): boolean;
23
+ static email(options?: RandexEmailOptions): any;
24
+ static email(prefixLength: RandexLength, lowDomainLength?: RandexLength, hightDomainLength?: RandexLength): any;
25
+ static email(domain: string): any;
26
+ static fileName(options?: RandexFileNameOptions): any;
27
+ static fileName(fileNameLength: RandexLength, extensionLength?: RandexLength): any;
28
+ static fileName(fileNameLength: RandexLength, extension: string): any;
29
+ static fileName(extension: string): any;
30
+ static fullName(options?: RandexFullNameOptions): any;
31
+ static fullName(length: RandexLength): any;
32
+ static fullName(alphabet?: RandexAlphabet): any;
33
+ static fullName(alphabet: RandexAlphabet, length: RandexLength): any;
34
+ static fullName(alphabet: RandexAlphabet, firstLength: RandexLength, secondLength: RandexLength): any;
35
+ static singleName(options?: RandexSingleNameOptions): any;
36
+ static singleName(length: RandexLength): any;
37
+ static singleName(alphabet?: RandexAlphabet): any;
38
+ static singleName(alphabet: RandexAlphabet, length: RandexLength): any;
39
+ static numberArray(length: RandexLength, count: number): number[];
40
+ private static getNumberBase;
41
+ private static getNumberValue;
42
+ private static innerRandomNumber;
43
+ static number(length: RandexLength, options?: RandomNumberOptions): number;
44
+ static number(from: number, to: number, options?: RandomNumberOptions): number;
45
+ static username(options?: RandexUsernameOptions | RandexLength): string;
46
+ }
@@ -14,13 +14,317 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.Randex = void 0;
18
+ var set_1 = require("../basic/set");
19
+ var type_1 = require("../basic/type");
17
20
  __exportStar(require("./email"), exports);
18
21
  __exportStar(require("./filename"), exports);
19
- __exportStar(require("./name"), exports);
22
+ __exportStar(require("./singleName"), exports);
20
23
  __exportStar(require("./username"), exports);
21
24
  __exportStar(require("./fullname"), exports);
22
25
  __exportStar(require("./number"), exports);
23
- __exportStar(require("./number-array"), exports);
24
- __exportStar(require("./array"), exports);
25
- __exportStar(require("./array-item"), exports);
26
- __exportStar(require("./bool"), exports);
26
+ var Randex = /** @class */ (function () {
27
+ function Randex() {
28
+ }
29
+ // base
30
+ Randex.randomString = function (params) {
31
+ var length = params.length, range = params.range;
32
+ var result = "";
33
+ var currentLength = 0;
34
+ if (typeof length === "number") {
35
+ currentLength = length;
36
+ }
37
+ else if (Array.isArray(length)) {
38
+ var min = length[0], max = length[1];
39
+ currentLength = min + set_1.RandexSetUtil.randomNumber(max - min + 1);
40
+ }
41
+ for (var i = 0; i < currentLength; i++) {
42
+ var index = set_1.RandexSetUtil.randomNumber(range.length - 1);
43
+ if (range.length >= index || range.length <= index) {
44
+ result += range[index];
45
+ }
46
+ }
47
+ return result;
48
+ };
49
+ Randex.toContent = function (options) {
50
+ if (type_1.RandexTypeParser.isSet(options)) {
51
+ return {
52
+ set: options,
53
+ };
54
+ }
55
+ else if (type_1.RandexTypeParser.isPartArray(options)) {
56
+ if (options.length === 2) {
57
+ var set = options[0], rangeOrLength = options[1];
58
+ return type_1.RandexTypeParser.isLength(rangeOrLength)
59
+ ? {
60
+ set: set,
61
+ length: rangeOrLength,
62
+ }
63
+ : {
64
+ set: set,
65
+ range: rangeOrLength,
66
+ };
67
+ }
68
+ else if (options.length === 3) {
69
+ var set = options[0], range = options[1], length_1 = options[2];
70
+ return {
71
+ set: set,
72
+ range: range,
73
+ length: length_1,
74
+ };
75
+ }
76
+ }
77
+ return options;
78
+ };
79
+ Randex.toRangeOptions = function (options) {
80
+ var fullRange = "";
81
+ var set = options.set, range = options.range, _a = options.length, length = _a === void 0 ? 1 : _a;
82
+ if (range) {
83
+ fullRange += range;
84
+ }
85
+ if (set) {
86
+ fullRange += set_1.RandexSetUtil.toRange(set);
87
+ }
88
+ return {
89
+ range: fullRange,
90
+ length: length,
91
+ };
92
+ };
93
+ Randex.random = function () {
94
+ var options = [];
95
+ for (var _i = 0; _i < arguments.length; _i++) {
96
+ options[_i] = arguments[_i];
97
+ }
98
+ var result = "";
99
+ for (var _a = 0, options_1 = options; _a < options_1.length; _a++) {
100
+ var option = options_1[_a];
101
+ var content = Randex.toContent(option);
102
+ var p = Randex.toRangeOptions(content);
103
+ result += Randex.randomString(p);
104
+ }
105
+ return result;
106
+ };
107
+ Randex.arrayItem = function (array, defaultValue) {
108
+ if (array === null || array === void 0 ? void 0 : array.length) {
109
+ var arrayCount = array.length - 1;
110
+ var index = Randex.number(0, arrayCount);
111
+ return array[index];
112
+ }
113
+ else if (defaultValue) {
114
+ return defaultValue;
115
+ }
116
+ else {
117
+ throw "Array is empty";
118
+ }
119
+ };
120
+ Randex.array = function (array, count) {
121
+ var result = [];
122
+ var maxCount = array.length;
123
+ var uniqueArray = [];
124
+ for (var i = 0; i < array.length; i++) {
125
+ uniqueArray.push(array[i]);
126
+ }
127
+ for (var i = 0; i < count && i < maxCount; i++) {
128
+ var arrayCount = uniqueArray.length - 1;
129
+ var index = Randex.number(arrayCount);
130
+ var value = uniqueArray[index];
131
+ result.push(value);
132
+ uniqueArray.splice(index, 1);
133
+ }
134
+ return result;
135
+ };
136
+ Randex.bool = function () {
137
+ return Math.random() < 0.5;
138
+ };
139
+ Randex.email = function (p1, p2, p3) {
140
+ var prefixLength = set_1.RandexSetUtil.defaultEmailPrefixLength;
141
+ var hightDomainLength = set_1.RandexSetUtil.defaultHightDomainEmailLength;
142
+ var lowDomainLength = set_1.RandexSetUtil.defaultLowDomainEmailLength;
143
+ var domain = "";
144
+ if (type_1.RandexTypeParser.isLength(p1)) {
145
+ prefixLength = p1;
146
+ if (type_1.RandexTypeParser.isLength(p2)) {
147
+ lowDomainLength = p2;
148
+ }
149
+ if (type_1.RandexTypeParser.isLength(p3)) {
150
+ hightDomainLength = p3;
151
+ }
152
+ }
153
+ else if (typeof p1 === "string") {
154
+ domain = p1;
155
+ }
156
+ else if (typeof p1 === "object") {
157
+ if (p1.prefixLength) {
158
+ prefixLength = p1.prefixLength;
159
+ }
160
+ if (p1.hightDomainLength) {
161
+ hightDomainLength = p1.hightDomainLength;
162
+ }
163
+ if (p1.lowDomainLength) {
164
+ lowDomainLength = p1.lowDomainLength;
165
+ }
166
+ if (p1.domain) {
167
+ domain = p1.domain;
168
+ }
169
+ }
170
+ if (!domain) {
171
+ domain = Randex.random([["english", "l"], lowDomainLength]) + "." + Randex.random([["english", "l"], hightDomainLength]);
172
+ }
173
+ return Randex.random([[["english", "l"], "number"], prefixLength]) + "@" + domain;
174
+ };
175
+ Randex.fileName = function (p1, p2) {
176
+ var fileNameLength = set_1.RandexSetUtil.defaultFileNameLength;
177
+ var extensionLength = set_1.RandexSetUtil.defaultExtensionLength;
178
+ var extension = "";
179
+ if (type_1.RandexTypeParser.isLength(p1)) {
180
+ fileNameLength = p1;
181
+ if (type_1.RandexTypeParser.isLength(p2)) {
182
+ extensionLength = p2;
183
+ }
184
+ else if (typeof p2 === "string") {
185
+ extension = p2;
186
+ }
187
+ }
188
+ else if (typeof p1 === "string") {
189
+ extension = p1;
190
+ }
191
+ else if (typeof p1 === "object") {
192
+ if (p1.fileNameLength) {
193
+ fileNameLength = p1.fileNameLength;
194
+ }
195
+ if (p1.extensionLength) {
196
+ extensionLength = p1.extensionLength;
197
+ }
198
+ if (p1.extension) {
199
+ extension = p1.extension;
200
+ }
201
+ }
202
+ fileNameLength = set_1.RandexSetUtil.getLength(1, fileNameLength, fileNameLength);
203
+ if (!extension) {
204
+ extension = Randex.random([["english", "l"], extensionLength]);
205
+ }
206
+ return (Randex.random([["english", "number"], set_1.RandexSetUtil.fileNameExtraChars, fileNameLength]) +
207
+ Randex.random(["english", "number"]) +
208
+ "." +
209
+ (extension ? extension.replace(/^\./, "") : Randex.random([["english", "l"], extensionLength])));
210
+ };
211
+ Randex.fullName = function (p1, p2, p3) {
212
+ var firstLength = 0;
213
+ var secondLength = 0;
214
+ var alphabet = "english";
215
+ if (type_1.RandexTypeParser.isLength(p1)) {
216
+ firstLength = secondLength = p1;
217
+ }
218
+ else if (type_1.RandexTypeParser.inAlphabet(p1)) {
219
+ alphabet = p1;
220
+ if (type_1.RandexTypeParser.isLength(p2)) {
221
+ firstLength = secondLength = p2;
222
+ }
223
+ if (type_1.RandexTypeParser.isLength(p3)) {
224
+ secondLength = p3;
225
+ }
226
+ }
227
+ else if (typeof p1 === "object") {
228
+ if (p1.alphabet) {
229
+ alphabet = p1.alphabet;
230
+ }
231
+ if (p1.firstLength) {
232
+ firstLength = p1.firstLength;
233
+ }
234
+ if (p1.secondLength) {
235
+ secondLength = p1.secondLength;
236
+ }
237
+ }
238
+ return Randex.singleName({ length: firstLength, alphabet: alphabet }) + " " + Randex.singleName({ length: secondLength, alphabet: alphabet });
239
+ };
240
+ Randex.singleName = function (p1, p2) {
241
+ var length = 0;
242
+ var alphabet = "english";
243
+ if (type_1.RandexTypeParser.isLength(p1)) {
244
+ length = p1;
245
+ }
246
+ else if (type_1.RandexTypeParser.inAlphabet(p1)) {
247
+ alphabet = p1;
248
+ if (type_1.RandexTypeParser.isLength(p2)) {
249
+ length = p2;
250
+ }
251
+ }
252
+ else if (typeof p1 === "object") {
253
+ if (p1.alphabet) {
254
+ alphabet = p1.alphabet;
255
+ }
256
+ if (p1.length) {
257
+ length = p1.length;
258
+ }
259
+ }
260
+ var currentLength = set_1.RandexSetUtil.getLength(1, length, [1, 9]);
261
+ return Randex.random([alphabet, "u"], [[alphabet, "l"], currentLength]);
262
+ };
263
+ Randex.numberArray = function (length, count) {
264
+ var min = 0;
265
+ var max = 0;
266
+ var result = [];
267
+ if (typeof length === "number") {
268
+ max = length;
269
+ }
270
+ else {
271
+ min = length[0];
272
+ max = length[1];
273
+ }
274
+ var maxCount = max - min + 1;
275
+ var numberArray = [];
276
+ for (var i = min; i <= max; i++) {
277
+ numberArray.push(i);
278
+ }
279
+ for (var i = 0; i < count && i < maxCount; i++) {
280
+ var arrayCount = numberArray.length - 1;
281
+ var index = Randex.number(arrayCount);
282
+ var value = numberArray[index];
283
+ result.push(value);
284
+ numberArray.splice(index, 1);
285
+ }
286
+ return result;
287
+ };
288
+ // number
289
+ Randex.getNumberBase = function (decimals) {
290
+ return decimals === 1 ? 10 : Math.pow(10, decimals);
291
+ };
292
+ Randex.getNumberValue = function (value, decimals) {
293
+ var result = value;
294
+ if (typeof decimals === "number") {
295
+ result = result * Randex.getNumberBase(decimals);
296
+ }
297
+ return result;
298
+ };
299
+ Randex.innerRandomNumber = function (from, to, decimals) {
300
+ var fromV = Randex.getNumberValue(from, decimals);
301
+ var toV = Randex.getNumberValue(to, decimals);
302
+ var result = set_1.RandexSetUtil.randomNumber(toV - fromV + 1) + fromV;
303
+ if (typeof decimals === "number") {
304
+ result = result / Randex.getNumberBase(decimals);
305
+ }
306
+ return result;
307
+ };
308
+ Randex.number = function (p1, p2, p3) {
309
+ if (typeof p1 === "number" && typeof p2 === "number") {
310
+ return Randex.innerRandomNumber(p1, p2, p3 === null || p3 === void 0 ? void 0 : p3.decimals);
311
+ }
312
+ else {
313
+ var decimals = p2 === null || p2 === void 0 ? void 0 : p2.decimals;
314
+ if (typeof p1 === "number") {
315
+ return Randex.innerRandomNumber(0, p1, decimals);
316
+ }
317
+ else {
318
+ var min = p1[0], max = p1[1];
319
+ return Randex.innerRandomNumber(min, max, decimals);
320
+ }
321
+ }
322
+ };
323
+ Randex.username = function (options) {
324
+ var length = type_1.RandexTypeParser.isLength(options) ? options : options === null || options === void 0 ? void 0 : options.length;
325
+ var currentLength = set_1.RandexSetUtil.getLength(1, length, [6, 10]);
326
+ return Randex.random(["english", "l"], [[["english", "l"], "number"], currentLength]);
327
+ };
328
+ return Randex;
329
+ }());
330
+ exports.Randex = Randex;
@@ -1,6 +1,3 @@
1
- import { RandexLength } from "../interfaces";
2
1
  export interface RandomNumberOptions {
3
2
  decimals?: number;
4
3
  }
5
- export declare function randomNumber(length: RandexLength, options?: RandomNumberOptions): number;
6
- export declare function randomNumber(from: number, to: number, options?: RandomNumberOptions): number;
@@ -1,39 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.randomNumber = void 0;
4
- var set_1 = require("../basic/set");
5
- function getBase(decimals) {
6
- return decimals === 1 ? 10 : Math.pow(10, decimals);
7
- }
8
- function getValue(value, decimals) {
9
- var result = value;
10
- if (typeof decimals === "number") {
11
- result = result * getBase(decimals);
12
- }
13
- return result;
14
- }
15
- function innerRandomNumber(from, to, decimals) {
16
- var fromV = getValue(from, decimals);
17
- var toV = getValue(to, decimals);
18
- var result = set_1.RandexSetUtil.randomNumber(toV - fromV + 1) + fromV;
19
- if (typeof decimals === "number") {
20
- result = result / getBase(decimals);
21
- }
22
- return result;
23
- }
24
- function randomNumber(p1, p2, p3) {
25
- if (typeof p1 === "number" && typeof p2 === "number") {
26
- return innerRandomNumber(p1, p2, p3 === null || p3 === void 0 ? void 0 : p3.decimals);
27
- }
28
- else {
29
- var decimals = p2 === null || p2 === void 0 ? void 0 : p2.decimals;
30
- if (typeof p1 === "number") {
31
- return innerRandomNumber(0, p1, decimals);
32
- }
33
- else {
34
- var min = p1[0], max = p1[1];
35
- return innerRandomNumber(min, max, decimals);
36
- }
37
- }
38
- }
39
- exports.randomNumber = randomNumber;
@@ -0,0 +1,5 @@
1
+ import { RandexLength } from "../interfaces";
2
+ export interface RandexRangeOptions {
3
+ range: string;
4
+ length: RandexLength;
5
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ import { RandexAlphabet, RandexLength } from "../interfaces";
2
+ export interface RandexSingleNameOptions {
3
+ alphabet?: RandexAlphabet;
4
+ length?: RandexLength;
5
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -2,4 +2,3 @@ import { RandexLength } from "../interfaces";
2
2
  export interface RandexUsernameOptions {
3
3
  length?: RandexLength;
4
4
  }
5
- export declare function randomUsername(options?: RandexUsernameOptions | RandexLength): string;
@@ -1,12 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.randomUsername = void 0;
4
- var basic_1 = require("../basic");
5
- var set_1 = require("../basic/set");
6
- var type_1 = require("../basic/type");
7
- function randomUsername(options) {
8
- var length = type_1.RandexTypeParser.isLength(options) ? options : options === null || options === void 0 ? void 0 : options.length;
9
- var currentLength = set_1.RandexSetUtil.getLength(1, length, [6, 10]);
10
- return (0, basic_1.random)(["english", "l"], [[["english", "l"], "number"], currentLength]);
11
- }
12
- exports.randomUsername = randomUsername;
package/lib/index.d.ts CHANGED
@@ -1,2 +1,4 @@
1
- export * from "./basic";
1
+ import { Randex } from "./custom";
2
+ export * from "./interfaces";
2
3
  export * from "./custom";
4
+ export default Randex;
package/lib/index.js CHANGED
@@ -14,5 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./basic"), exports);
17
+ var custom_1 = require("./custom");
18
+ __exportStar(require("./interfaces"), exports);
18
19
  __exportStar(require("./custom"), exports);
20
+ // eslint-disable-next-line import/no-default-export
21
+ exports.default = custom_1.Randex;
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var array_item_1 = require("../custom/array-item");
3
+ var custom_1 = require("../custom");
4
4
  var test_util_1 = require("./test-util");
5
5
  describe("randomArrayItem", function () {
6
6
  it("param: number", function () {
7
7
  var array = [1, 2, 3, 4, 5, 6];
8
8
  var resultArray = {};
9
9
  test_util_1.TestUtil.loop(function () {
10
- var value = (0, array_item_1.randomArrayItem)(array);
10
+ var value = custom_1.Randex.arrayItem(array);
11
11
  resultArray[value] = (resultArray[value] || 0) + 1;
12
12
  });
13
13
  for (var _i = 0, array_1 = array; _i < array_1.length; _i++) {
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var array_1 = require("../custom/array");
3
+ var custom_1 = require("../custom");
4
4
  function testUniqueArray(array, count) {
5
- var value = (0, array_1.randomArray)(array, count);
5
+ var value = custom_1.Randex.array(array, count);
6
6
  var uniqueResult = [];
7
7
  var _loop_1 = function (i) {
8
8
  var uniqueValue = value[i];