randex 0.24.0 → 0.26.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/basic/set.d.ts +1 -0
  2. package/lib/basic/set.js +7 -0
  3. package/lib/custom/bool.d.ts +1 -0
  4. package/lib/custom/bool.js +7 -0
  5. package/lib/custom/email.d.ts +4 -13
  6. package/lib/custom/email.js +41 -0
  7. package/lib/custom/filenameX.d.ts +5 -0
  8. package/lib/custom/filenameX.js +43 -0
  9. package/lib/custom/fullnameX.d.ts +6 -0
  10. package/lib/custom/fullnameX.js +35 -0
  11. package/lib/custom/index.d.ts +27 -44
  12. package/lib/custom/index.js +21 -289
  13. package/lib/custom/number.d.ts +3 -3
  14. package/lib/custom/number.js +37 -0
  15. package/lib/custom/random.d.ts +2 -5
  16. package/lib/custom/random.js +81 -0
  17. package/lib/custom/singleName.d.ts +5 -0
  18. package/lib/custom/singleName.js +30 -0
  19. package/lib/custom/username.d.ts +2 -4
  20. package/lib/custom/username.js +10 -0
  21. package/lib/custom/word.d.ts +11 -5
  22. package/lib/custom/word.js +34 -0
  23. package/lib/interfaces/base.d.ts +21 -0
  24. package/lib/interfaces/email.d.ts +13 -0
  25. package/lib/{custom → interfaces}/filename.d.ts +1 -1
  26. package/lib/interfaces/filename.js +2 -0
  27. package/lib/{custom → interfaces}/fullname.d.ts +1 -1
  28. package/lib/interfaces/fullname.js +2 -0
  29. package/lib/interfaces/index.d.ts +8 -21
  30. package/lib/interfaces/index.js +22 -0
  31. package/lib/interfaces/number.d.ts +3 -0
  32. package/lib/interfaces/number.js +2 -0
  33. package/lib/interfaces/random.d.ts +5 -0
  34. package/lib/interfaces/random.js +2 -0
  35. package/lib/interfaces/username.d.ts +4 -0
  36. package/lib/interfaces/username.js +2 -0
  37. package/lib/interfaces/word.d.ts +5 -0
  38. package/lib/interfaces/word.js +2 -0
  39. package/lib/test/word.test.js +8 -0
  40. package/package.json +1 -1
  41. package/todo +2 -4
  42. /package/lib/{custom/filename.js → interfaces/base.js} +0 -0
  43. /package/lib/{custom/fullname.js → interfaces/email.js} +0 -0
@@ -12,4 +12,5 @@ export declare class RandexSetUtil {
12
12
  static toRange(set: RandexSet): string;
13
13
  static getLength(reservedChars: number, length: RandexLength | undefined, defaultLength: RandexLength): RandexLength;
14
14
  static randomNumber(length: number): number;
15
+ static many<TItem>(count: number, callback: () => TItem): TItem[];
15
16
  }
