randex 0.5.0 → 0.7.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 CHANGED
@@ -23,6 +23,11 @@ Functions:
23
23
  - [randomName](#randomname)
24
24
  - [randomFullName](#randomfullname)
25
25
 
26
+ Deeps:
27
+
28
+ - [Customization](#customization)
29
+ - [Types](#types)
30
+
26
31
  ## random
27
32
 
28
33
  Basic function for construct random thing.
@@ -35,6 +40,8 @@ random({
35
40
  set: "english",
36
41
  length: 3,
37
42
  });
43
+ // or short:
44
+ random(["english", 3]);
38
45
  // EFd
39
46
 
40
47
  // 3 lower english chars
@@ -42,6 +49,8 @@ random({
42
49
  set: ["english", "lower"],
43
50
  length: 3,
44
51
  });
52
+ // or short:
53
+ random([["english", "lower"], 3]);
45
54
  // yhl
46
55
 
47
56
  // min 1 and max 3 english chars
@@ -49,6 +58,8 @@ random({
49
58
  set: "english",
50
59
  length: [1, 3],
51
60
  });
61
+ // or short:
62
+ random(["english", [1, 3]]);
52
63
  // eR
53
64
 
54
65
  // 3 number chars
@@ -56,6 +67,8 @@ random({
56
67
  set: "number",
57
68
  length: 3,
58
69
  });
70
+ // or short:
71
+ random(["number", 3]);
59
72
  // 643
60
73
 
61
74
  // 3 chars from custom range
@@ -70,6 +83,9 @@ random({
70
83
  set: ["english", "number"],
71
84
  length: 3,
72
85
  });
86
+ // or short:
87
+ random([["english", "number"], 3]);
88
+ // x4d
73
89
 
74
90
  // 4 chars: 2 english and 2 english or number
75
91
  random(
@@ -82,6 +98,8 @@ random(
82
98
  length: 2,
83
99
  }
84
100
  );
101
+ // or short:
102
+ random(["english", 2], [["english", "number"], 2]);
85
103
  // Kb3b
86
104
  ```
87
105
 
@@ -106,20 +124,6 @@ randomFileName({
106
124
  // td1TX31eOB.txt
107
125
  ```
108
126
 
109
- Equals to:
110
-
111
- ```ts
112
- random([["english", "number"], "_.", [5, 10]]) +
113
- random(["english", "number"]) +
114
- "." +
115
- (extension
116
- ? extension
117
- : random([
118
- ["english", "l"],
119
- [2, 5],
120
- ]));
121
- ```
122
-
123
127
  ## randomUsername
124
128
 
125
129
  Randoms username.
@@ -127,48 +131,39 @@ Randoms username.
127
131
  ```ts
128
132
  import { randomUsername } from "randex";
129
133
 
134
+ // default
130
135
  randomUsername();
131
-
132
136
  // icvv81d1j
133
- ```
134
137
 
135
- Equals to:
138
+ // with length 5 chars
139
+ randomUsername({ length: 5 });
140
+ // or short:
141
+ randomUsername(5);
142
+ // okmle
136
143
 
137
- ```ts
138
- random(
139
- ["english", "l"],
140
- [
141
- [["english", "l"], "number"],
142
- [5, 10],
143
- ]
144
- );
144
+ // with 2 min and 5 max chars
145
+ randomName({ length: [2, 5] });
146
+ // or short:
147
+ randomUsername([2, 5]);
148
+ // lkhs
145
149
  ```
146
150
 
151
+ Options:
152
+ | Name | Type| Description|
153
+ | ------------------------ | ---- |------------ |
154
+ |length|[RandexLength](#randexlength) | Length of chars. Default: min - 6, max - 10 chars. |
155
+
147
156
  ## randomEmail
148
157
 
149
- Randoms username.
158
+ Randoms an email.
150
159
 
151
160
  ```ts
152
161
  import { randomEmail } from "randex";
153
162
 
154
163
  randomEmail();
155
-
156
164
  // stv4ox27sevt@mqsyin.fil
157
165
  ```
158
166
 
159
- Equals to:
160
-
161
- ```ts
162
- random(["english", "l"], [[["english", "l"], "number"], 10], ["english", "l"]) +
163
- "@" +
164
- random(["english", "l"], [["english", "l"], "-", [0, 5]], ["english", "l"]) +
165
- "." +
166
- random([
167
- ["english", "l"],
168
- [2, 4],
169
- ]);
170
- ```
171
-
172
167
  ## randomName
173
168
 
174
169
  Randoms a name of the person, city, place, restaurant, ect.
@@ -176,40 +171,40 @@ Randoms a name of the person, city, place, restaurant, ect.
176
171
  ```ts
177
172
  import { randomName } from "randex";
178
173
 
179
- // default (min - 2, max - 10 chars)
174
+ // default
180
175
  randomName();
181
176
  // Ijb
182
177
 
183
- // name from french alphabet
184
- randomName({ alphabet: "french" });
185
- // Dbïœ
186
-
187
- // name with length 5 chars
178
+ // with length 5 chars
188
179
  randomName({ length: 5 });
180
+ // or short:
181
+ randomName(5);
189
182
  // Okmpj
190
183
 
191
- // name with 2 min and 5 max chars
184
+ // with 2 min and 5 max chars
192
185
  randomName({ length: [2, 5] });
186
+ // or short:
187
+ randomName([2, 5]);
193
188
  // Wslg
194
- ```
195
189
 
196
- Equals to:
190
+ // name from french alphabet
191
+ randomName({ alphabet: "french" });
192
+ // or short:
193
+ randomName("french");
194
+ // Dbïœ
197
195
 
198
- ```ts
199
- random(
200
- ["english", "u"],
201
- [
202
- ["english", "l"],
203
- [1, 10],
204
- ]
205
- );
196
+ // name from french alphabet with length
197
+ randomName({ alphabet: "french", length: 10 });
198
+ // or short:
199
+ randomName("french", 10);
200
+ // Rsîrjhjôôw
206
201
  ```
207
202
 
208
203
  Options:
209
204
  | Name | Type| Description|
210
205
  | ------------------------ | ---- |------------ |
211
- |length|[RandexLength](#randexlength) | Length of chars |
212
- |alphabet|[RandexAlphabet](#randexalphabet) | Defined alphabet |
206
+ |length|[RandexLength](#randexlength) | Length of chars. Default: min - 2, max - 10 chars|
207
+ |alphabet|[RandexAlphabet](#randexalphabet) | Defined alphabet. Default: `english` |
213
208
 
214
209
  ## randomFullName
215
210
 
@@ -218,6 +213,7 @@ Randoms a full name of the person.
218
213
  ```ts
219
214
  import { randomFullName } from "randex";
220
215
 
216
+ // default
221
217
  randomFullName();
222
218
  // Eqaa Bfmotnq
223
219
  ```
@@ -225,9 +221,84 @@ randomFullName();
225
221
  Options:
226
222
  | Name | Type| Description|
227
223
  | ------------------------ | ---- |------------ |
228
- |firstLength|[RandexLength](#randexlength) | First name length of chars |
229
- |secondLength|[RandexLength](#randexlength) | Second name length of chars |
230
- |alphabet|[RandexAlphabet](#randexalphabet) | Defined alphabet |
224
+ |firstLength|[RandexLength](#randexlength) | First name length of chars. Default: min - 2, max - 10 chars |
225
+ |secondLength|[RandexLength](#randexlength) | Second name length of chars. Default: min - 2, max - 10 chars |
226
+ |alphabet|[RandexAlphabet](#randexalphabet) | Defined alphabet. Default: `english` |
227
+
228
+ ## Customization
229
+
230
+ [random](#random) function is very flexible, there are many custom functions can be created.
231
+
232
+ There are examples how to create custom function for most common cases:
233
+
234
+ <b>randomFileName</b>
235
+
236
+ ```ts
237
+ random([["english", "number"], "_.", [5, 10]]) +
238
+ random(["english", "number"]) +
239
+ "." +
240
+ random([
241
+ ["english", "l"],
242
+ [2, 5],
243
+ ]);
244
+ ```
245
+
246
+ <b>randomUsername</b>
247
+
248
+ ```ts
249
+ random(
250
+ ["english", "l"],
251
+ [
252
+ [["english", "l"], "number"],
253
+ [5, 10],
254
+ ]
255
+ );
256
+ ```
257
+
258
+ <b>randomEmail</b>
259
+
260
+ ```ts
261
+ random(["english", "l"], [[["english", "l"], "number"], 10], ["english", "l"]) +
262
+ "@" +
263
+ random(["english", "l"], [["english", "l"], "-", [0, 5]], ["english", "l"]) +
264
+ "." +
265
+ random([
266
+ ["english", "l"],
267
+ [2, 4],
268
+ ]);
269
+ ```
270
+
271
+ <b>randomName</b>
272
+
273
+ ```ts
274
+ random(
275
+ ["english", "u"],
276
+ [
277
+ ["english", "l"],
278
+ [1, 10],
279
+ ]
280
+ );
281
+ ```
282
+
283
+ <b>randomFullName</b>
284
+
285
+ ```ts
286
+ random(
287
+ ["english", "u"],
288
+ [
289
+ ["english", "l"],
290
+ [1, 10],
291
+ ]
292
+ ) +
293
+ " " +
294
+ random(
295
+ ["english", "u"],
296
+ [
297
+ ["english", "l"],
298
+ [1, 10],
299
+ ]
300
+ );
301
+ ```
231
302
 
232
303
  ## Types
233
304
 
@@ -239,6 +310,16 @@ Possible types:
239
310
 
240
311
  `[number, number]`: an array of min and max length.
241
312
 
313
+ Example:
314
+
315
+ ```ts
316
+ random({ set: "bit", length: 5 });
317
+ random({ set: "bit", length: [5, 10] });
318
+ // or short:
319
+ random(["bit", 5]);
320
+ random(["bit", [5, 10]]);
321
+ ```
322
+
242
323
  ## RandexSet
243
324
 
244
325
  Possible types:
@@ -247,20 +328,56 @@ Possible types:
247
328
 
248
329
  `[string, string]`: the first item is - [RandexAlphabet](#randexalphabet), the second item is - [RandexCase](#randexcase)
249
330
 
331
+ Example:
332
+
333
+ ```ts
334
+ random({ set: "bit" });
335
+ random({ set: "spanish" });
336
+ random({ set: ["spanish", "lower"] });
337
+ // or short:
338
+ random("bit");
339
+ random("spanish");
340
+ random(["spanish", "l"]);
341
+ ```
342
+
250
343
  ## RandexAlphabet
251
344
 
252
345
  An alphabet of chars
253
346
 
254
347
  `string` values: `english`, `french`, `spanish`, `russian`.
255
348
 
349
+ Example:
350
+
351
+ ```ts
352
+ random({ set: "spanish" });
353
+ // or short:
354
+ random("spanish");
355
+ ```
356
+
256
357
  ## RandexKit
257
358
 
258
359
  A kit of chars
259
360
 
260
361
  `string` values: `hex`, `symbol`, `number`, `binary`.
261
362
 
363
+ Example:
364
+
365
+ ```ts
366
+ random({ set: "hex" });
367
+ // or short:
368
+ random("hex");
369
+ ```
370
+
262
371
  ## RandexCase
263
372
 
264
373
  A case of alphabet
265
374
 
266
375
  `string` values: `upper`, `u`,`lower`, `l`.
376
+
377
+ Example:
378
+
379
+ ```ts
380
+ random({ set: ["spanish", "lower"] });
381
+ // or short:
382
+ random(["spanish", "l"]);
383
+ ```
@@ -62,7 +62,7 @@ function toRangeOptions(options) {
62
62
  fullRange += range;
63
63
  }
64
64
  if (set) {
65
- fullRange += set_1.RtSetUtil.toRange(set);
65
+ fullRange += set_1.RandexSetUtil.toRange(set);
66
66
  }
67
67
  return {
68
68
  range: fullRange,
@@ -1,7 +1,8 @@
1
- import { RandexSet } from "../interfaces";
2
- export declare class RtSetUtil {
1
+ import { RandexSet, RandexLength } from "../interfaces";
2
+ export declare class RandexSetUtil {
3
3
  private static toSingleRange;
4
4
  private static toAlphabetCase;
5
5
  private static toAlphabetRange;
6
6
  static toRange(set: RandexSet): string;
7
+ static getLength(reservedChars: number, length: RandexLength | undefined, defaultLength: RandexLength): RandexLength;
7
8
  }
package/lib/basic/set.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RtSetUtil = void 0;
3
+ exports.RandexSetUtil = void 0;
4
4
  var type_1 = require("./type");
5
5
  var hex = "0123456789ABCDEFabcdef";
6
6
  var symbol = '[-!$%^&*()_+|~=`{}[]:";<>?,./]' + "'";
@@ -14,15 +14,15 @@ var spanishLower = "abcdefghijklmnopqrstuvwxyzñ";
14
14
  var spanishUpper = "ABCDEFGHIJKLMNOPQRSTUVWXYZÑ";
15
15
  var russianLower = "абвгдеёжзийклмнопрстуфхцчшщъыьэюя";
16
16
  var russianUpper = "АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ";
17
- var RtSetUtil = /** @class */ (function () {
18
- function RtSetUtil() {
17
+ var RandexSetUtil = /** @class */ (function () {
18
+ function RandexSetUtil() {
19
19
  }
20
- RtSetUtil.toSingleRange = function (itemSet) {
20
+ RandexSetUtil.toSingleRange = function (itemSet) {
21
21
  if (Array.isArray(itemSet)) {
22
- return RtSetUtil.toAlphabetRange(itemSet);
22
+ return RandexSetUtil.toAlphabetRange(itemSet);
23
23
  }
24
24
  else if (type_1.RandexTypeParser.inAlphabet(itemSet)) {
25
- return RtSetUtil.toAlphabetRange([itemSet, "default"]);
25
+ return RandexSetUtil.toAlphabetRange([itemSet, "default"]);
26
26
  }
27
27
  switch (itemSet) {
28
28
  case "hex":
@@ -37,7 +37,7 @@ var RtSetUtil = /** @class */ (function () {
37
37
  return "";
38
38
  }
39
39
  };
40
- RtSetUtil.toAlphabetCase = function (cas, lowerWord, upperWord) {
40
+ RandexSetUtil.toAlphabetCase = function (cas, lowerWord, upperWord) {
41
41
  switch (cas) {
42
42
  case "lower":
43
43
  case "l":
@@ -49,31 +49,51 @@ var RtSetUtil = /** @class */ (function () {
49
49
  return lowerWord + upperWord;
50
50
  }
51
51
  };
52
- RtSetUtil.toAlphabetRange = function (set) {
52
+ RandexSetUtil.toAlphabetRange = function (set) {
53
53
  var alphabet = set[0], aCase = set[1];
54
54
  switch (alphabet) {
55
55
  case "english":
56
- return RtSetUtil.toAlphabetCase(aCase, englishLower, englishUpper);
56
+ return RandexSetUtil.toAlphabetCase(aCase, englishLower, englishUpper);
57
57
  case "french":
58
- return RtSetUtil.toAlphabetCase(aCase, frenchLower, frenchUpper);
58
+ return RandexSetUtil.toAlphabetCase(aCase, frenchLower, frenchUpper);
59
59
  case "spanish":
60
- return RtSetUtil.toAlphabetCase(aCase, spanishLower, spanishUpper);
60
+ return RandexSetUtil.toAlphabetCase(aCase, spanishLower, spanishUpper);
61
61
  // case "german":
62
62
  // return RtSetUtil.toAlphabetCase(aCase, englishLower, englishUpper);
63
63
  case "russian":
64
- return RtSetUtil.toAlphabetCase(aCase, russianLower, russianUpper);
64
+ return RandexSetUtil.toAlphabetCase(aCase, russianLower, russianUpper);
65
65
  }
66
66
  };
67
- RtSetUtil.toRange = function (set) {
67
+ RandexSetUtil.toRange = function (set) {
68
68
  var result = "";
69
69
  if (type_1.RandexTypeParser.isSetSingle(set)) {
70
- result += RtSetUtil.toSingleRange(set);
70
+ result += RandexSetUtil.toSingleRange(set);
71
71
  }
72
72
  else if (type_1.RandexTypeParser.isSet(set)) {
73
- result += set.map(RtSetUtil.toSingleRange).join("");
73
+ result += set.map(RandexSetUtil.toSingleRange).join("");
74
74
  }
75
75
  return result;
76
76
  };
77
- return RtSetUtil;
77
+ RandexSetUtil.getLength = function (reservedChars, length, defaultLength) {
78
+ var result = defaultLength;
79
+ if (typeof length === "number" && length > reservedChars) {
80
+ result = length - reservedChars;
81
+ }
82
+ else if (Array.isArray(length)) {
83
+ var min = length[0], max = length[1];
84
+ var dMin = min - reservedChars;
85
+ var dMax = max - reservedChars;
86
+ if (dMin >= 0 && dMax >= 0) {
87
+ if (dMin < dMax) {
88
+ return [dMin, dMax];
89
+ }
90
+ else if (dMin === dMax) {
91
+ return dMin;
92
+ }
93
+ }
94
+ }
95
+ return result;
96
+ };
97
+ return RandexSetUtil;
78
98
  }());
79
- exports.RtSetUtil = RtSetUtil;
99
+ exports.RandexSetUtil = RandexSetUtil;
@@ -3,7 +3,7 @@ export declare class RandexTypeParser {
3
3
  private static inRange;
4
4
  private static inLiteral;
5
5
  static inCase(value: string): value is RandexCase;
6
- static inAlphabet(value: string): value is RandexAlphabet;
6
+ static inAlphabet(value: any): value is RandexAlphabet;
7
7
  static inSet(value: string): value is RandexSingleSet;
8
8
  static isLength(value: any): value is RandexLength;
9
9
  static isSetSingle(value: any): value is RandexItemSet;
package/lib/basic/type.js CHANGED
@@ -13,14 +13,15 @@ var RandexTypeParser = /** @class */ (function () {
13
13
  for (var _i = 1; _i < arguments.length; _i++) {
14
14
  expects[_i - 1] = arguments[_i];
15
15
  }
16
- return !!expects.find(function (x) { return x === value; });
16
+ return typeof value === "string" && !!expects.find(function (x) { return x === value; });
17
17
  };
18
18
  RandexTypeParser.inCase = function (value) {
19
19
  return RandexTypeParser.inLiteral(value, "default", "lower", "upper", "l", "u");
20
20
  };
21
21
  RandexTypeParser.inAlphabet = function (value) {
22
- return RandexTypeParser.inLiteral(value, "english", "french", "spanish", // "german",
23
- "russian");
22
+ return (typeof value === "string" &&
23
+ RandexTypeParser.inLiteral(value, "english", "french", "spanish", // "german",
24
+ "russian"));
24
25
  };
25
26
  RandexTypeParser.inSet = function (value) {
26
27
  return RandexTypeParser.inAlphabet(value) || RandexTypeParser.inLiteral(value, "hex", "symbol", "number", "binary");
@@ -0,0 +1,11 @@
1
+ import { RandexAlphabet, RandexLength } from "../interfaces";
2
+ export interface RandexFullNameOptions {
3
+ alphabet?: RandexAlphabet;
4
+ firstLength?: RandexLength;
5
+ secondLength?: RandexLength;
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;
@@ -0,0 +1,35 @@
1
+ "use strict";
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;
@@ -2,3 +2,4 @@ export * from "./email";
2
2
  export * from "./filename";
3
3
  export * from "./name";
4
4
  export * from "./username";
5
+ export * from "./fullname";
@@ -18,3 +18,4 @@ __exportStar(require("./email"), exports);
18
18
  __exportStar(require("./filename"), exports);
19
19
  __exportStar(require("./name"), exports);
20
20
  __exportStar(require("./username"), exports);
21
+ __exportStar(require("./fullname"), exports);
@@ -1,12 +1,9 @@
1
1
  import { RandexAlphabet, RandexLength } from "../interfaces";
2
2
  export interface RandexNameOptions {
3
- length?: RandexLength;
4
- alphabet?: RandexAlphabet;
5
- }
6
- export interface RandexFullNameOptions {
7
- firstLength?: RandexLength;
8
- secondLength?: RandexLength;
9
3
  alphabet?: RandexAlphabet;
4
+ length?: RandexLength;
10
5
  }
11
- export declare function randomName(options?: RandexNameOptions): string;
12
- export declare function randomFullName(options?: RandexFullNameOptions): string;
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;
@@ -1,35 +1,30 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.randomFullName = exports.randomName = void 0;
3
+ exports.randomName = void 0;
4
4
  var basic_1 = require("../basic");
5
- function getLength(reservedChars, length, defaultLength) {
6
- var result = defaultLength;
7
- if (typeof length === "number" && length > reservedChars) {
8
- result = length - reservedChars;
5
+ var set_1 = require("../basic/set");
6
+ var type_1 = require("../basic/type");
7
+ function randomName(p1, p2) {
8
+ var length = 0;
9
+ var alphabet = "english";
10
+ if (type_1.RandexTypeParser.isLength(p1)) {
11
+ length = p1;
9
12
  }
10
- else if (Array.isArray(length)) {
11
- var min = length[0], max = length[1];
12
- var dMin = min - reservedChars;
13
- var dMax = max - reservedChars;
14
- if (dMin >= 0 && dMax >= 0) {
15
- if (dMin < dMax) {
16
- return [dMin, dMax];
17
- }
18
- else if (dMin === dMax) {
19
- return dMin;
20
- }
13
+ else if (type_1.RandexTypeParser.inAlphabet(p1)) {
14
+ alphabet = p1;
15
+ if (type_1.RandexTypeParser.isLength(p2)) {
16
+ length = p2;
21
17
  }
22
18
  }
23
- return result;
24
- }
25
- function randomName(options) {
26
- var _a = options || {}, length = _a.length, _b = _a.alphabet, alphabet = _b === void 0 ? "english" : _b;
27
- var currentLength = getLength(1, length, [1, 9]);
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
28
  return (0, basic_1.random)([alphabet, "u"], [[alphabet, "l"], currentLength]);
29
29
  }
30
30
  exports.randomName = randomName;
31
- function randomFullName(options) {
32
- var _a = options || {}, firstLength = _a.firstLength, secondLength = _a.secondLength, alphabet = _a.alphabet;
33
- return randomName({ length: firstLength, alphabet: alphabet }) + " " + randomName({ length: secondLength, alphabet: alphabet });
34
- }
35
- exports.randomFullName = randomFullName;
@@ -1 +1,5 @@
1
- export declare function randomUsername(): string;
1
+ import { RandexLength } from "../interfaces";
2
+ export interface RandexUsernameOptions {
3
+ length?: RandexLength;
4
+ }
5
+ export declare function randomUsername(options?: RandexUsernameOptions | RandexLength): string;
@@ -2,10 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.randomUsername = void 0;
4
4
  var basic_1 = require("../basic");
5
- function randomUsername() {
6
- return (0, basic_1.random)(["english", "l"], [
7
- [["english", "l"], "number"],
8
- [5, 10],
9
- ]);
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]);
10
11
  }
11
12
  exports.randomUsername = randomUsername;
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var name_1 = require("../custom/name");
3
+ var custom_1 = require("../custom");
4
4
  var test_util_1 = require("./test-util");
5
5
  describe("randomFullName", function () {
6
6
  it("simple", function () {
7
7
  for (var i = 0; i < 100; i++) {
8
- var value = (0, name_1.randomFullName)();
8
+ var value = (0, custom_1.randomFullName)();
9
9
  expect(test_util_1.TestUtil.isFullNameValid(value)).toBeTruthy();
10
10
  }
11
11
  });
@@ -9,31 +9,47 @@ describe("markdown", function () {
9
9
  length: 3,
10
10
  });
11
11
  expect(value.length).toBe(3);
12
+ value = (0, basic_1.random)(["english", 3]);
13
+ expect(value.length).toBe(3);
14
+ //
12
15
  value = (0, basic_1.random)({
13
16
  set: ["english", "lower"],
14
17
  length: 3,
15
18
  });
16
19
  expect(value.length).toBe(3);
20
+ value = (0, basic_1.random)([["english", "lower"], 3]);
21
+ expect(value.length).toBe(3);
22
+ //
17
23
  value = (0, basic_1.random)({
18
24
  set: "english",
19
25
  length: [1, 3],
20
26
  });
21
27
  expect(value.length).toBeLessThanOrEqual(3);
28
+ value = (0, basic_1.random)(["english", [1, 3]]);
29
+ expect(value.length).toBeLessThanOrEqual(3);
30
+ //
22
31
  value = (0, basic_1.random)({
23
32
  set: "number",
24
33
  length: 3,
25
34
  });
26
35
  expect(value.length).toBe(3);
36
+ value = (0, basic_1.random)(["number", 3]);
37
+ expect(value.length).toBe(3);
38
+ //
27
39
  value = (0, basic_1.random)({
28
40
  range: "abc123",
29
41
  length: 3,
30
42
  });
31
43
  expect(value.length).toBe(3);
44
+ //
32
45
  value = (0, basic_1.random)({
33
46
  set: ["english", "number"],
34
47
  length: 3,
35
48
  });
36
49
  expect(value.length).toBe(3);
50
+ value = (0, basic_1.random)([["english", "number"], 3]);
51
+ expect(value.length).toBe(3);
52
+ //
37
53
  value = (0, basic_1.random)({
38
54
  set: "english",
39
55
  length: 2,
@@ -42,6 +58,8 @@ describe("markdown", function () {
42
58
  length: 2,
43
59
  });
44
60
  expect(value.length).toBe(4);
61
+ value = (0, basic_1.random)(["english", 2], [["english", "number"], 2]);
62
+ expect(value.length).toBe(4);
45
63
  });
46
64
  it("randomFileName", function () {
47
65
  var value = (0, custom_1.randomFileName)({
@@ -9,12 +9,26 @@ describe("randomName", function () {
9
9
  expect(test_util_1.TestUtil.isNameValid(value)).toBeTruthy();
10
10
  }
11
11
  });
12
- it("options", function () {
13
- var value1 = (0, name_1.randomName)({ length: 5 });
14
- expect(value1.length).toBe(5);
15
- var value2 = (0, name_1.randomName)({ length: [5, 5] });
16
- expect(value2.length).toBe(5);
17
- var value3 = (0, name_1.randomName)({ length: [1, 5] });
18
- expect(test_util_1.TestUtil.inNumberRange(value3.length, [1, 5])).toBeTruthy();
12
+ it("options: length", function () {
13
+ var value = (0, name_1.randomName)({ length: 5 });
14
+ expect(value.length).toBe(5);
15
+ value = (0, name_1.randomName)(5);
16
+ expect(value.length).toBe(5);
17
+ //
18
+ value = (0, name_1.randomName)({ length: [5, 5] });
19
+ expect(value.length).toBe(5);
20
+ value = (0, name_1.randomName)([5, 5]);
21
+ expect(value.length).toBe(5);
22
+ //
23
+ value = (0, name_1.randomName)({ length: [1, 5] });
24
+ expect(test_util_1.TestUtil.inNumberRange(value.length, [1, 5])).toBeTruthy();
25
+ value = (0, name_1.randomName)([1, 5]);
26
+ expect(test_util_1.TestUtil.inNumberRange(value.length, [1, 5])).toBeTruthy();
27
+ });
28
+ it("options: alphabet", function () {
29
+ var value = (0, name_1.randomName)({ alphabet: "russian", length: 5 });
30
+ expect(value.length).toBe(5);
31
+ value = (0, name_1.randomName)("french", 10);
32
+ expect(value.length).toBe(10);
19
33
  });
20
34
  });
@@ -32,6 +32,12 @@ describe("random", function () {
32
32
  inSet("english", [1, 3]);
33
33
  inSet("english", [0, 1]);
34
34
  });
35
+ it("length: alphabet", function () {
36
+ var value = (0, basic_1.random)("english");
37
+ expect(value.length).toBe(1);
38
+ value = (0, basic_1.random)(["english", "l"]);
39
+ expect(value.length).toBe(1);
40
+ });
35
41
  it("alphabet: upper", function () {
36
42
  for (var i = 0; i < 100; i++) {
37
43
  var value = (0, basic_1.random)(["english", "u"]);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var set_1 = require("../basic/set");
4
+ var defaultLength = [1, 10];
5
+ function getLength(reservedChars, length, resultLength) {
6
+ var result = set_1.RandexSetUtil.getLength(reservedChars, length, defaultLength);
7
+ if (typeof resultLength === "number") {
8
+ expect(result).toBe(resultLength);
9
+ }
10
+ else {
11
+ expect(result).toMatchObject(resultLength);
12
+ }
13
+ }
14
+ describe("RandexSetUtil", function () {
15
+ describe("getLength", function () {
16
+ it("single", function () {
17
+ getLength(0, 2, 2);
18
+ getLength(1, 3, 2);
19
+ getLength(0, undefined, defaultLength);
20
+ getLength(5, 3, defaultLength);
21
+ });
22
+ it("array", function () {
23
+ getLength(0, [1, 2], [1, 2]);
24
+ getLength(1, [2, 3], [1, 2]);
25
+ getLength(3, [1, 5], defaultLength);
26
+ });
27
+ });
28
+ });
@@ -46,11 +46,11 @@ var TestUtil = /** @class */ (function () {
46
46
  return value.length > 0;
47
47
  };
48
48
  TestUtil.inSet = function (value, set) {
49
- var range = set_1.RtSetUtil.toRange(set);
49
+ var range = set_1.RandexSetUtil.toRange(set);
50
50
  return TestUtil.inRange(value, range);
51
51
  };
52
52
  TestUtil.inBoth = function (value, set, range) {
53
- var fullRange = set_1.RtSetUtil.toRange(set) + range;
53
+ var fullRange = set_1.RandexSetUtil.toRange(set) + range;
54
54
  return TestUtil.inRange(value, fullRange);
55
55
  };
56
56
  TestUtil.isEmailValid = function (email) {
@@ -9,4 +9,20 @@ describe("randomEmail", function () {
9
9
  expect(test_util_1.TestUtil.isUsernameValid(value)).toBeTruthy();
10
10
  }
11
11
  });
12
+ it("options", function () {
13
+ var value = (0, username_1.randomUsername)({ length: 5 });
14
+ expect(value.length).toBe(5);
15
+ value = (0, username_1.randomUsername)(5);
16
+ expect(value.length).toBe(5);
17
+ //
18
+ value = (0, username_1.randomUsername)({ length: [5, 5] });
19
+ expect(value.length).toBe(5);
20
+ value = (0, username_1.randomUsername)([5, 5]);
21
+ expect(value.length).toBe(5);
22
+ //
23
+ value = (0, username_1.randomUsername)({ length: [1, 5] });
24
+ expect(test_util_1.TestUtil.inNumberRange(value.length, [1, 5])).toBeTruthy();
25
+ value = (0, username_1.randomUsername)([1, 5]);
26
+ expect(test_util_1.TestUtil.inNumberRange(value.length, [1, 5])).toBeTruthy();
27
+ });
12
28
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "randex",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -26,15 +26,12 @@
26
26
  "ts-jest": "^24.1.0",
27
27
  "typescript": "^4.2.4"
28
28
  },
29
- "dependencies": {
30
- "reflect-metadata": "^0.2.1"
31
- },
32
29
  "keywords": [
33
30
  "random",
34
31
  "random filename",
35
32
  "random email",
36
33
  "random username",
37
- "random full name",
34
+ "random name",
38
35
  "random string"
39
36
  ]
40
37
  }