randex 0.22.0 → 0.24.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 +138 -93
- package/lib/custom/index.d.ts +7 -3
- package/lib/custom/index.js +23 -1
- package/lib/custom/{singleName.d.ts → word.d.ts} +1 -1
- package/lib/test/test-util.d.ts +2 -0
- package/lib/test/test-util.js +10 -2
- package/lib/test/word.test.d.ts +1 -0
- package/lib/test/word.test.js +12 -0
- package/package.json +1 -1
- /package/lib/custom/{singleName.js → word.js} +0 -0
package/README.md
CHANGED
|
@@ -17,18 +17,19 @@ npm i randex
|
|
|
17
17
|
Strings:
|
|
18
18
|
|
|
19
19
|
- [random](#random)
|
|
20
|
-
- [
|
|
21
|
-
- [
|
|
22
|
-
- [
|
|
23
|
-
- [
|
|
24
|
-
- [
|
|
20
|
+
- [fileName](#filename)
|
|
21
|
+
- [username](#username)
|
|
22
|
+
- [email](#email)
|
|
23
|
+
- [singleName](#singlename)
|
|
24
|
+
- [fullName](#fullname)
|
|
25
|
+
- [word](#word)
|
|
25
26
|
|
|
26
27
|
Numbers:
|
|
27
|
-
- [
|
|
28
|
-
- [
|
|
28
|
+
- [number](#number)
|
|
29
|
+
- [numberArray](#numberarray)
|
|
29
30
|
|
|
30
31
|
Generic Type:
|
|
31
|
-
- [
|
|
32
|
+
- [array](#array)
|
|
32
33
|
|
|
33
34
|
Deeps:
|
|
34
35
|
|
|
@@ -40,62 +41,62 @@ Deeps:
|
|
|
40
41
|
Basic function to construct random things.
|
|
41
42
|
|
|
42
43
|
```ts
|
|
43
|
-
import
|
|
44
|
+
import Randex from "randex";
|
|
44
45
|
|
|
45
46
|
// 3 english chars
|
|
46
|
-
random({
|
|
47
|
+
Randex.random({
|
|
47
48
|
set: "english",
|
|
48
49
|
length: 3,
|
|
49
50
|
});
|
|
50
51
|
// or short:
|
|
51
|
-
random(["english", 3]);
|
|
52
|
+
Randex.random(["english", 3]);
|
|
52
53
|
// EFd
|
|
53
54
|
|
|
54
55
|
// 3 lower english chars
|
|
55
|
-
random({
|
|
56
|
+
Randex.random({
|
|
56
57
|
set: ["english", "lower"],
|
|
57
58
|
length: 3,
|
|
58
59
|
});
|
|
59
60
|
// or short:
|
|
60
|
-
random([["english", "lower"], 3]);
|
|
61
|
+
Randex.random([["english", "lower"], 3]);
|
|
61
62
|
// yhl
|
|
62
63
|
|
|
63
64
|
// min 1 and max 3 english chars
|
|
64
|
-
random({
|
|
65
|
+
Randex.random({
|
|
65
66
|
set: "english",
|
|
66
67
|
length: [1, 3],
|
|
67
68
|
});
|
|
68
69
|
// or short:
|
|
69
|
-
random(["english", [1, 3]]);
|
|
70
|
+
Randex.random(["english", [1, 3]]);
|
|
70
71
|
// eR
|
|
71
72
|
|
|
72
73
|
// 3 number chars
|
|
73
|
-
random({
|
|
74
|
+
Randex.random({
|
|
74
75
|
set: "number",
|
|
75
76
|
length: 3,
|
|
76
77
|
});
|
|
77
78
|
// or short:
|
|
78
|
-
random(["number", 3]);
|
|
79
|
+
Randex.random(["number", 3]);
|
|
79
80
|
// 643
|
|
80
81
|
|
|
81
82
|
// 3 chars from custom range
|
|
82
|
-
random({
|
|
83
|
+
Randex.random({
|
|
83
84
|
range: "abc123",
|
|
84
85
|
length: 3,
|
|
85
86
|
});
|
|
86
87
|
// a21
|
|
87
88
|
|
|
88
89
|
// 3 english or number chars
|
|
89
|
-
random({
|
|
90
|
+
Randex.random({
|
|
90
91
|
set: ["english", "number"],
|
|
91
92
|
length: 3,
|
|
92
93
|
});
|
|
93
94
|
// or short:
|
|
94
|
-
random([["english", "number"], 3]);
|
|
95
|
+
Randex.random([["english", "number"], 3]);
|
|
95
96
|
// x4d
|
|
96
97
|
|
|
97
98
|
// 4 chars: 2 english and 2 english or number
|
|
98
|
-
random(
|
|
99
|
+
Randex.random(
|
|
99
100
|
{
|
|
100
101
|
set: "english",
|
|
101
102
|
length: 2,
|
|
@@ -106,7 +107,7 @@ random(
|
|
|
106
107
|
}
|
|
107
108
|
);
|
|
108
109
|
// or short:
|
|
109
|
-
random(["english", 2], [["english", "number"], 2]);
|
|
110
|
+
Randex.random(["english", 2], [["english", "number"], 2]);
|
|
110
111
|
// Kb3b
|
|
111
112
|
```
|
|
112
113
|
|
|
@@ -117,43 +118,43 @@ Options:
|
|
|
117
118
|
|range|`string`| Range or custom chars |
|
|
118
119
|
|length|[RandexLength](#randexlength) | Length of chars |
|
|
119
120
|
|
|
120
|
-
##
|
|
121
|
+
## fileName
|
|
121
122
|
|
|
122
123
|
Randoms file name.
|
|
123
124
|
|
|
124
125
|
```ts
|
|
125
|
-
import
|
|
126
|
+
import Randex from "randex";
|
|
126
127
|
|
|
127
128
|
// default
|
|
128
|
-
|
|
129
|
+
Randex.fileName({
|
|
129
130
|
extension: "txt",
|
|
130
131
|
});
|
|
131
132
|
// td1TX31eOB.txt
|
|
132
133
|
|
|
133
134
|
// defined extension
|
|
134
|
-
|
|
135
|
+
Randex.fileName({
|
|
135
136
|
extension: "txt",
|
|
136
137
|
});
|
|
137
138
|
// or short:
|
|
138
|
-
|
|
139
|
+
Randex.fileName("txt");
|
|
139
140
|
// HkmOjqHC6.txt
|
|
140
141
|
|
|
141
142
|
// defined file name length and extension length
|
|
142
|
-
|
|
143
|
+
Randex.fileName({
|
|
143
144
|
fileNameLength: [7, 10],
|
|
144
145
|
extensionLength: 5,
|
|
145
146
|
});
|
|
146
147
|
// or short:
|
|
147
|
-
|
|
148
|
+
Randex.fileName([7, 10], 5);
|
|
148
149
|
// 1SJVkHSBjq.tejuw
|
|
149
150
|
|
|
150
151
|
// defined file name length and extension
|
|
151
|
-
|
|
152
|
+
Randex.fileName({
|
|
152
153
|
fileNameLength: 8,
|
|
153
154
|
extension: "xml",
|
|
154
155
|
});
|
|
155
156
|
// or short:
|
|
156
|
-
|
|
157
|
+
Randex.fileName(8, "xml");
|
|
157
158
|
// JyCsuN5kD.xml
|
|
158
159
|
```
|
|
159
160
|
|
|
@@ -164,27 +165,27 @@ Options:
|
|
|
164
165
|
|extensionLength|[RandexLength](#randexlength) | Length of extension (not including file name) chars. Default: [2,5] |
|
|
165
166
|
|extension| `string`| File extension. |
|
|
166
167
|
|
|
167
|
-
##
|
|
168
|
+
## username
|
|
168
169
|
|
|
169
170
|
Randoms username.
|
|
170
171
|
|
|
171
172
|
```ts
|
|
172
|
-
import
|
|
173
|
+
import Randex from "randex";
|
|
173
174
|
|
|
174
175
|
// default
|
|
175
|
-
|
|
176
|
+
Randex.username();
|
|
176
177
|
// icvv81d1j
|
|
177
178
|
|
|
178
179
|
// with length 5 chars
|
|
179
|
-
|
|
180
|
+
Randex.username({ length: 5 });
|
|
180
181
|
// or short:
|
|
181
|
-
|
|
182
|
+
Randex.username(5);
|
|
182
183
|
// okmle
|
|
183
184
|
|
|
184
185
|
// with 2 min and 5 max chars
|
|
185
|
-
|
|
186
|
+
Randex.singleName({ length: [2, 5] });
|
|
186
187
|
// or short:
|
|
187
|
-
|
|
188
|
+
Randex.username([2, 5]);
|
|
188
189
|
// lkhs
|
|
189
190
|
```
|
|
190
191
|
|
|
@@ -239,39 +240,39 @@ Options:
|
|
|
239
240
|
|lowDomainLength|[RandexLength](#randexlength) | Length of low domain part (example: <b>test</b>.com). Default: [4,2] |
|
|
240
241
|
|domain| `string`| Defined domain. |
|
|
241
242
|
|
|
242
|
-
##
|
|
243
|
+
## singleName
|
|
243
244
|
|
|
244
245
|
Randoms a name of the person, city, place, restaurant, ect.
|
|
245
246
|
|
|
246
247
|
```ts
|
|
247
|
-
import
|
|
248
|
+
import Randex from "randex";
|
|
248
249
|
|
|
249
250
|
// default
|
|
250
|
-
|
|
251
|
+
Randex.singleName();
|
|
251
252
|
// Ijb
|
|
252
253
|
|
|
253
254
|
// with length 5 chars
|
|
254
|
-
|
|
255
|
+
Randex.singleName({ length: 5 });
|
|
255
256
|
// or short:
|
|
256
|
-
|
|
257
|
+
Randex.singleName(5);
|
|
257
258
|
// Okmpj
|
|
258
259
|
|
|
259
260
|
// with 2 min and 5 max chars
|
|
260
|
-
|
|
261
|
+
Randex.singleName({ length: [2, 5] });
|
|
261
262
|
// or short:
|
|
262
|
-
|
|
263
|
+
Randex.singleName([2, 5]);
|
|
263
264
|
// Wslg
|
|
264
265
|
|
|
265
266
|
// name from french alphabet
|
|
266
|
-
|
|
267
|
+
Randex.singleName({ alphabet: "french" });
|
|
267
268
|
// or short:
|
|
268
|
-
|
|
269
|
+
Randex.singleName("french");
|
|
269
270
|
// Dbïœ
|
|
270
271
|
|
|
271
272
|
// name from french alphabet with length
|
|
272
|
-
|
|
273
|
+
Randex.singleName({ alphabet: "french", length: 10 });
|
|
273
274
|
// or short:
|
|
274
|
-
|
|
275
|
+
Randex.singleName("french", 10);
|
|
275
276
|
// Rsîrjhjôôw
|
|
276
277
|
```
|
|
277
278
|
|
|
@@ -286,10 +287,10 @@ Options:
|
|
|
286
287
|
Randoms a full name of the person.
|
|
287
288
|
|
|
288
289
|
```ts
|
|
289
|
-
import
|
|
290
|
+
import Randex from "randex";
|
|
290
291
|
|
|
291
292
|
// default
|
|
292
|
-
|
|
293
|
+
Randex.fullName();
|
|
293
294
|
// Eqaa Bfmotnq
|
|
294
295
|
```
|
|
295
296
|
|
|
@@ -301,18 +302,62 @@ Options:
|
|
|
301
302
|
|alphabet|[RandexAlphabet](#randexalphabet) | Defined alphabet. Default: `english` |
|
|
302
303
|
|
|
303
304
|
|
|
304
|
-
|
|
305
|
+
|
|
306
|
+
## word
|
|
307
|
+
|
|
308
|
+
Randoms a simple word.
|
|
309
|
+
|
|
310
|
+
```ts
|
|
311
|
+
import Randex from "randex";
|
|
312
|
+
|
|
313
|
+
// default
|
|
314
|
+
Randex.word();
|
|
315
|
+
// kpmld
|
|
316
|
+
|
|
317
|
+
// with length 5 chars
|
|
318
|
+
Randex.word({ length: 5 });
|
|
319
|
+
// or short:
|
|
320
|
+
Randex.word(5);
|
|
321
|
+
// imphs
|
|
322
|
+
|
|
323
|
+
// with 2 min and 5 max chars
|
|
324
|
+
Randex.word({ length: [2, 5] });
|
|
325
|
+
// or short:
|
|
326
|
+
Randex.word([2, 5]);
|
|
327
|
+
// kslg
|
|
328
|
+
|
|
329
|
+
// name from french alphabet
|
|
330
|
+
Randex.word({ alphabet: "french" });
|
|
331
|
+
// or short:
|
|
332
|
+
Randex.word("french");
|
|
333
|
+
// dbïœ
|
|
334
|
+
|
|
335
|
+
// name from french alphabet with length
|
|
336
|
+
Randex.word({ alphabet: "french", length: 10 });
|
|
337
|
+
// or short:
|
|
338
|
+
Randex.word("french", 10);
|
|
339
|
+
// rsîrjhjôôw
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
Options:
|
|
343
|
+
| Name | Type| Description|
|
|
344
|
+
| ------------------------ | ---- |------------ |
|
|
345
|
+
|length|[RandexLength](#randexlength) | Length of chars. Default: [2,10] |
|
|
346
|
+
|alphabet|[RandexAlphabet](#randexalphabet) | Defined alphabet. Default: `english` |
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
## number
|
|
305
350
|
|
|
306
351
|
Generates random number from a range of numbers.
|
|
307
352
|
|
|
308
353
|
```ts
|
|
309
|
-
import
|
|
354
|
+
import Randex from "randex";
|
|
310
355
|
|
|
311
356
|
// Generates a number from a range: [0, 3] (includes 0 and 3).
|
|
312
|
-
|
|
357
|
+
Randex.number(3);
|
|
313
358
|
|
|
314
359
|
// Generates a number from a specified range: [3, 7].
|
|
315
|
-
|
|
360
|
+
Randex.number([3, 7]);
|
|
316
361
|
```
|
|
317
362
|
|
|
318
363
|
Options:
|
|
@@ -320,31 +365,31 @@ Options:
|
|
|
320
365
|
| ------------------------ | ---- |------------ |
|
|
321
366
|
|decimals| `number` | Number of decimal digits |
|
|
322
367
|
|
|
323
|
-
##
|
|
368
|
+
## numberArray
|
|
324
369
|
|
|
325
370
|
Generates random array with values from a range.
|
|
326
371
|
|
|
327
372
|
```ts
|
|
328
|
-
import
|
|
373
|
+
import Randex from "randex";
|
|
329
374
|
|
|
330
375
|
// Generates an array (with length equals 2) with unique numbers from a range: [0, 3].
|
|
331
|
-
|
|
376
|
+
Randex.numberArray(3, 2);
|
|
332
377
|
|
|
333
378
|
// Generates an array (with length equals 3) with unique numbers from a range: [3, 7].
|
|
334
|
-
|
|
379
|
+
Randex.numberArray([3, 7], 3);
|
|
335
380
|
```
|
|
336
381
|
|
|
337
|
-
##
|
|
382
|
+
## array
|
|
338
383
|
|
|
339
384
|
Generates random array with values from defined array.
|
|
340
385
|
|
|
341
386
|
```ts
|
|
342
|
-
import
|
|
387
|
+
import Randex from "randex";
|
|
343
388
|
|
|
344
389
|
// Generates an array (with length equals 2) with values picked from defined array as the first parameter.
|
|
345
|
-
|
|
390
|
+
Randex.array([1, 2, 3, 4], 2);
|
|
346
391
|
// [2, 4]
|
|
347
|
-
|
|
392
|
+
Randex.array(["1", "2", "3", "4"], 2);
|
|
348
393
|
// ["1", "3"]
|
|
349
394
|
```
|
|
350
395
|
|
|
@@ -355,24 +400,24 @@ randomArray(["1", "2", "3", "4"], 2);
|
|
|
355
400
|
|
|
356
401
|
There are examples how to create custom function for most common cases:
|
|
357
402
|
|
|
358
|
-
<b>
|
|
403
|
+
<b>Randex.fileName</b>
|
|
359
404
|
|
|
360
405
|
```ts
|
|
361
|
-
random([
|
|
406
|
+
Randex.random([
|
|
362
407
|
["english", "number"],
|
|
363
408
|
[3, 10],
|
|
364
409
|
]) +
|
|
365
410
|
"." +
|
|
366
|
-
random([
|
|
411
|
+
Randex.random([
|
|
367
412
|
["english", "l"],
|
|
368
413
|
[2, 5],
|
|
369
414
|
]);
|
|
370
415
|
```
|
|
371
416
|
|
|
372
|
-
<b>
|
|
417
|
+
<b>Randex.username</b>
|
|
373
418
|
|
|
374
419
|
```ts
|
|
375
|
-
random(
|
|
420
|
+
Randex.random(
|
|
376
421
|
["english", "l"],
|
|
377
422
|
[
|
|
378
423
|
[["english", "l"], "number"],
|
|
@@ -381,29 +426,29 @@ random(
|
|
|
381
426
|
);
|
|
382
427
|
```
|
|
383
428
|
|
|
384
|
-
<b>
|
|
429
|
+
<b>Randex.email</b>
|
|
385
430
|
|
|
386
431
|
```ts
|
|
387
|
-
random([
|
|
432
|
+
Randex.random([
|
|
388
433
|
[["english", "l"], "number"],
|
|
389
434
|
[6, 10],
|
|
390
435
|
]) +
|
|
391
436
|
"@" +
|
|
392
|
-
random([
|
|
437
|
+
Randex.random([
|
|
393
438
|
["english", "l"],
|
|
394
439
|
[2, 4],
|
|
395
440
|
]) +
|
|
396
441
|
"." +
|
|
397
|
-
random([
|
|
442
|
+
Randex.random([
|
|
398
443
|
["english", "l"],
|
|
399
444
|
[1, 6],
|
|
400
445
|
]);
|
|
401
446
|
```
|
|
402
447
|
|
|
403
|
-
<b>
|
|
448
|
+
<b>Randex.singleName</b>
|
|
404
449
|
|
|
405
450
|
```ts
|
|
406
|
-
random(
|
|
451
|
+
Randex.random(
|
|
407
452
|
["english", "u"],
|
|
408
453
|
[
|
|
409
454
|
["english", "l"],
|
|
@@ -412,10 +457,10 @@ random(
|
|
|
412
457
|
);
|
|
413
458
|
```
|
|
414
459
|
|
|
415
|
-
<b>
|
|
460
|
+
<b>Randex.fullName</b>
|
|
416
461
|
|
|
417
462
|
```ts
|
|
418
|
-
random(
|
|
463
|
+
Randex.random(
|
|
419
464
|
["english", "u"],
|
|
420
465
|
[
|
|
421
466
|
["english", "l"],
|
|
@@ -423,7 +468,7 @@ random(
|
|
|
423
468
|
]
|
|
424
469
|
) +
|
|
425
470
|
" " +
|
|
426
|
-
random(
|
|
471
|
+
Randex.random(
|
|
427
472
|
["english", "u"],
|
|
428
473
|
[
|
|
429
474
|
["english", "l"],
|
|
@@ -445,11 +490,11 @@ Possible types:
|
|
|
445
490
|
Example:
|
|
446
491
|
|
|
447
492
|
```ts
|
|
448
|
-
random({ set: "bit", length: 5 });
|
|
449
|
-
random({ set: "bit", length: [5, 10] });
|
|
493
|
+
Randex.random({ set: "bit", length: 5 });
|
|
494
|
+
Randex.random({ set: "bit", length: [5, 10] });
|
|
450
495
|
// or short:
|
|
451
|
-
random(["bit", 5]);
|
|
452
|
-
random(["bit", [5, 10]]);
|
|
496
|
+
Randex.random(["bit", 5]);
|
|
497
|
+
Randex.random(["bit", [5, 10]]);
|
|
453
498
|
```
|
|
454
499
|
|
|
455
500
|
## RandexSet
|
|
@@ -463,13 +508,13 @@ Possible types:
|
|
|
463
508
|
Example:
|
|
464
509
|
|
|
465
510
|
```ts
|
|
466
|
-
random({ set: "bit" });
|
|
467
|
-
random({ set: "spanish" });
|
|
468
|
-
random({ set: ["spanish", "lower"] });
|
|
511
|
+
Randex.random({ set: "bit" });
|
|
512
|
+
Randex.random({ set: "spanish" });
|
|
513
|
+
Randex.random({ set: ["spanish", "lower"] });
|
|
469
514
|
// or short:
|
|
470
|
-
random("bit");
|
|
471
|
-
random("spanish");
|
|
472
|
-
random(["spanish", "l"]);
|
|
515
|
+
Randex.random("bit");
|
|
516
|
+
Randex.random("spanish");
|
|
517
|
+
Randex.random(["spanish", "l"]);
|
|
473
518
|
```
|
|
474
519
|
|
|
475
520
|
## RandexAlphabet
|
|
@@ -481,9 +526,9 @@ An alphabet of chars
|
|
|
481
526
|
Example:
|
|
482
527
|
|
|
483
528
|
```ts
|
|
484
|
-
random({ set: "spanish" });
|
|
529
|
+
Randex.random({ set: "spanish" });
|
|
485
530
|
// or short:
|
|
486
|
-
random("spanish");
|
|
531
|
+
Randex.random("spanish");
|
|
487
532
|
```
|
|
488
533
|
|
|
489
534
|
## RandexKit
|
|
@@ -495,9 +540,9 @@ A kit of chars
|
|
|
495
540
|
Example:
|
|
496
541
|
|
|
497
542
|
```ts
|
|
498
|
-
random({ set: "hex" });
|
|
543
|
+
Randex.random({ set: "hex" });
|
|
499
544
|
// or short:
|
|
500
|
-
random("hex");
|
|
545
|
+
Randex.random("hex");
|
|
501
546
|
```
|
|
502
547
|
|
|
503
548
|
## RandexCase
|
|
@@ -509,7 +554,7 @@ A case of alphabet
|
|
|
509
554
|
Example:
|
|
510
555
|
|
|
511
556
|
```ts
|
|
512
|
-
random({ set: ["spanish", "lower"] });
|
|
557
|
+
Randex.random({ set: ["spanish", "lower"] });
|
|
513
558
|
// or short:
|
|
514
|
-
random(["spanish", "l"]);
|
|
559
|
+
Randex.random(["spanish", "l"]);
|
|
515
560
|
```
|
package/lib/custom/index.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { RandexAlphabet, RandexContentOptions, RandexLength } from "../interfaces";
|
|
2
2
|
import { RandexEmailOptions } from "./email";
|
|
3
3
|
import { RandexFileNameOptions } from "./filename";
|
|
4
|
-
import {
|
|
4
|
+
import { RandexWordOptions } from "./word";
|
|
5
5
|
import { RandomNumberOptions } from "./number";
|
|
6
6
|
import { RandexUsernameOptions } from "./username";
|
|
7
7
|
import { RandexFullNameOptions } from "./fullname";
|
|
8
8
|
export * from "./email";
|
|
9
9
|
export * from "./filename";
|
|
10
|
-
export * from "./
|
|
10
|
+
export * from "./word";
|
|
11
11
|
export * from "./username";
|
|
12
12
|
export * from "./fullname";
|
|
13
13
|
export * from "./number";
|
|
@@ -32,10 +32,14 @@ export declare class Randex {
|
|
|
32
32
|
static fullName(alphabet?: RandexAlphabet): any;
|
|
33
33
|
static fullName(alphabet: RandexAlphabet, length: RandexLength): any;
|
|
34
34
|
static fullName(alphabet: RandexAlphabet, firstLength: RandexLength, secondLength: RandexLength): any;
|
|
35
|
-
static singleName(options?:
|
|
35
|
+
static singleName(options?: RandexWordOptions): any;
|
|
36
36
|
static singleName(length: RandexLength): any;
|
|
37
37
|
static singleName(alphabet?: RandexAlphabet): any;
|
|
38
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;
|
|
39
43
|
static numberArray(length: RandexLength, count: number): number[];
|
|
40
44
|
private static getNumberBase;
|
|
41
45
|
private static getNumberValue;
|
package/lib/custom/index.js
CHANGED
|
@@ -19,7 +19,7 @@ var set_1 = require("../basic/set");
|
|
|
19
19
|
var type_1 = require("../basic/type");
|
|
20
20
|
__exportStar(require("./email"), exports);
|
|
21
21
|
__exportStar(require("./filename"), exports);
|
|
22
|
-
__exportStar(require("./
|
|
22
|
+
__exportStar(require("./word"), exports);
|
|
23
23
|
__exportStar(require("./username"), exports);
|
|
24
24
|
__exportStar(require("./fullname"), exports);
|
|
25
25
|
__exportStar(require("./number"), exports);
|
|
@@ -260,6 +260,28 @@ var Randex = /** @class */ (function () {
|
|
|
260
260
|
var currentLength = set_1.RandexSetUtil.getLength(1, length, [1, 9]);
|
|
261
261
|
return Randex.random([alphabet, "u"], [[alphabet, "l"], currentLength]);
|
|
262
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
|
+
};
|
|
263
285
|
Randex.numberArray = function (length, count) {
|
|
264
286
|
var min = 0;
|
|
265
287
|
var max = 0;
|
package/lib/test/test-util.d.ts
CHANGED
|
@@ -12,9 +12,11 @@ export declare class TestUtil {
|
|
|
12
12
|
static isEmailValid(email: string): RegExpMatchArray | null;
|
|
13
13
|
static isUsernameValid(email: string): RegExpMatchArray | null;
|
|
14
14
|
static isNameValid(email: string): RegExpMatchArray | null;
|
|
15
|
+
static isWordValid(word: string, length?: RandexLength): RegExpMatchArray | null;
|
|
15
16
|
static isUpperCharValid(value: string, length?: RandexLength): RegExpMatchArray | null;
|
|
16
17
|
static isLowerCharValid(value: string, length?: RandexLength): RegExpMatchArray | null;
|
|
17
18
|
static isFullNameValid(email: string): RegExpMatchArray | null;
|
|
18
19
|
static isFileNameValid(email: string): RegExpMatchArray | null;
|
|
19
20
|
static inNumberRange(value: number, range: [number, number]): boolean;
|
|
21
|
+
private static getLength;
|
|
20
22
|
}
|
package/lib/test/test-util.js
CHANGED
|
@@ -77,14 +77,19 @@ var TestUtil = /** @class */ (function () {
|
|
|
77
77
|
TestUtil.isNameValid = function (email) {
|
|
78
78
|
return String(email).match(/^[A-Z][a-z]{1,}$/);
|
|
79
79
|
};
|
|
80
|
+
TestUtil.isWordValid = function (word, length) {
|
|
81
|
+
if (length === void 0) { length = 2; }
|
|
82
|
+
var l = TestUtil.getLength(length);
|
|
83
|
+
return String(word).match(new RegExp("^[a-z]{".concat(l, "}$")));
|
|
84
|
+
};
|
|
80
85
|
TestUtil.isUpperCharValid = function (value, length) {
|
|
81
86
|
if (length === void 0) { length = 1; }
|
|
82
|
-
var l =
|
|
87
|
+
var l = TestUtil.getLength(length);
|
|
83
88
|
return String(value).match(new RegExp("^[A-Z]{".concat(l, "}$")));
|
|
84
89
|
};
|
|
85
90
|
TestUtil.isLowerCharValid = function (value, length) {
|
|
86
91
|
if (length === void 0) { length = 1; }
|
|
87
|
-
var l =
|
|
92
|
+
var l = TestUtil.getLength(length);
|
|
88
93
|
return String(value).match(new RegExp("^[a-z]{".concat(l, "}$")));
|
|
89
94
|
};
|
|
90
95
|
TestUtil.isFullNameValid = function (email) {
|
|
@@ -98,6 +103,9 @@ var TestUtil = /** @class */ (function () {
|
|
|
98
103
|
TestUtil.inNumberRange = function (value, range) {
|
|
99
104
|
return value >= range[0] && value <= range[1];
|
|
100
105
|
};
|
|
106
|
+
TestUtil.getLength = function (length) {
|
|
107
|
+
return Array.isArray(length) ? "".concat(length[0], ",").concat(length[1]) : length;
|
|
108
|
+
};
|
|
101
109
|
return TestUtil;
|
|
102
110
|
}());
|
|
103
111
|
exports.TestUtil = TestUtil;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var custom_1 = require("../custom");
|
|
4
|
+
var test_util_1 = require("./test-util");
|
|
5
|
+
describe("word", function () {
|
|
6
|
+
it("classic", function () {
|
|
7
|
+
test_util_1.TestUtil.loop(function () {
|
|
8
|
+
var w = custom_1.Randex.word();
|
|
9
|
+
expect(test_util_1.TestUtil.isWordValid(w, [2, 10])).toBeTruthy();
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
});
|
package/package.json
CHANGED
|
File without changes
|