package/lib/basic/set.js CHANGED
@@ -97,6 +97,13 @@ var RandexSetUtil = /** @class */ (function () {
97
97
  RandexSetUtil.randomNumber = function (length) {
98
98
  return Math.floor(Math.random() * length);
99
99
  };
100
+ RandexSetUtil.many = function (count, callback) {
101
+ var result = [];
102
+ for (var i = 0; i < count; i++) {
103
+ result.push(callback());
104
+ }
105
+ return result;
106
+ };
100
107
  RandexSetUtil.defaultFileNameLength = [3, 10];
101
108
  RandexSetUtil.defaultExtensionLength = [2, 5];
102
109
  RandexSetUtil.fileNameExtraChars = ""; //"-_.";
@@ -0,0 +1 @@
1
+ export declare function randexBool(): boolean;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.randexBool = void 0;
4
+ function randexBool() {
5
+ return Math.random() < 0.5;
6
+ }
7
+ exports.randexBool = randexBool;
@@ -1,13 +1,4 @@
1
- import { RandexLength } from "../interfaces";
2
- interface BasicEmailOptions {
3
- prefixLength?: RandexLength;
4
- }
5
- interface DomainLengthEmailOptions {
6
- hightDomainLength?: RandexLength;
7
- lowDomainLength?: RandexLength;
8
- }
9
- interface DomainEmailOptions {
10
- domain?: string;
11
- }
12
- export type RandexEmailOptions = BasicEmailOptions & (DomainLengthEmailOptions | DomainEmailOptions);
13
- export {};
1
+ import { RandexEmailOptions, RandexLength } from "../interfaces";
2
+ export declare function randexEmail(options?: RandexEmailOptions): string;
3
+ export declare function randexEmail(prefixLength: RandexLength, lowDomainLength?: RandexLength, hightDomainLength?: RandexLength): string;
4
+ export declare function randexEmail(domain: string): string;
@@ -1,2 +1,43 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.randexEmail = void 0;
4
+ var set_1 = require("../basic/set");
5
+ var type_1 = require("../basic/type");
6
+ var random_1 = require("./random");
7
+ function randexEmail(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, random_1.randexRandom)([["english", "l"], lowDomainLength]) + "." + (0, random_1.randexRandom)([["english", "l"], hightDomainLength]);
40
+ }
41
+ return (0, random_1.randexRandom)([[["english", "l"], "number"], prefixLength]) + "@" + domain;
42
+ }
43
+ exports.randexEmail = randexEmail;
@@ -0,0 +1,5 @@
1
+ import { RandexFileNameOptions, RandexLength } from "../interfaces";
2
+ export declare function randexFileName(options?: RandexFileNameOptions): string;
3
+ export declare function randexFileName(fileNameLength: RandexLength, extensionLength?: RandexLength): string;
4
+ export declare function randexFileName(fileNameLength: RandexLength, extension: string): string;
5
+ export declare function randexFileName(extension: string): string;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.randexFileName = void 0;
4
+ var set_1 = require("../basic/set");
5
+ var type_1 = require("../basic/type");
6
+ var random_1 = require("./random");
7
+ function randexFileName(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, random_1.randexRandom)([["english", "l"], extensionLength]);
37
+ }
38
+ return ((0, random_1.randexRandom)([["english", "number"], set_1.RandexSetUtil.fileNameExtraChars, fileNameLength]) +
39
+ (0, random_1.randexRandom)(["english", "number"]) +
40
+ "." +
41
+ (extension ? extension.replace(/^\./, "") : (0, random_1.randexRandom)([["english", "l"], extensionLength])));
42
+ }
43
+ exports.randexFileName = randexFileName;
@@ -0,0 +1,6 @@
1
+ import { RandexAlphabet, RandexFullNameOptions, RandexLength } from "../interfaces";
2
+ export declare function randexFullName(options?: RandexFullNameOptions): string;
3
+ export declare function randexFullName(length: RandexLength): string;
4
+ export declare function randexFullName(alphabet?: RandexAlphabet): string;
5
+ export declare function randexFullName(alphabet: RandexAlphabet, length: RandexLength): string;
6
+ export declare function randexFullName(alphabet: RandexAlphabet, firstLength: RandexLength, secondLength: RandexLength): string;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.randexFullName = void 0;
4
+ var type_1 = require("../basic/type");
5
+ var singleName_1 = require("./singleName");
6
+ function randexFullName(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, singleName_1.randexSingleName)({ length: firstLength, alphabet: alphabet }) + " " + (0, singleName_1.randexSingleName)({ length: secondLength, alphabet: alphabet });
34
+ }
35
+ exports.randexFullName = randexFullName;
@@ -1,50 +1,33 @@
1
- import { RandexAlphabet, RandexContentOptions, RandexLength } from "../interfaces";
2
- import { RandexEmailOptions } from "./email";
3
- import { RandexFileNameOptions } from "./filename";
4
- import { RandexWordOptions } from "./word";
5
- import { RandomNumberOptions } from "./number";
6
- import { RandexUsernameOptions } from "./username";
7
- import { RandexFullNameOptions } from "./fullname";
8
- export * from "./email";
9
- export * from "./filename";
10
- export * from "./word";
11
- export * from "./username";
12
- export * from "./fullname";
13
- export * from "./number";
1
+ import { RandexLength } from "../interfaces";
2
+ import { randexBool } from "./bool";
3
+ import { randexEmail } from "./email";
4
+ import { randexFileName } from "./filenameX";
5
+ import { randexFullName } from "./fullnameX";
6
+ import { randexNumber } from "./number";
7
+ import { randexRandom } from "./random";
8
+ import { randexSingleName } from "./singleName";
9
+ import { randexUsername } from "./username";
10
+ import { randexWord } from "./word";
14
11
  export declare class Randex {
15
- private static randomString;
16
- private static toContent;
17
- private static toRangeOptions;
18
- static random(...options: RandexContentOptions[]): string;
12
+ static random: typeof randexRandom;
19
13
  static arrayItem<T>(array: T[]): T;
20
14
  static arrayItem<T>(array: T[], defaultValue: T): T;
21
15
  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?: RandexWordOptions): any;
