randex 0.26.0 → 0.31.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 +109 -68
- package/lib/basic/const.d.ts +3 -0
- package/lib/basic/const.js +5 -0
- package/lib/basic/set.d.ts +10 -9
- package/lib/basic/set.js +8 -2
- package/lib/basic/type.d.ts +2 -2
- package/lib/custom/email.d.ts +2 -2
- package/lib/custom/filenameX.d.ts +3 -3
- package/lib/custom/fullnameX.d.ts +4 -4
- package/lib/custom/index.d.ts +17 -6
- package/lib/custom/index.js +4 -27
- package/lib/custom/number.d.ts +6 -2
- package/lib/custom/number.js +9 -2
- package/lib/custom/random.js +5 -5
- package/lib/custom/sentence.d.ts +11 -0
- package/lib/custom/sentence.js +50 -0
- package/lib/custom/singleName.d.ts +3 -3
- package/lib/custom/username.d.ts +2 -2
- package/lib/custom/word.d.ts +6 -6
- package/lib/custom/word.js +2 -1
- package/lib/interfaces/base.d.ts +6 -6
- package/lib/interfaces/email.d.ts +4 -4
- package/lib/interfaces/filename.d.ts +3 -3
- package/lib/interfaces/fullname.d.ts +3 -3
- package/lib/interfaces/index.d.ts +1 -0
- package/lib/interfaces/index.js +1 -0
- package/lib/interfaces/random.d.ts +2 -2
- package/lib/interfaces/sentence.d.ts +5 -0
- package/lib/interfaces/sentence.js +2 -0
- package/lib/interfaces/username.d.ts +2 -2
- package/lib/interfaces/word.d.ts +2 -2
- package/lib/test/markdown.test.js +1 -1
- package/lib/test/{number-array.test.js → number.many.test.js} +10 -14
- package/lib/test/params.test.js +2 -2
- package/lib/test/random.test.js +1 -1
- package/lib/test/sentence.test.d.ts +1 -0
- package/lib/test/sentence.test.js +33 -0
- package/lib/test/test-util.d.ts +10 -9
- package/lib/test/test-util.js +15 -3
- package/lib/test/word.test.js +10 -3
- package/package.json +1 -1
- /package/lib/test/{number-array.test.d.ts → number.many.test.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -17,16 +17,20 @@ npm i randex
|
|
|
17
17
|
Strings:
|
|
18
18
|
|
|
19
19
|
- [random](#random)
|
|
20
|
+
- [word](#word)
|
|
21
|
+
- [sentence](#sentence)
|
|
20
22
|
- [fileName](#filename)
|
|
21
23
|
- [username](#username)
|
|
22
24
|
- [email](#email)
|
|
23
25
|
- [singleName](#singlename)
|
|
24
26
|
- [fullName](#fullname)
|
|
25
|
-
- [word](#word)
|
|
26
27
|
|
|
27
28
|
Numbers:
|
|
28
29
|
- [number](#number)
|
|
29
|
-
|
|
30
|
+
|
|
31
|
+
Many
|
|
32
|
+
- [many](#many)
|
|
33
|
+
|
|
30
34
|
|
|
31
35
|
Generic Type:
|
|
32
36
|
- [array](#array)
|
|
@@ -79,9 +83,9 @@ Randex.random({
|
|
|
79
83
|
Randex.random(["number", 3]);
|
|
80
84
|
// 643
|
|
81
85
|
|
|
82
|
-
// 3 chars from custom range
|
|
86
|
+
// 3 chars from custom char range
|
|
83
87
|
Randex.random({
|
|
84
|
-
|
|
88
|
+
charRange: "abc123",
|
|
85
89
|
length: 3,
|
|
86
90
|
});
|
|
87
91
|
// a21
|
|
@@ -115,8 +119,86 @@ Options:
|
|
|
115
119
|
| Name | Type| Description|
|
|
116
120
|
| ------------------------ | ---- |------------ |
|
|
117
121
|
|set|[RandexSet](#randexset) | Defined chars|
|
|
118
|
-
|
|
|
119
|
-
|length|[
|
|
122
|
+
|charRange|`string`| Range or custom chars |
|
|
123
|
+
|length|[RandexRange](#randexrange) | Length of chars |
|
|
124
|
+
|
|
125
|
+
## word
|
|
126
|
+
|
|
127
|
+
Randoms a simple word.
|
|
128
|
+
|
|
129
|
+
```ts
|
|
130
|
+
import Randex from "randex";
|
|
131
|
+
|
|
132
|
+
// default
|
|
133
|
+
Randex.word();
|
|
134
|
+
// kpmld
|
|
135
|
+
|
|
136
|
+
// with length 5 chars
|
|
137
|
+
Randex.word({ length: 5 });
|
|
138
|
+
// or short:
|
|
139
|
+
Randex.word(5);
|
|
140
|
+
// imphs
|
|
141
|
+
|
|
142
|
+
// with 2 min and 5 max chars
|
|
143
|
+
Randex.word({ length: [2, 5] });
|
|
144
|
+
// or short:
|
|
145
|
+
Randex.word([2, 5]);
|
|
146
|
+
// kslg
|
|
147
|
+
|
|
148
|
+
// name from french alphabet
|
|
149
|
+
Randex.word({ alphabet: "french" });
|
|
150
|
+
// or short:
|
|
151
|
+
Randex.word("french");
|
|
152
|
+
// dbïœ
|
|
153
|
+
|
|
154
|
+
// name from french alphabet with length
|
|
155
|
+
Randex.word({ alphabet: "french", length: 10 });
|
|
156
|
+
// or short:
|
|
157
|
+
Randex.word("french", 10);
|
|
158
|
+
// rsîrjhjôôw
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Options:
|
|
162
|
+
| Name | Type| Description|
|
|
163
|
+
| ------------------------ | ---- |------------ |
|
|
164
|
+
|length|[RandexRange](#randexrange) | Length of chars. Default: [2,10] |
|
|
165
|
+
|alphabet|[RandexAlphabet](#randexalphabet) | Defined alphabet. Default: `english` |
|
|
166
|
+
|
|
167
|
+
## sentence
|
|
168
|
+
|
|
169
|
+
Randoms a sentence.
|
|
170
|
+
|
|
171
|
+
```ts
|
|
172
|
+
import Randex from "randex";
|
|
173
|
+
|
|
174
|
+
// default word range is from 3 to 15
|
|
175
|
+
Randex.sentence();
|
|
176
|
+
// Gpgowb te vdancy poluwsd sswl aqxq.
|
|
177
|
+
|
|
178
|
+
// with 5 words
|
|
179
|
+
Randex.sentence({ wordRange: 5 });
|
|
180
|
+
// or:
|
|
181
|
+
Randex.sentence(5);
|
|
182
|
+
// Xja wyfbhnhtl ptn shemiukme poyyjtr.
|
|
183
|
+
|
|
184
|
+
// with words range
|
|
185
|
+
Randex.sentence({ wordRange: [3, 6] });
|
|
186
|
+
// or:
|
|
187
|
+
Randex.sentence([3, 6]);
|
|
188
|
+
// Vg nfobxcwg tmhfu hiqonw.
|
|
189
|
+
|
|
190
|
+
// with french alphabet
|
|
191
|
+
Randex.sentence({ alphabet: "french" });
|
|
192
|
+
// or:
|
|
193
|
+
Randex.sentence("french");
|
|
194
|
+
// Êid æeâoô déèbfûûæ aôç udôûsèqpa ygyïœùuè oê rmânacgwnc kuàq qêœççzœx iolîœsqàu aùàrpëhuâh rèèfhmæ klltu.
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
Options:
|
|
198
|
+
| Name | Type| Description|
|
|
199
|
+
| ------------------------ | ---- |------------ |
|
|
200
|
+
|wordRange|[RandexRange](#randexrange) | Range of words. Default: [3,15] |
|
|
201
|
+
|alphabet|[RandexAlphabet](#randexalphabet) | Defined alphabet. Default: `english` |
|
|
120
202
|
|
|
121
203
|
## fileName
|
|
122
204
|
|
|
@@ -161,8 +243,8 @@ Randex.fileName(8, "xml");
|
|
|
161
243
|
Options:
|
|
162
244
|
| Name | Type| Description|
|
|
163
245
|
| ------------------------ | ---- |------------ |
|
|
164
|
-
|fileNameLength|[
|
|
165
|
-
|extensionLength|[
|
|
246
|
+
|fileNameLength|[RandexRange](#randexrange) | Length of file name (not including extension). Default: [3,10] |
|
|
247
|
+
|extensionLength|[RandexRange](#randexrange) | Length of extension (not including file name) chars. Default: [2,5] |
|
|
166
248
|
|extension| `string`| File extension. |
|
|
167
249
|
|
|
168
250
|
## username
|
|
@@ -192,7 +274,7 @@ Randex.username([2, 5]);
|
|
|
192
274
|
Options:
|
|
193
275
|
| Name | Type| Description|
|
|
194
276
|
| ------------------------ | ---- |------------ |
|
|
195
|
-
|length|[
|
|
277
|
+
|length|[RandexRange](#randexrange) | Length of chars. Default: [6,10] |
|
|
196
278
|
|
|
197
279
|
## randomEmail
|
|
198
280
|
|
|
@@ -235,9 +317,9 @@ randomEmail("test.com");
|
|
|
235
317
|
Options:
|
|
236
318
|
| Name | Type| Description|
|
|
237
319
|
| ------------------------ | ---- |------------ |
|
|
238
|
-
|prefixLength|[
|
|
239
|
-
|hightDomainLength|[
|
|
240
|
-
|lowDomainLength|[
|
|
320
|
+
|prefixLength|[RandexRange](#randexrange) | Length of email prefix (chars before `@`). Default: [6, 10] |
|
|
321
|
+
|hightDomainLength|[RandexRange](#randexrange) | Length of hight domain part (example: test.<b>com</b>). Default: [1,6] |
|
|
322
|
+
|lowDomainLength|[RandexRange](#randexrange) | Length of low domain part (example: <b>test</b>.com). Default: [4,2] |
|
|
241
323
|
|domain| `string`| Defined domain. |
|
|
242
324
|
|
|
243
325
|
## singleName
|
|
@@ -279,7 +361,7 @@ Randex.singleName("french", 10);
|
|
|
279
361
|
Options:
|
|
280
362
|
| Name | Type| Description|
|
|
281
363
|
| ------------------------ | ---- |------------ |
|
|
282
|
-
|length|[
|
|
364
|
+
|length|[RandexRange](#randexrange) | Length of chars. Default: [2,10] |
|
|
283
365
|
|alphabet|[RandexAlphabet](#randexalphabet) | Defined alphabet. Default: `english` |
|
|
284
366
|
|
|
285
367
|
## randomFullName
|
|
@@ -297,52 +379,8 @@ Randex.fullName();
|
|
|
297
379
|
Options:
|
|
298
380
|
| Name | Type| Description|
|
|
299
381
|
| ------------------------ | ---- |------------ |
|
|
300
|
-
|firstLength|[
|
|
301
|
-
|secondLength|[
|
|
302
|
-
|alphabet|[RandexAlphabet](#randexalphabet) | Defined alphabet. Default: `english` |
|
|
303
|
-
|
|
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] |
|
|
382
|
+
|firstLength|[RandexRange](#randexrange) | First name length of chars. Default: [2, 10] |
|
|
383
|
+
|secondLength|[RandexRange](#randexrange) | Second name length of chars. Default: [2,10] |
|
|
346
384
|
|alphabet|[RandexAlphabet](#randexalphabet) | Defined alphabet. Default: `english` |
|
|
347
385
|
|
|
348
386
|
|
|
@@ -365,18 +403,21 @@ Options:
|
|
|
365
403
|
| ------------------------ | ---- |------------ |
|
|
366
404
|
|decimals| `number` | Number of decimal digits |
|
|
367
405
|
|
|
368
|
-
##
|
|
406
|
+
## many
|
|
369
407
|
|
|
370
|
-
Generates
|
|
408
|
+
Generates many defined random methods.
|
|
371
409
|
|
|
372
410
|
```ts
|
|
373
411
|
import Randex from "randex";
|
|
374
412
|
|
|
375
|
-
// Generates
|
|
376
|
-
Randex.
|
|
413
|
+
// Generates three words with english alphabet.
|
|
414
|
+
Randex.many(3).word("english");
|
|
415
|
+
|
|
416
|
+
// Generates five sentences with french alphabet.
|
|
417
|
+
Randex.many(5).sentence("french");
|
|
377
418
|
|
|
378
|
-
// Generates an array
|
|
379
|
-
Randex.
|
|
419
|
+
// Generates an array with length from 2 to 4 of random numbers from 3 to 7.
|
|
420
|
+
Randex.many([2, 4]).number([3, 7]);
|
|
380
421
|
```
|
|
381
422
|
|
|
382
423
|
## array
|
|
@@ -479,13 +520,13 @@ Randex.random(
|
|
|
479
520
|
|
|
480
521
|
## Types
|
|
481
522
|
|
|
482
|
-
##
|
|
523
|
+
## RandexRange
|
|
483
524
|
|
|
484
525
|
Possible types:
|
|
485
526
|
|
|
486
|
-
`number`: strict
|
|
527
|
+
`number`: strict number
|
|
487
528
|
|
|
488
|
-
`[number, number]`: an array of min and max
|
|
529
|
+
`[number, number]`: an array of min and max numbers.
|
|
489
530
|
|
|
490
531
|
Example:
|
|
491
532
|
|
package/lib/basic/set.d.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import { RandexSet,
|
|
1
|
+
import { RandexSet, RandexRange } from "../interfaces";
|
|
2
2
|
export declare class RandexSetUtil {
|
|
3
|
-
static readonly defaultFileNameLength:
|
|
4
|
-
static readonly defaultExtensionLength:
|
|
3
|
+
static readonly defaultFileNameLength: RandexRange;
|
|
4
|
+
static readonly defaultExtensionLength: RandexRange;
|
|
5
5
|
static readonly fileNameExtraChars = "";
|
|
6
|
-
static readonly defaultEmailPrefixLength:
|
|
7
|
-
static readonly defaultHightDomainEmailLength:
|
|
8
|
-
static readonly defaultLowDomainEmailLength:
|
|
6
|
+
static readonly defaultEmailPrefixLength: RandexRange;
|
|
7
|
+
static readonly defaultHightDomainEmailLength: RandexRange;
|
|
8
|
+
static readonly defaultLowDomainEmailLength: RandexRange;
|
|
9
9
|
private static toSingleRange;
|
|
10
10
|
private static toAlphabetCase;
|
|
11
11
|
private static toAlphabetRange;
|
|
12
12
|
static toRange(set: RandexSet): string;
|
|
13
|
-
static getLength(reservedChars: number, length:
|
|
14
|
-
static
|
|
15
|
-
static
|
|
13
|
+
static getLength(reservedChars: number, length: RandexRange | undefined, defaultLength: RandexRange): RandexRange;
|
|
14
|
+
static randomSingleNumber(length: number): number;
|
|
15
|
+
static randomRangeNumber(min: number, max: number): number;
|
|
16
|
+
static many<TItem>(count: RandexRange, callback: () => TItem): TItem[];
|
|
16
17
|
}
|
package/lib/basic/set.js
CHANGED
|
@@ -94,12 +94,18 @@ var RandexSetUtil = /** @class */ (function () {
|
|
|
94
94
|
}
|
|
95
95
|
return result;
|
|
96
96
|
};
|
|
97
|
-
RandexSetUtil.
|
|
97
|
+
RandexSetUtil.randomSingleNumber = function (length) {
|
|
98
98
|
return Math.floor(Math.random() * length);
|
|
99
99
|
};
|
|
100
|
+
RandexSetUtil.randomRangeNumber = function (min, max) {
|
|
101
|
+
var minN = Math.min(min, max);
|
|
102
|
+
var maxN = Math.max(min, max);
|
|
103
|
+
return RandexSetUtil.randomSingleNumber(maxN - minN + 1) + minN;
|
|
104
|
+
};
|
|
100
105
|
RandexSetUtil.many = function (count, callback) {
|
|
101
106
|
var result = [];
|
|
102
|
-
|
|
107
|
+
var length = Array.isArray(count) ? RandexSetUtil.randomRangeNumber(count[0], count[1]) : count;
|
|
108
|
+
for (var i = 0; i < length; i++) {
|
|
103
109
|
result.push(callback());
|
|
104
110
|
}
|
|
105
111
|
return result;
|
package/lib/basic/type.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { RandexCase, RandexAlphabet, RandexItemSet, RandexContentArrayOptions, RandexSet, RandexSingleSet,
|
|
1
|
+
import { RandexCase, RandexAlphabet, RandexItemSet, RandexContentArrayOptions, RandexSet, RandexSingleSet, RandexRange } from "../interfaces";
|
|
2
2
|
export declare class RandexTypeParser {
|
|
3
3
|
private static inRange;
|
|
4
4
|
private static inLiteral;
|
|
5
5
|
static inCase(value: string): value is RandexCase;
|
|
6
6
|
static inAlphabet(value: any): value is RandexAlphabet;
|
|
7
7
|
static inSet(value: string): value is RandexSingleSet;
|
|
8
|
-
static isLength(value: any): value is
|
|
8
|
+
static isLength(value: any): value is RandexRange;
|
|
9
9
|
static isSetSingle(value: any): value is RandexItemSet;
|
|
10
10
|
static isSet(value: any): value is RandexSet;
|
|
11
11
|
static isPartArray(value: any): value is RandexContentArrayOptions;
|
package/lib/custom/email.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RandexEmailOptions,
|
|
1
|
+
import { RandexEmailOptions, RandexRange } from "../interfaces";
|
|
2
2
|
export declare function randexEmail(options?: RandexEmailOptions): string;
|
|
3
|
-
export declare function randexEmail(prefixLength:
|
|
3
|
+
export declare function randexEmail(prefixLength: RandexRange, lowDomainLength?: RandexRange, hightDomainLength?: RandexRange): string;
|
|
4
4
|
export declare function randexEmail(domain: string): string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { RandexFileNameOptions,
|
|
1
|
+
import { RandexFileNameOptions, RandexRange } from "../interfaces";
|
|
2
2
|
export declare function randexFileName(options?: RandexFileNameOptions): string;
|
|
3
|
-
export declare function randexFileName(fileNameLength:
|
|
4
|
-
export declare function randexFileName(fileNameLength:
|
|
3
|
+
export declare function randexFileName(fileNameLength: RandexRange, extensionLength?: RandexRange): string;
|
|
4
|
+
export declare function randexFileName(fileNameLength: RandexRange, extension: string): string;
|
|
5
5
|
export declare function randexFileName(extension: string): string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { RandexAlphabet, RandexFullNameOptions,
|
|
1
|
+
import { RandexAlphabet, RandexFullNameOptions, RandexRange } from "../interfaces";
|
|
2
2
|
export declare function randexFullName(options?: RandexFullNameOptions): string;
|
|
3
|
-
export declare function randexFullName(length:
|
|
3
|
+
export declare function randexFullName(length: RandexRange): string;
|
|
4
4
|
export declare function randexFullName(alphabet?: RandexAlphabet): string;
|
|
5
|
-
export declare function randexFullName(alphabet: RandexAlphabet, length:
|
|
6
|
-
export declare function randexFullName(alphabet: RandexAlphabet, firstLength:
|
|
5
|
+
export declare function randexFullName(alphabet: RandexAlphabet, length: RandexRange): string;
|
|
6
|
+
export declare function randexFullName(alphabet: RandexAlphabet, firstLength: RandexRange, secondLength: RandexRange): string;
|
package/lib/custom/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RandexRange } from "../interfaces";
|
|
2
2
|
import { randexBool } from "./bool";
|
|
3
3
|
import { randexEmail } from "./email";
|
|
4
4
|
import { randexFileName } from "./filenameX";
|
|
5
5
|
import { randexFullName } from "./fullnameX";
|
|
6
6
|
import { randexNumber } from "./number";
|
|
7
7
|
import { randexRandom } from "./random";
|
|
8
|
+
import { randexSentence } from "./sentence";
|
|
8
9
|
import { randexSingleName } from "./singleName";
|
|
9
10
|
import { randexUsername } from "./username";
|
|
10
11
|
import { randexWord } from "./word";
|
|
@@ -18,16 +19,26 @@ export declare class Randex {
|
|
|
18
19
|
static fileName: typeof randexFileName;
|
|
19
20
|
static fullName: typeof randexFullName;
|
|
20
21
|
static singleName: typeof randexSingleName;
|
|
21
|
-
static word: typeof randexWord;
|
|
22
|
-
static numberArray(length: RandexLength, count: number): number[];
|
|
23
22
|
static number: typeof randexNumber;
|
|
24
23
|
static username: typeof randexUsername;
|
|
25
|
-
static
|
|
24
|
+
static word: typeof randexWord;
|
|
25
|
+
static sentence: typeof randexSentence;
|
|
26
|
+
static many(count: RandexRange): {
|
|
26
27
|
word: {
|
|
27
28
|
(options?: import("../interfaces").RandexWordOptions | undefined): string[];
|
|
28
|
-
(length:
|
|
29
|
+
(length: RandexRange): string[];
|
|
29
30
|
(alphabet?: import("../interfaces").RandexAlphabet | undefined): string[];
|
|
30
|
-
(alphabet: import("../interfaces").RandexAlphabet, length:
|
|
31
|
+
(alphabet: import("../interfaces").RandexAlphabet, length: RandexRange): string[];
|
|
32
|
+
};
|
|
33
|
+
sentence: {
|
|
34
|
+
(options?: import("../interfaces").RandexSentenceOptions | undefined): string[];
|
|
35
|
+
(length: RandexRange): string[];
|
|
36
|
+
(alphabet?: import("../interfaces").RandexAlphabet | undefined): string[];
|
|
37
|
+
(alphabet: import("../interfaces").RandexAlphabet, length: RandexRange): string[];
|
|
38
|
+
};
|
|
39
|
+
number: {
|
|
40
|
+
(length: RandexRange, options?: import("../interfaces").RandomNumberOptions | undefined): number[];
|
|
41
|
+
(from: number, to: number, options?: import("../interfaces").RandomNumberOptions | undefined): number[];
|
|
31
42
|
};
|
|
32
43
|
};
|
|
33
44
|
}
|
package/lib/custom/index.js
CHANGED
|
@@ -7,6 +7,7 @@ var filenameX_1 = require("./filenameX");
|
|
|
7
7
|
var fullnameX_1 = require("./fullnameX");
|
|
8
8
|
var number_1 = require("./number");
|
|
9
9
|
var random_1 = require("./random");
|
|
10
|
+
var sentence_1 = require("./sentence");
|
|
10
11
|
var singleName_1 = require("./singleName");
|
|
11
12
|
var username_1 = require("./username");
|
|
12
13
|
var word_1 = require("./word");
|
|
@@ -42,33 +43,8 @@ var Randex = /** @class */ (function () {
|
|
|
42
43
|
}
|
|
43
44
|
return result;
|
|
44
45
|
};
|
|
45
|
-
Randex.numberArray = function (length, count) {
|
|
46
|
-
var min = 0;
|
|
47
|
-
var max = 0;
|
|
48
|
-
var result = [];
|
|
49
|
-
if (typeof length === "number") {
|
|
50
|
-
max = length;
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
min = length[0];
|
|
54
|
-
max = length[1];
|
|
55
|
-
}
|
|
56
|
-
var maxCount = max - min + 1;
|
|
57
|
-
var numberArray = [];
|
|
58
|
-
for (var i = min; i <= max; i++) {
|
|
59
|
-
numberArray.push(i);
|
|
60
|
-
}
|
|
61
|
-
for (var i = 0; i < count && i < maxCount; i++) {
|
|
62
|
-
var arrayCount = numberArray.length - 1;
|
|
63
|
-
var index = Randex.number(arrayCount);
|
|
64
|
-
var value = numberArray[index];
|
|
65
|
-
result.push(value);
|
|
66
|
-
numberArray.splice(index, 1);
|
|
67
|
-
}
|
|
68
|
-
return result;
|
|
69
|
-
};
|
|
70
46
|
Randex.many = function (count) {
|
|
71
|
-
return { word: (0, word_1.randexManyWord)(count) };
|
|
47
|
+
return { word: (0, word_1.randexManyWord)(count), sentence: (0, sentence_1.randexManySentence)(count), number: (0, number_1.randexManyNumber)(count) };
|
|
72
48
|
};
|
|
73
49
|
Randex.random = random_1.randexRandom;
|
|
74
50
|
Randex.bool = bool_1.randexBool;
|
|
@@ -76,9 +52,10 @@ var Randex = /** @class */ (function () {
|
|
|
76
52
|
Randex.fileName = filenameX_1.randexFileName;
|
|
77
53
|
Randex.fullName = fullnameX_1.randexFullName;
|
|
78
54
|
Randex.singleName = singleName_1.randexSingleName;
|
|
79
|
-
Randex.word = word_1.randexWord;
|
|
80
55
|
Randex.number = number_1.randexNumber;
|
|
81
56
|
Randex.username = username_1.randexUsername;
|
|
57
|
+
Randex.word = word_1.randexWord;
|
|
58
|
+
Randex.sentence = sentence_1.randexSentence;
|
|
82
59
|
return Randex;
|
|
83
60
|
}());
|
|
84
61
|
exports.Randex = Randex;
|
package/lib/custom/number.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function randexNumber(length:
|
|
1
|
+
import { RandexRange, RandomNumberOptions } from "../interfaces";
|
|
2
|
+
export declare function randexNumber(length: RandexRange, options?: RandomNumberOptions): number;
|
|
3
3
|
export declare function randexNumber(from: number, to: number, options?: RandomNumberOptions): number;
|
|
4
|
+
export declare function randexManyNumber(count: RandexRange): {
|
|
5
|
+
(length: RandexRange, options?: RandomNumberOptions): number[];
|
|
6
|
+
(from: number, to: number, options?: RandomNumberOptions): number[];
|
|
7
|
+
};
|
package/lib/custom/number.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.randexNumber = void 0;
|
|
3
|
+
exports.randexManyNumber = exports.randexNumber = void 0;
|
|
4
4
|
var set_1 = require("../basic/set");
|
|
5
5
|
function getNumberBase(decimals) {
|
|
6
6
|
return decimals === 1 ? 10 : Math.pow(10, decimals);
|
|
@@ -15,7 +15,7 @@ function getNumberValue(value, decimals) {
|
|
|
15
15
|
function innerRandomNumber(from, to, decimals) {
|
|
16
16
|
var fromV = getNumberValue(from, decimals);
|
|
17
17
|
var toV = getNumberValue(to, decimals);
|
|
18
|
-
var result = set_1.RandexSetUtil.
|
|
18
|
+
var result = set_1.RandexSetUtil.randomRangeNumber(fromV, toV);
|
|
19
19
|
if (typeof decimals === "number") {
|
|
20
20
|
result = result / getNumberBase(decimals);
|
|
21
21
|
}
|
|
@@ -37,3 +37,10 @@ function randexNumber(p1, p2, p3) {
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
exports.randexNumber = randexNumber;
|
|
40
|
+
function randexManyNumber(count) {
|
|
41
|
+
function many(p1, p2, p3) {
|
|
42
|
+
return set_1.RandexSetUtil.many(count, function () { return randexNumber(p1, p2, p3); });
|
|
43
|
+
}
|
|
44
|
+
return many;
|
|
45
|
+
}
|
|
46
|
+
exports.randexManyNumber = randexManyNumber;
|
package/lib/custom/random.js
CHANGED
|
@@ -12,10 +12,10 @@ function randomString(params) {
|
|
|
12
12
|
}
|
|
13
13
|
else if (Array.isArray(length)) {
|
|
14
14
|
var min = length[0], max = length[1];
|
|
15
|
-
currentLength =
|
|
15
|
+
currentLength = set_1.RandexSetUtil.randomRangeNumber(min, max);
|
|
16
16
|
}
|
|
17
17
|
for (var i = 0; i < currentLength; i++) {
|
|
18
|
-
var index = set_1.RandexSetUtil.
|
|
18
|
+
var index = set_1.RandexSetUtil.randomSingleNumber(range.length - 1);
|
|
19
19
|
if (range.length >= index || range.length <= index) {
|
|
20
20
|
result += range[index];
|
|
21
21
|
}
|
|
@@ -38,14 +38,14 @@ function toContent(options) {
|
|
|
38
38
|
}
|
|
39
39
|
: {
|
|
40
40
|
set: set,
|
|
41
|
-
|
|
41
|
+
charRange: rangeOrLength,
|
|
42
42
|
};
|
|
43
43
|
}
|
|
44
44
|
else if (options.length === 3) {
|
|
45
45
|
var set = options[0], range = options[1], length_1 = options[2];
|
|
46
46
|
return {
|
|
47
47
|
set: set,
|
|
48
|
-
|
|
48
|
+
charRange: range,
|
|
49
49
|
length: length_1,
|
|
50
50
|
};
|
|
51
51
|
}
|
|
@@ -54,7 +54,7 @@ function toContent(options) {
|
|
|
54
54
|
}
|
|
55
55
|
function toRangeOptions(options) {
|
|
56
56
|
var fullRange = "";
|
|
57
|
-
var set = options.set, range = options.
|
|
57
|
+
var set = options.set, range = options.charRange, _a = options.length, length = _a === void 0 ? 1 : _a;
|
|
58
58
|
if (range) {
|
|
59
59
|
fullRange += range;
|
|
60
60
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { RandexAlphabet, RandexRange, RandexSentenceOptions } from "../interfaces";
|
|
2
|
+
export declare function randexSentence(options?: RandexSentenceOptions): string;
|
|
3
|
+
export declare function randexSentence(length: RandexRange): string;
|
|
4
|
+
export declare function randexSentence(alphabet?: RandexAlphabet): string;
|
|
5
|
+
export declare function randexSentence(alphabet: RandexAlphabet, length: RandexRange): string;
|
|
6
|
+
export declare function randexManySentence(count: RandexRange): {
|
|
7
|
+
(options?: RandexSentenceOptions): string[];
|
|
8
|
+
(length: RandexRange): string[];
|
|
9
|
+
(alphabet?: RandexAlphabet): string[];
|
|
10
|
+
(alphabet: RandexAlphabet, length: RandexRange): string[];
|
|
11
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.randexManySentence = exports.randexSentence = void 0;
|
|
4
|
+
var const_1 = require("../basic/const");
|
|
5
|
+
var set_1 = require("../basic/set");
|
|
6
|
+
var type_1 = require("../basic/type");
|
|
7
|
+
var word_1 = require("./word");
|
|
8
|
+
function randexSentence(p1, p2) {
|
|
9
|
+
var length = const_1.DEFAULT_SENTENCE_RANGE;
|
|
10
|
+
var alphabet = "english";
|
|
11
|
+
if (type_1.RandexTypeParser.isLength(p1)) {
|
|
12
|
+
length = p1;
|
|
13
|
+
}
|
|
14
|
+
else if (type_1.RandexTypeParser.inAlphabet(p1)) {
|
|
15
|
+
alphabet = p1;
|
|
16
|
+
if (type_1.RandexTypeParser.isLength(p2)) {
|
|
17
|
+
length = p2;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
else if (typeof p1 === "object") {
|
|
21
|
+
var options = p1;
|
|
22
|
+
if (options.alphabet) {
|
|
23
|
+
alphabet = options.alphabet;
|
|
24
|
+
}
|
|
25
|
+
if (options.wordRange) {
|
|
26
|
+
length = options.wordRange;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
var words = (0, word_1.randexManyWord)(length)(alphabet);
|
|
30
|
+
return words
|
|
31
|
+
.map(function (text, index) {
|
|
32
|
+
var wordText = text;
|
|
33
|
+
if (index === 0 && text.length > 0) {
|
|
34
|
+
wordText = text[0].toUpperCase() + text.slice(1);
|
|
35
|
+
}
|
|
36
|
+
if (index + 1 >= words.length) {
|
|
37
|
+
wordText = wordText + ".";
|
|
38
|
+
}
|
|
39
|
+
return wordText;
|
|
40
|
+
})
|
|
41
|
+
.join(" ");
|
|
42
|
+
}
|
|
43
|
+
exports.randexSentence = randexSentence;
|
|
44
|
+
function randexManySentence(count) {
|
|
45
|
+
function many(p1, p2) {
|
|
46
|
+
return set_1.RandexSetUtil.many(count, function () { return randexSentence(p1, p2); });
|
|
47
|
+
}
|
|
48
|
+
return many;
|
|
49
|
+
}
|
|
50
|
+
exports.randexManySentence = randexManySentence;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { RandexAlphabet,
|
|
1
|
+
import { RandexAlphabet, RandexRange, RandexWordOptions } from "../interfaces";
|
|
2
2
|
export declare function randexSingleName(options?: RandexWordOptions): string;
|
|
3
|
-
export declare function randexSingleName(length:
|
|
3
|
+
export declare function randexSingleName(length: RandexRange): string;
|
|
4
4
|
export declare function randexSingleName(alphabet?: RandexAlphabet): string;
|
|
5
|
-
export declare function randexSingleName(alphabet: RandexAlphabet, length:
|
|
5
|
+
export declare function randexSingleName(alphabet: RandexAlphabet, length: RandexRange): string;
|
package/lib/custom/username.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function randexUsername(options?: RandexUsernameOptions |
|
|
1
|
+
import { RandexRange, RandexUsernameOptions } from "../interfaces";
|
|
2
|
+
export declare function randexUsername(options?: RandexUsernameOptions | RandexRange): string;
|
package/lib/custom/word.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { RandexAlphabet,
|
|
1
|
+
import { RandexAlphabet, RandexRange, RandexWordOptions } from "../interfaces";
|
|
2
2
|
export declare function randexWord(options?: RandexWordOptions): string;
|
|
3
|
-
export declare function randexWord(length:
|
|
3
|
+
export declare function randexWord(length: RandexRange): string;
|
|
4
4
|
export declare function randexWord(alphabet?: RandexAlphabet): string;
|
|
5
|
-
export declare function randexWord(alphabet: RandexAlphabet, length:
|
|
6
|
-
export declare function randexManyWord(count:
|
|
5
|
+
export declare function randexWord(alphabet: RandexAlphabet, length: RandexRange): string;
|
|
6
|
+
export declare function randexManyWord(count: RandexRange): {
|
|
7
7
|
(options?: RandexWordOptions): string[];
|
|
8
|
-
(length:
|
|
8
|
+
(length: RandexRange): string[];
|
|
9
9
|
(alphabet?: RandexAlphabet): string[];
|
|
10
|
-
(alphabet: RandexAlphabet, length:
|
|
10
|
+
(alphabet: RandexAlphabet, length: RandexRange): string[];
|
|
11
11
|
};
|
package/lib/custom/word.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.randexManyWord = exports.randexWord = void 0;
|
|
4
|
+
var const_1 = require("../basic/const");
|
|
4
5
|
var set_1 = require("../basic/set");
|
|
5
6
|
var type_1 = require("../basic/type");
|
|
6
7
|
var random_1 = require("./random");
|
|
7
8
|
function randexWord(p1, p2) {
|
|
8
|
-
var length =
|
|
9
|
+
var length = const_1.DEFAULT_WORD_RANGE;
|
|
9
10
|
var alphabet = "english";
|
|
10
11
|
if (type_1.RandexTypeParser.isLength(p1)) {
|
|
11
12
|
length = p1;
|
package/lib/interfaces/base.d.ts
CHANGED
|
@@ -4,18 +4,18 @@ export type RandexSingleSet = RandexAlphabet | "hex" | "symbol" | "number" | "bi
|
|
|
4
4
|
export type RandexAlphabetCase = [RandexAlphabet, RandexCase];
|
|
5
5
|
export type RandexItemSet = RandexSingleSet | RandexAlphabetCase;
|
|
6
6
|
export type RandexSet = RandexItemSet | RandexItemSet[];
|
|
7
|
-
export type
|
|
7
|
+
export type RandexRange = number | [number, number];
|
|
8
8
|
interface RandexItemBasicOptions {
|
|
9
9
|
set?: RandexSet;
|
|
10
|
-
|
|
11
|
-
length?:
|
|
10
|
+
charRange?: string;
|
|
11
|
+
length?: RandexRange;
|
|
12
12
|
}
|
|
13
13
|
export interface RandexContentSetOptions extends Omit<RandexItemBasicOptions, "set"> {
|
|
14
14
|
set: RandexSet;
|
|
15
15
|
}
|
|
16
|
-
export interface RandexContentRangeOptions extends Omit<RandexItemBasicOptions, "
|
|
17
|
-
|
|
16
|
+
export interface RandexContentRangeOptions extends Omit<RandexItemBasicOptions, "charRange"> {
|
|
17
|
+
charRange: string;
|
|
18
18
|
}
|
|
19
|
-
export type RandexContentArrayOptions = [RandexSet, string |
|
|
19
|
+
export type RandexContentArrayOptions = [RandexSet, string | RandexRange] | [RandexSet, string, RandexRange];
|
|
20
20
|
export type RandexContentOptions = RandexContentSetOptions | RandexContentRangeOptions | RandexContentArrayOptions | RandexSet;
|
|
21
21
|
export {};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RandexRange } from "./base";
|
|
2
2
|
interface BasicEmailOptions {
|
|
3
|
-
prefixLength?:
|
|
3
|
+
prefixLength?: RandexRange;
|
|
4
4
|
}
|
|
5
5
|
interface DomainLengthEmailOptions {
|
|
6
|
-
hightDomainLength?:
|
|
7
|
-
lowDomainLength?:
|
|
6
|
+
hightDomainLength?: RandexRange;
|
|
7
|
+
lowDomainLength?: RandexRange;
|
|
8
8
|
}
|
|
9
9
|
interface DomainEmailOptions {
|
|
10
10
|
domain?: string;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RandexRange } from "./base";
|
|
2
2
|
interface BasicFileNameOptions {
|
|
3
|
-
fileNameLength?:
|
|
3
|
+
fileNameLength?: RandexRange;
|
|
4
4
|
}
|
|
5
5
|
interface ExtensionLengthFileNameOptions {
|
|
6
|
-
extensionLength?:
|
|
6
|
+
extensionLength?: RandexRange;
|
|
7
7
|
}
|
|
8
8
|
interface ExtensionFileNameOptions {
|
|
9
9
|
extension?: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { RandexAlphabet,
|
|
1
|
+
import { RandexAlphabet, RandexRange } from "./base";
|
|
2
2
|
export interface RandexFullNameOptions {
|
|
3
3
|
alphabet?: RandexAlphabet;
|
|
4
|
-
firstLength?:
|
|
5
|
-
secondLength?:
|
|
4
|
+
firstLength?: RandexRange;
|
|
5
|
+
secondLength?: RandexRange;
|
|
6
6
|
}
|
package/lib/interfaces/index.js
CHANGED
package/lib/interfaces/word.d.ts
CHANGED
|
@@ -2,20 +2,16 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
var custom_1 = require("../custom");
|
|
4
4
|
function testNumber(min, max, count) {
|
|
5
|
-
var value = custom_1.Randex.
|
|
5
|
+
var value = custom_1.Randex.many(count).number([min, max]);
|
|
6
6
|
var uniqueResult = [];
|
|
7
|
-
var
|
|
7
|
+
for (var i = 0; i < count; i++) {
|
|
8
8
|
var uniqueValue = value[i];
|
|
9
|
-
expect(uniqueResult.find(function (x) { return x === uniqueValue; })).toBeFalsy();
|
|
10
9
|
expect(value[i]).toBeGreaterThanOrEqual(min);
|
|
11
10
|
expect(value[i]).toBeLessThanOrEqual(max);
|
|
12
11
|
uniqueResult.push(uniqueValue);
|
|
13
|
-
};
|
|
14
|
-
for (var i = 0; i < count; i++) {
|
|
15
|
-
_loop_1(i);
|
|
16
12
|
}
|
|
17
13
|
}
|
|
18
|
-
describe("
|
|
14
|
+
describe("random many number", function () {
|
|
19
15
|
it("param: number", function () {
|
|
20
16
|
testNumber(0, 2, 0);
|
|
21
17
|
testNumber(1, 5, 1);
|
|
@@ -31,23 +27,23 @@ describe("randomNumberArray", function () {
|
|
|
31
27
|
var min = 5;
|
|
32
28
|
var max = 10;
|
|
33
29
|
var count = max - min + 1;
|
|
34
|
-
var value = custom_1.Randex.
|
|
30
|
+
var value = custom_1.Randex.many(count).number([min, max]);
|
|
35
31
|
expect(value.length).toBe(count);
|
|
36
32
|
// max length limit
|
|
37
|
-
value = custom_1.Randex.
|
|
38
|
-
expect(value.length).toBe(count);
|
|
33
|
+
value = custom_1.Randex.many(count + 10).number([min, max]);
|
|
34
|
+
expect(value.length).toBe(count + 10);
|
|
39
35
|
});
|
|
40
36
|
it("range: fill all possible values", function () {
|
|
41
37
|
var min = 5;
|
|
42
38
|
var max = 10;
|
|
43
39
|
var count = max - min + 1;
|
|
44
|
-
var value = custom_1.Randex.
|
|
45
|
-
expect(value.length).toBe(count);
|
|
46
|
-
var
|
|
40
|
+
var value = custom_1.Randex.many(count + 10).number([min, max]);
|
|
41
|
+
expect(value.length).toBe(count + 10);
|
|
42
|
+
var _loop_1 = function (i) {
|
|
47
43
|
expect(value.find(function (x) { return x === i; })).toBeTruthy();
|
|
48
44
|
};
|
|
49
45
|
for (var i = min; i <= max; i++) {
|
|
50
|
-
|
|
46
|
+
_loop_1(i);
|
|
51
47
|
}
|
|
52
48
|
});
|
|
53
49
|
});
|
package/lib/test/params.test.js
CHANGED
|
@@ -36,7 +36,7 @@ describe("random params", function () {
|
|
|
36
36
|
it("array 2 (range)", function () {
|
|
37
37
|
var set = "number";
|
|
38
38
|
var range = "abcdefghijklmnopqrstuvwxyz";
|
|
39
|
-
var result1 = custom_1.Randex.random({ set: set,
|
|
39
|
+
var result1 = custom_1.Randex.random({ set: set, charRange: range });
|
|
40
40
|
var result2 = custom_1.Randex.random([set, range]);
|
|
41
41
|
test_util_1.TestUtil.testInBoth(result1, set, range);
|
|
42
42
|
test_util_1.TestUtil.testInBoth(result2, set, range);
|
|
@@ -53,7 +53,7 @@ describe("random params", function () {
|
|
|
53
53
|
var set = "number";
|
|
54
54
|
var range = "abcdefghijklmnopqrstuvwxyz";
|
|
55
55
|
var length = 3;
|
|
56
|
-
var result1 = custom_1.Randex.random({ set: set,
|
|
56
|
+
var result1 = custom_1.Randex.random({ set: set, charRange: range, length: length });
|
|
57
57
|
var result2 = custom_1.Randex.random([set, range, length]);
|
|
58
58
|
test_util_1.TestUtil.testInBoth(result1, set, range, length);
|
|
59
59
|
test_util_1.TestUtil.testInBoth(result2, set, range, length);
|
package/lib/test/random.test.js
CHANGED
|
@@ -9,7 +9,7 @@ function inSet(set, length) {
|
|
|
9
9
|
}
|
|
10
10
|
function inRange(range, length) {
|
|
11
11
|
if (length === void 0) { length = 1; }
|
|
12
|
-
var result = custom_1.Randex.random({
|
|
12
|
+
var result = custom_1.Randex.random({ charRange: range, length: length });
|
|
13
13
|
test_util_1.TestUtil.testInRange(result, range, length);
|
|
14
14
|
}
|
|
15
15
|
describe("random", function () {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
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("sentence", function () {
|
|
6
|
+
it("default", function () {
|
|
7
|
+
test_util_1.TestUtil.loop(function () {
|
|
8
|
+
var text = custom_1.Randex.sentence();
|
|
9
|
+
expect(test_util_1.TestUtil.isSentenceValid(text)).toBeTruthy();
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
it("range", function () {
|
|
13
|
+
var range = [10, 20];
|
|
14
|
+
test_util_1.TestUtil.loop(function () {
|
|
15
|
+
var text = custom_1.Randex.sentence(range);
|
|
16
|
+
expect(test_util_1.TestUtil.isSentenceValid(text, range)).toBeTruthy();
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
it("specific number", function () {
|
|
20
|
+
var range = 5;
|
|
21
|
+
test_util_1.TestUtil.loop(function () {
|
|
22
|
+
var text = custom_1.Randex.sentence(range);
|
|
23
|
+
expect(test_util_1.TestUtil.isSentenceValid(text, range)).toBeTruthy();
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
it("many", function () {
|
|
27
|
+
var count = 5;
|
|
28
|
+
var sentences = custom_1.Randex.many(count).sentence();
|
|
29
|
+
for (var i = 0; i < count; i++) {
|
|
30
|
+
expect(test_util_1.TestUtil.isSentenceValid(sentences[i])).toBeTruthy();
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
});
|
package/lib/test/test-util.d.ts
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RandexRange, RandexSet } from "../interfaces";
|
|
2
2
|
export declare class TestUtil {
|
|
3
|
-
static testIn(value: string, length:
|
|
3
|
+
static testIn(value: string, length: RandexRange | undefined, action: () => void): void;
|
|
4
4
|
static loop(action: (index: number) => void): void;
|
|
5
|
-
static testInSet(value: string, set: RandexSet, length?:
|
|
6
|
-
static testInSetRange(value: string, set: RandexSet, range: string, length?:
|
|
7
|
-
static testInRange(value: string, range: string, length?:
|
|
8
|
-
static testInBoth(value: string, set: RandexSet, range: string, length?:
|
|
5
|
+
static testInSet(value: string, set: RandexSet, length?: RandexRange): void;
|
|
6
|
+
static testInSetRange(value: string, set: RandexSet, range: string, length?: RandexRange): void;
|
|
7
|
+
static testInRange(value: string, range: string, length?: RandexRange): void;
|
|
8
|
+
static testInBoth(value: string, set: RandexSet, range: string, length?: RandexRange): void;
|
|
9
9
|
static inRange(value: string, range: string): boolean;
|
|
10
10
|
static inSet(value: string, set: RandexSet, range?: string): boolean;
|
|
11
11
|
static inBoth(value: string, set: RandexSet, range: string): boolean;
|
|
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(
|
|
16
|
-
static
|
|
17
|
-
static
|
|
15
|
+
static isWordValid(text: string, length?: RandexRange): RegExpMatchArray | null;
|
|
16
|
+
static isSentenceValid(text: string, length?: RandexRange): boolean;
|
|
17
|
+
static isUpperCharValid(value: string, length?: RandexRange): RegExpMatchArray | null;
|
|
18
|
+
static isLowerCharValid(value: string, length?: RandexRange): RegExpMatchArray | null;
|
|
18
19
|
static isFullNameValid(email: string): RegExpMatchArray | null;
|
|
19
20
|
static isFileNameValid(email: string): RegExpMatchArray | null;
|
|
20
21
|
static inNumberRange(value: number, range: [number, number]): boolean;
|
package/lib/test/test-util.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TestUtil = void 0;
|
|
4
|
+
var const_1 = require("../basic/const");
|
|
4
5
|
var set_1 = require("../basic/set");
|
|
5
6
|
var TestUtil = /** @class */ (function () {
|
|
6
7
|
function TestUtil() {
|
|
@@ -77,10 +78,21 @@ var TestUtil = /** @class */ (function () {
|
|
|
77
78
|
TestUtil.isNameValid = function (email) {
|
|
78
79
|
return String(email).match(/^[A-Z][a-z]{1,}$/);
|
|
79
80
|
};
|
|
80
|
-
TestUtil.isWordValid = function (
|
|
81
|
-
if (length === void 0) { length =
|
|
81
|
+
TestUtil.isWordValid = function (text, length) {
|
|
82
|
+
if (length === void 0) { length = const_1.DEFAULT_WORD_RANGE; }
|
|
82
83
|
var l = TestUtil.getLength(length);
|
|
83
|
-
return String(
|
|
84
|
+
return String(text).match(new RegExp("^[a-z]{".concat(l, "}$")));
|
|
85
|
+
};
|
|
86
|
+
TestUtil.isSentenceValid = function (text, length) {
|
|
87
|
+
if (length === void 0) { length = const_1.DEFAULT_SENTENCE_RANGE; }
|
|
88
|
+
var splits = text.split(" ");
|
|
89
|
+
if (Array.isArray(length)) {
|
|
90
|
+
var min = length[0], max = length[1];
|
|
91
|
+
return splits.length >= min && splits.length <= max;
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
return splits.length === length;
|
|
95
|
+
}
|
|
84
96
|
};
|
|
85
97
|
TestUtil.isUpperCharValid = function (value, length) {
|
|
86
98
|
if (length === void 0) { length = 1; }
|
package/lib/test/word.test.js
CHANGED
|
@@ -1,20 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var const_1 = require("../basic/const");
|
|
3
4
|
var custom_1 = require("../custom");
|
|
4
5
|
var test_util_1 = require("./test-util");
|
|
5
6
|
describe("word", function () {
|
|
6
7
|
it("classic", function () {
|
|
7
8
|
test_util_1.TestUtil.loop(function () {
|
|
8
9
|
var w = custom_1.Randex.word();
|
|
9
|
-
expect(test_util_1.TestUtil.isWordValid(w,
|
|
10
|
+
expect(test_util_1.TestUtil.isWordValid(w, const_1.DEFAULT_WORD_RANGE)).toBeTruthy();
|
|
10
11
|
});
|
|
11
12
|
});
|
|
12
|
-
it("many", function () {
|
|
13
|
+
it("many - number", function () {
|
|
13
14
|
var count = 5;
|
|
14
15
|
var ws = custom_1.Randex.many(count).word();
|
|
15
16
|
expect(ws.length).toBe(count);
|
|
16
17
|
for (var i = 0; i < count; i++) {
|
|
17
|
-
expect(test_util_1.TestUtil.isWordValid(ws[i],
|
|
18
|
+
expect(test_util_1.TestUtil.isWordValid(ws[i], const_1.DEFAULT_WORD_RANGE)).toBeTruthy();
|
|
18
19
|
}
|
|
19
20
|
});
|
|
21
|
+
it("many - range", function () {
|
|
22
|
+
var count = [5, 10];
|
|
23
|
+
var ws = custom_1.Randex.many(count).word();
|
|
24
|
+
expect(ws.length).toBeGreaterThanOrEqual(5);
|
|
25
|
+
expect(ws.length).toBeLessThanOrEqual(10);
|
|
26
|
+
});
|
|
20
27
|
});
|
package/package.json
CHANGED
|
File without changes
|