36
- static singleName(length: RandexLength): any;
37
- static singleName(alphabet?: RandexAlphabet): any;
38
- static singleName(alphabet: RandexAlphabet, length: RandexLength): any;
39
- static word(options?: RandexWordOptions): any;
40
- static word(length: RandexLength): any;
41
- static word(alphabet?: RandexAlphabet): any;
42
- static word(alphabet: RandexAlphabet, length: RandexLength): any;
16
+ static bool: typeof randexBool;
17
+ static email: typeof randexEmail;
18
+ static fileName: typeof randexFileName;
19
+ static fullName: typeof randexFullName;
20
+ static singleName: typeof randexSingleName;
21
+ static word: typeof randexWord;
43
22
  static numberArray(length: RandexLength, count: number): number[];
44
- private static getNumberBase;
45
- private static getNumberValue;
46
- private static innerRandomNumber;
47
- static number(length: RandexLength, options?: RandomNumberOptions): number;
48
- static number(from: number, to: number, options?: RandomNumberOptions): number;
49
- static username(options?: RandexUsernameOptions | RandexLength): string;
23
+ static number: typeof randexNumber;
24
+ static username: typeof randexUsername;
25
+ static many(count: number): {
26
+ word: {
27
+ (options?: import("../interfaces").RandexWordOptions | undefined): string[];
28
+ (length: RandexLength): string[];
29
+ (alphabet?: import("../interfaces").RandexAlphabet | undefined): string[];
30
+ (alphabet: import("../interfaces").RandexAlphabet, length: RandexLength): string[];
31
+ };
32
+ };
50
33
  }
@@ -1,109 +1,18 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
2
  Object.defineProperty(exports, "__esModule", { value: true });
17
3
  exports.Randex = void 0;
18
- var set_1 = require("../basic/set");
19
- var type_1 = require("../basic/type");
20
- __exportStar(require("./email"), exports);
21
- __exportStar(require("./filename"), exports);
22
- __exportStar(require("./word"), exports);
23
- __exportStar(require("./username"), exports);
24
- __exportStar(require("./fullname"), exports);
25
- __exportStar(require("./number"), exports);
4
+ var bool_1 = require("./bool");
5
+ var email_1 = require("./email");
6
+ var filenameX_1 = require("./filenameX");
7
+ var fullnameX_1 = require("./fullnameX");
8
+ var number_1 = require("./number");
9
+ var random_1 = require("./random");
10
+ var singleName_1 = require("./singleName");
11
+ var username_1 = require("./username");
12
+ var word_1 = require("./word");
26
13
  var Randex = /** @class */ (function () {
27
14
  function Randex() {
28
15
  }
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
16
  Randex.arrayItem = function (array, defaultValue) {
108
17
  if (array === null || array === void 0 ? void 0 : array.length) {
109
18
  var arrayCount = array.length - 1;
@@ -133,155 +42,6 @@ var Randex = /** @class */ (function () {
133
42
  }
134
43
  return result;
135
44
  };
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.word = function (p1, p2) {
264
- var length = [2, 10];
265
- var alphabet = "english";
266
- if (type_1.RandexTypeParser.isLength(p1)) {
267
- length = p1;
268
- }
269
- else if (type_1.RandexTypeParser.inAlphabet(p1)) {
270
- alphabet = p1;
271
- if (type_1.RandexTypeParser.isLength(p2)) {
272
- length = p2;
273
- }
274
- }
275
- else if (typeof p1 === "object") {
276
- if (p1.alphabet) {
277
- alphabet = p1.alphabet;
278
- }
279
- if (p1.length) {
280
- length = p1.length;
281
- }
282
- }
283
- return Randex.random([[alphabet, "l"], length]);
284
- };
285
45
  Randex.numberArray = function (length, count) {
286
46
  var min = 0;
287
47
  var max = 0;
@@ -307,46 +67,18 @@ var Randex = /** @class */ (function () {
307
67
  }
308
68
  return result;
309
69
  };
310
- // number
311
- Randex.getNumberBase = function (decimals) {
312
- return decimals === 1 ? 10 : Math.pow(10, decimals);
313
- };
314
- Randex.getNumberValue = function (value, decimals) {
315
- var result = value;
316
- if (typeof decimals === "number") {
317
- result = result * Randex.getNumberBase(decimals);
318
- }
319
- return result;
320
- };
321
- Randex.innerRandomNumber = function (from, to, decimals) {
322
- var fromV = Randex.getNumberValue(from, decimals);
323
- var toV = Randex.getNumberValue(to, decimals);
324
- var result = set_1.RandexSetUtil.randomNumber(toV - fromV + 1) + fromV;
325
- if (typeof decimals === "number") {
326
- result = result / Randex.getNumberBase(decimals);
327
- }
328
- return result;
329
- };
330
- Randex.number = function (p1, p2, p3) {
331
- if (typeof p1 === "number" && typeof p2 === "number") {
332
- return Randex.innerRandomNumber(p1, p2, p3 === null || p3 === void 0 ? void 0 : p3.decimals);
333
- }
334
- else {
335
- var decimals = p2 === null || p2 === void 0 ? void 0 : p2.decimals;
336
- if (typeof p1 === "number") {
337
- return Randex.innerRandomNumber(0, p1, decimals);
338
- }
339
- else {
340
- var min = p1[0], max = p1[1];
341
- return Randex.innerRandomNumber(min, max, decimals);
342
- }
343
- }
344
- };
345
- Randex.username = function (options) {
346
- var length = type_1.RandexTypeParser.isLength(options) ? options : options === null || options === void 0 ? void 0 : options.length;
347
- var currentLength = set_1.RandexSetUtil.getLength(1, length, [6, 10]);
348
- return Randex.random(["english", "l"], [[["english", "l"], "number"], currentLength]);
349
- };
70
+ Randex.many = function (count) {
71
+ return { word: (0, word_1.randexManyWord)(count) };
72
+ };
73
+ Randex.random = random_1.randexRandom;
74
+ Randex.bool = bool_1.randexBool;
75
+ Randex.email = email_1.randexEmail;
76
+ Randex.fileName = filenameX_1.randexFileName;
77
+ Randex.fullName = fullnameX_1.randexFullName;
78
+ Randex.singleName = singleName_1.randexSingleName;
79
+ Randex.word = word_1.randexWord;
80
+ Randex.number = number_1.randexNumber;
81
+ Randex.username = username_1.randexUsername;
350
82
  return Randex;
351
83
  }());
352
84
  exports.Randex = Randex;
@@ -1,3 +1,3 @@
1
- export interface RandomNumberOptions {
2
- decimals?: number;
3
- }
1
+ import { RandexLength, RandomNumberOptions } from "../interfaces";
2
+ export declare function randexNumber(length: RandexLength, options?: RandomNumberOptions): number;
3
+ export declare function randexNumber(from: number, to: number, options?: RandomNumberOptions): number;
@@ -1,2 +1,39 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.randexNumber = void 0;
4
+ var set_1 = require("../basic/set");
5
+ function getNumberBase(decimals) {
6
+ return decimals === 1 ? 10 : Math.pow(10, decimals);
7
+ }
8
+ function getNumberValue(value, decimals) {
9
+ var result = value;
10
+ if (typeof decimals === "number") {
11
+ result = result * getNumberBase(decimals);
12
+ }
13
+ return result;
14
+ }
15
+ function innerRandomNumber(from, to, decimals) {
16
+ var fromV = getNumberValue(from, decimals);
17
+ var toV = getNumberValue(to, decimals);
18
+ var result = set_1.RandexSetUtil.randomNumber(toV - fromV + 1) + fromV;
19
+ if (typeof decimals === "number") {
20
+ result = result / getNumberBase(decimals);
21
+ }
22
+ return result;
23
+ }
24
+ function randexNumber(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.randexNumber = randexNumber;
@@ -1,5 +1,2 @@
1
- import { RandexLength } from "../interfaces";
2
- export interface RandexRangeOptions {
3
- range: string;
4
- length: RandexLength;
5
- }
1
+ import { RandexContentOptions } from "../interfaces";
2
+ export declare function randexRandom(...options: RandexContentOptions[]): string;
@@ -1,2 +1,83 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.randexRandom = void 0;
4
+ var set_1 = require("../basic/set");
5
+ var type_1 = require("../basic/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 randexRandom() {
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.randexRandom = randexRandom;
@@ -0,0 +1,5 @@
1
+ import { RandexAlphabet, RandexLength, RandexWordOptions } from "../interfaces";
2
+ export declare function randexSingleName(options?: RandexWordOptions): string;
3
+ export declare function randexSingleName(length: RandexLength): string;
4
+ export declare function randexSingleName(alphabet?: RandexAlphabet): string;
5
+ export declare function randexSingleName(alphabet: RandexAlphabet, length: RandexLength): string;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.randexSingleName = void 0;
4
+ var set_1 = require("../basic/set");
5
+ var type_1 = require("../basic/type");
6
+ var random_1 = require("./random");
7
+ function randexSingleName(p1, p2) {
8
+ var length = 0;
9
+ var alphabet = "english";
10
+ if (type_1.RandexTypeParser.isLength(p1)) {
11
+ length = p1;
12
+ }
13
+ else if (type_1.RandexTypeParser.inAlphabet(p1)) {
14
+ alphabet = p1;
15
+ if (type_1.RandexTypeParser.isLength(p2)) {
16
+ length = p2;
17
+ }
18
+ }
19
+ else if (typeof p1 === "object") {
20
+ if (p1.alphabet) {
21
+ alphabet = p1.alphabet;
22
+ }
23
+ if (p1.length) {
24
+ length = p1.length;
25
+ }
26
+ }
27
+ var currentLength = set_1.RandexSetUtil.getLength(1, length, [1, 9]);
28
+ return (0, random_1.randexRandom)([alphabet, "u"], [[alphabet, "l"], currentLength]);
29
+ }
30
+ exports.randexSingleName = randexSingleName;
@@ -1,4 +1,2 @@
1
- import { RandexLength } from "../interfaces";
2
- export interface RandexUsernameOptions {
3
- length?: RandexLength;
4
- }
1
+ import { RandexLength, RandexUsernameOptions } from "../interfaces";
2
+ export declare function randexUsername(options?: RandexUsernameOptions | RandexLength): string;
@@ -1,2 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.randexUsername = void 0;
4
+ var set_1 = require("../basic/set");
5
+ var type_1 = require("../basic/type");
6
+ var random_1 = require("./random");
7
+ function randexUsername(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, random_1.randexRandom)(["english", "l"], [[["english", "l"], "number"], currentLength]);
11
+ }
12
+ exports.randexUsername = randexUsername;
@@ -1,5 +1,11 @@
1
- import { RandexAlphabet, RandexLength } from "../interfaces";
2
- export interface RandexWordOptions {
3
- alphabet?: RandexAlphabet;
4
- length?: RandexLength;
5
- }
1
+ import { RandexAlphabet, RandexLength, RandexWordOptions } from "../interfaces";
2
+ export declare function randexWord(options?: RandexWordOptions): string;
3
+ export declare function randexWord(length: RandexLength): string;
4
+ export declare function randexWord(alphabet?: RandexAlphabet): string;
5
+ export declare function randexWord(alphabet: RandexAlphabet, length: RandexLength): string;
6
+ export declare function randexManyWord(count: number): {
7
+ (options?: RandexWordOptions): string[];
8
+ (length: RandexLength): string[];
9
+ (alphabet?: RandexAlphabet): string[];
10
+ (alphabet: RandexAlphabet, length: RandexLength): string[];
11
+ };
@@ -1,2 +1,36 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.randexManyWord = exports.randexWord = void 0;
4
+ var set_1 = require("../basic/set");
5
+ var type_1 = require("../basic/type");
6
+ var random_1 = require("./random");
7
+ function randexWord(p1, p2) {
8
+ var length = [2, 10];
9
+ var alphabet = "english";
10
+ if (type_1.RandexTypeParser.isLength(p1)) {
11
+ length = p1;
12
+ }
13
+ else if (type_1.RandexTypeParser.inAlphabet(p1)) {
14
+ alphabet = p1;
15
+ if (type_1.RandexTypeParser.isLength(p2)) {
16
+ length = p2;
17
+ }
18
+ }
19
+ else if (typeof p1 === "object") {
20
+ if (p1.alphabet) {
21
+ alphabet = p1.alphabet;
22
+ }
23
+ if (p1.length) {
24
+ length = p1.length;
25
+ }
26
+ }
27
+ return (0, random_1.randexRandom)([[alphabet, "l"], length]);
28
+ }
29
+ exports.randexWord = randexWord;
30
+ function randexManyWord(count) {
31
+ function many(p1, p2) {
32
+ return set_1.RandexSetUtil.many(count, function () { return randexWord(p1, p2); });
33
+ }
34
+ return many;
35
+ }
36
+ exports.randexManyWord = randexManyWord;
@@ -0,0 +1,21 @@
1
+ export type RandexCase = "default" | "lower" | "upper" | "l" | "u";
2
+ export type RandexAlphabet = "english" | "french" | "spanish" | "russian";
3
+ export type RandexSingleSet = RandexAlphabet | "hex" | "symbol" | "number" | "binary";
4
+ export type RandexAlphabetCase = [RandexAlphabet, RandexCase];
5
+ export type RandexItemSet = RandexSingleSet | RandexAlphabetCase;
6
+ export type RandexSet = RandexItemSet | RandexItemSet[];
7
+ export type RandexLength = number | [number, number];
8
+ interface RandexItemBasicOptions {
9
+ set?: RandexSet;
10
+ range?: string;
11
+ length?: RandexLength;
12
+ }
13
+ export interface RandexContentSetOptions extends Omit<RandexItemBasicOptions, "set"> {
14
+ set: RandexSet;
15
+ }
16
+ export interface RandexContentRangeOptions extends Omit<RandexItemBasicOptions, "range"> {
17
+ range: string;
18
+ }
19
+ export type RandexContentArrayOptions = [RandexSet, string | RandexLength] | [RandexSet, string, RandexLength];
20
+ export type RandexContentOptions = RandexContentSetOptions | RandexContentRangeOptions | RandexContentArrayOptions | RandexSet;
21
+ export {};
@@ -0,0 +1,13 @@
1
+ import { RandexLength } from "./base";
2
+ interface BasicEmailOptions {
3
+ prefixLength?: RandexLength;
4
+ }
5
+ interface DomainLengthEmailOptions {
6
+ hightDomainLength?: RandexLength;
7
+ lowDomainLength?: RandexLength;
8
+ }
9
+ interface DomainEmailOptions {
10
+ domain?: string;
11
+ }
12
+ export type RandexEmailOptions = BasicEmailOptions & (DomainLengthEmailOptions | DomainEmailOptions);
13
+ export {};
@@ -1,4 +1,4 @@
1
- import { RandexLength } from "../interfaces";
1
+ import { RandexLength } from "./base";
2
2
  interface BasicFileNameOptions {
3
3
  fileNameLength?: RandexLength;
4
4
  }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,4 +1,4 @@
1
- import { RandexAlphabet, RandexLength } from "../interfaces";
1
+ import { RandexAlphabet, RandexLength } from "./base";
2
2
  export interface RandexFullNameOptions {
3
3
  alphabet?: RandexAlphabet;
4
4
  firstLength?: RandexLength;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,21 +1,8 @@
1
- export type RandexCase = "default" | "lower" | "upper" | "l" | "u";
2
- export type RandexAlphabet = "english" | "french" | "spanish" | "russian";
3
- export type RandexSingleSet = RandexAlphabet | "hex" | "symbol" | "number" | "binary";
4
- export type RandexAlphabetCase = [RandexAlphabet, RandexCase];
5
- export type RandexItemSet = RandexSingleSet | RandexAlphabetCase;
6
- export type RandexSet = RandexItemSet | RandexItemSet[];
7
- export type RandexLength = number | [number, number];
8
- interface RandexItemBasicOptions {
9
- set?: RandexSet;
10
- range?: string;
11
- length?: RandexLength;
12
- }
13
- export interface RandexContentSetOptions extends Omit<RandexItemBasicOptions, "set"> {
14
- set: RandexSet;
15
- }
16
- export interface RandexContentRangeOptions extends Omit<RandexItemBasicOptions, "range"> {
17
- range: string;
18
- }
19
- export type RandexContentArrayOptions = [RandexSet, string | RandexLength] | [RandexSet, string, RandexLength];
20
- export type RandexContentOptions = RandexContentSetOptions | RandexContentRangeOptions | RandexContentArrayOptions | RandexSet;
21
- export {};
1
+ export * from "./base";
2
+ export * from "./email";
3
+ export * from "./filename";
4
+ export * from "./fullname";
5
+ export * from "./number";
6
+ export * from "./random";
7
+ export * from "./username";
8
+ export * from "./word";
@@ -1,2 +1,24 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./base"), exports);
18
+ __exportStar(require("./email"), exports);
19
+ __exportStar(require("./filename"), exports);
20
+ __exportStar(require("./fullname"), exports);
21
+ __exportStar(require("./number"), exports);
22
+ __exportStar(require("./random"), exports);
23
+ __exportStar(require("./username"), exports);
24
+ __exportStar(require("./word"), exports);
@@ -0,0 +1,3 @@
1
+ export interface RandomNumberOptions {
2
+ decimals?: number;
3
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ import { RandexLength } from "./base";
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,4 @@
1
+ import { RandexLength } from "./base";
2
+ export interface RandexUsernameOptions {
3
+ length?: RandexLength;
4
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ import { RandexAlphabet, RandexLength } from "./base";
2
+ export interface RandexWordOptions {
3
+ alphabet?: RandexAlphabet;
4
+ length?: RandexLength;
5
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -9,4 +9,12 @@ describe("word", function () {
9
9
  expect(test_util_1.TestUtil.isWordValid(w, [2, 10])).toBeTruthy();
10
10
  });
11
11
  });
12
+ it("many", function () {
13
+ var count = 5;
14
+ var ws = custom_1.Randex.many(count).word();
15
+ expect(ws.length).toBe(count);
16
+ for (var i = 0; i < count; i++) {
17
+ expect(test_util_1.TestUtil.isWordValid(ws[i], [2, 10])).toBeTruthy();
18
+ }
19
+ });
12
20
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "randex",
3
- "version": "0.24.0",
3
+ "version": "0.26.0",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
package/todo CHANGED
@@ -1,4 +1,2 @@
1
- * randomWord
2
- * randomSentence
3
-
4
- randomNumber: add decimals numbers to option
1
+ randomNumber: add decimals numbers to option
2
+ randex - add count function for word, name, ...
File without changes
File without changes