randex 0.32.0 → 0.33.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 +90 -49
- package/lib/basic/const.d.ts +4 -3
- package/lib/basic/const.js +2 -1
- package/lib/basic/set.d.ts +8 -8
- 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 +15 -7
- package/lib/custom/index.js +3 -1
- package/lib/custom/number.d.ts +4 -4
- package/lib/custom/phrase.d.ts +11 -0
- package/lib/custom/phrase.js +39 -0
- package/lib/custom/sentence.d.ts +6 -6
- package/lib/custom/sentence.js +2 -2
- 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/interfaces/base.d.ts +3 -3
- 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/phrase.d.ts +5 -0
- package/lib/interfaces/phrase.js +2 -0
- package/lib/interfaces/random.d.ts +2 -2
- package/lib/interfaces/sentence.d.ts +2 -4
- package/lib/interfaces/username.d.ts +2 -2
- package/lib/interfaces/word.d.ts +2 -2
- package/lib/test/number.many.test.js +1 -1
- package/lib/test/phrase.test.d.ts +1 -0
- package/lib/test/phrase.test.js +33 -0
- package/lib/test/test-util.d.ts +11 -10
- package/lib/test/test-util.js +11 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,12 +18,13 @@ Strings:
|
|
|
18
18
|
|
|
19
19
|
- [random](#random)
|
|
20
20
|
- [word](#word)
|
|
21
|
-
- [sentence](#sentence)
|
|
22
21
|
- [fileName](#filename)
|
|
23
22
|
- [username](#username)
|
|
24
23
|
- [email](#email)
|
|
25
24
|
- [singleName](#singlename)
|
|
26
25
|
- [fullName](#fullname)
|
|
26
|
+
- [phrase](#phrase)
|
|
27
|
+
- [sentence](#sentence)
|
|
27
28
|
|
|
28
29
|
Numbers:
|
|
29
30
|
- [number](#number)
|
|
@@ -120,7 +121,7 @@ Options:
|
|
|
120
121
|
| ------------------------ | ---- |------------ |
|
|
121
122
|
|set|[RandexSet](#randexset) | Defined chars|
|
|
122
123
|
|charRange|`string`| Range or custom chars |
|
|
123
|
-
|length|[
|
|
124
|
+
|length|[RandexNumberRange](#randexnumberrange) | Length of chars |
|
|
124
125
|
|
|
125
126
|
## word
|
|
126
127
|
|
|
@@ -161,43 +162,7 @@ Randex.word("french", 10);
|
|
|
161
162
|
Options:
|
|
162
163
|
| Name | Type| Description|
|
|
163
164
|
| ------------------------ | ---- |------------ |
|
|
164
|
-
|length|[
|
|
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] |
|
|
165
|
+
|length|[RandexNumberRange](#randexnumberrange) | Length of chars. Default: [2,10] |
|
|
201
166
|
|alphabet|[RandexAlphabet](#randexalphabet) | Defined alphabet. Default: `english` |
|
|
202
167
|
|
|
203
168
|
## fileName
|
|
@@ -243,8 +208,8 @@ Randex.fileName(8, "xml");
|
|
|
243
208
|
Options:
|
|
244
209
|
| Name | Type| Description|
|
|
245
210
|
| ------------------------ | ---- |------------ |
|
|
246
|
-
|fileNameLength|[
|
|
247
|
-
|extensionLength|[
|
|
211
|
+
|fileNameLength|[RandexNumberRange](#randexnumberrange) | Length of file name (not including extension). Default: [3,10] |
|
|
212
|
+
|extensionLength|[RandexNumberRange](#randexnumberrange) | Length of extension (not including file name) chars. Default: [2,5] |
|
|
248
213
|
|extension| `string`| File extension. |
|
|
249
214
|
|
|
250
215
|
## username
|
|
@@ -274,7 +239,7 @@ Randex.username([2, 5]);
|
|
|
274
239
|
Options:
|
|
275
240
|
| Name | Type| Description|
|
|
276
241
|
| ------------------------ | ---- |------------ |
|
|
277
|
-
|length|[
|
|
242
|
+
|length|[RandexNumberRange](#randexnumberrange) | Length of chars. Default: [6,10] |
|
|
278
243
|
|
|
279
244
|
## email
|
|
280
245
|
|
|
@@ -317,9 +282,9 @@ randomEmail("test.com");
|
|
|
317
282
|
Options:
|
|
318
283
|
| Name | Type| Description|
|
|
319
284
|
| ------------------------ | ---- |------------ |
|
|
320
|
-
|prefixLength|[
|
|
321
|
-
|hightDomainLength|[
|
|
322
|
-
|lowDomainLength|[
|
|
285
|
+
|prefixLength|[RandexNumberRange](#randexnumberrange) | Length of email prefix (chars before `@`). Default: [6, 10] |
|
|
286
|
+
|hightDomainLength|[RandexNumberRange](#randexnumberrange) | Length of hight domain part (example: test.<b>com</b>). Default: [1,6] |
|
|
287
|
+
|lowDomainLength|[RandexNumberRange](#randexnumberrange) | Length of low domain part (example: <b>test</b>.com). Default: [4,2] |
|
|
323
288
|
|domain| `string`| Defined domain. |
|
|
324
289
|
|
|
325
290
|
## singleName
|
|
@@ -361,7 +326,7 @@ Randex.singleName("french", 10);
|
|
|
361
326
|
Options:
|
|
362
327
|
| Name | Type| Description|
|
|
363
328
|
| ------------------------ | ---- |------------ |
|
|
364
|
-
|length|[
|
|
329
|
+
|length|[RandexNumberRange](#randexnumberrange) | Length of chars. Default: [2,10] |
|
|
365
330
|
|alphabet|[RandexAlphabet](#randexalphabet) | Defined alphabet. Default: `english` |
|
|
366
331
|
|
|
367
332
|
## fullName
|
|
@@ -379,8 +344,81 @@ Randex.fullName();
|
|
|
379
344
|
Options:
|
|
380
345
|
| Name | Type| Description|
|
|
381
346
|
| ------------------------ | ---- |------------ |
|
|
382
|
-
|firstLength|[
|
|
383
|
-
|secondLength|[
|
|
347
|
+
|firstLength|[RandexNumberRange](#randexnumberrange) | First name length of chars. Default: [2, 10] |
|
|
348
|
+
|secondLength|[RandexNumberRange](#randexnumberrange) | Second name length of chars. Default: [2,10] |
|
|
349
|
+
|alphabet|[RandexAlphabet](#randexalphabet) | Defined alphabet. Default: `english` |
|
|
350
|
+
|
|
351
|
+
## phrase
|
|
352
|
+
|
|
353
|
+
Randoms a phrase.
|
|
354
|
+
|
|
355
|
+
```ts
|
|
356
|
+
import Randex from "randex";
|
|
357
|
+
|
|
358
|
+
// default word range is from 2 to 9
|
|
359
|
+
Randex.phrase();
|
|
360
|
+
// te vdancy poluwsd sswl aqxq
|
|
361
|
+
|
|
362
|
+
// with 5 words
|
|
363
|
+
Randex.v({ words: 5 });
|
|
364
|
+
// or:
|
|
365
|
+
Randex.sentence(5);
|
|
366
|
+
// wyfb hnhtl ptn shemiukme poyyjtr
|
|
367
|
+
|
|
368
|
+
// with words range
|
|
369
|
+
Randex.sentence({ words: [3, 6] });
|
|
370
|
+
// or:
|
|
371
|
+
Randex.sentence([3, 6]);
|
|
372
|
+
// nfob xcwg tmhfu hiqonw
|
|
373
|
+
|
|
374
|
+
// with french alphabet
|
|
375
|
+
Randex.sentence({ alphabet: "french" });
|
|
376
|
+
// or:
|
|
377
|
+
Randex.sentence("french");
|
|
378
|
+
// æeâoô déèbfûûæ aôç udôûsèqpa ygyïœùuè oê
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
Options:
|
|
382
|
+
| Name | Type| Description|
|
|
383
|
+
| ------------------------ | ---- |------------ |
|
|
384
|
+
|words|[RandexNumberRange](#randexnumberrange) | A number or range of words. Default: [2,9] |
|
|
385
|
+
|alphabet|[RandexAlphabet](#randexalphabet) | Defined alphabet. Default: `english` |
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
## sentence
|
|
389
|
+
|
|
390
|
+
Randoms a sentence.
|
|
391
|
+
|
|
392
|
+
```ts
|
|
393
|
+
import Randex from "randex";
|
|
394
|
+
|
|
395
|
+
// default word range is from 3 to 15
|
|
396
|
+
Randex.sentence();
|
|
397
|
+
// Gpgowb te vdancy poluwsd sswl aqxq.
|
|
398
|
+
|
|
399
|
+
// with 5 words
|
|
400
|
+
Randex.sentence({ words: 5 });
|
|
401
|
+
// or:
|
|
402
|
+
Randex.sentence(5);
|
|
403
|
+
// Xja wyfbhnhtl ptn shemiukme poyyjtr.
|
|
404
|
+
|
|
405
|
+
// with words range
|
|
406
|
+
Randex.sentence({ words: [3, 6] });
|
|
407
|
+
// or:
|
|
408
|
+
Randex.sentence([3, 6]);
|
|
409
|
+
// Vg nfobxcwg tmhfu hiqonw.
|
|
410
|
+
|
|
411
|
+
// with french alphabet
|
|
412
|
+
Randex.sentence({ alphabet: "french" });
|
|
413
|
+
// or:
|
|
414
|
+
Randex.sentence("french");
|
|
415
|
+
// Ê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.
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
Options:
|
|
419
|
+
| Name | Type| Description|
|
|
420
|
+
| ------------------------ | ---- |------------ |
|
|
421
|
+
|words|[RandexNumberRange](#randexnumberrange) | A number or range of words. Default: [3,15] |
|
|
384
422
|
|alphabet|[RandexAlphabet](#randexalphabet) | Defined alphabet. Default: `english` |
|
|
385
423
|
|
|
386
424
|
|
|
@@ -413,6 +451,9 @@ import Randex from "randex";
|
|
|
413
451
|
// Generates three words with english alphabet.
|
|
414
452
|
Randex.many(3).word("english");
|
|
415
453
|
|
|
454
|
+
// Generates seven phrases with english alphabet.
|
|
455
|
+
Randex.many(7).phrase("english");
|
|
456
|
+
|
|
416
457
|
// Generates five sentences with french alphabet.
|
|
417
458
|
Randex.many(5).sentence("french");
|
|
418
459
|
|
|
@@ -520,7 +561,7 @@ Randex.random(
|
|
|
520
561
|
|
|
521
562
|
## Types
|
|
522
563
|
|
|
523
|
-
###
|
|
564
|
+
### RandexNumberRange
|
|
524
565
|
|
|
525
566
|
Possible types:
|
|
526
567
|
|
package/lib/basic/const.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const DEFAULT_WORD_RANGE:
|
|
3
|
-
export declare const DEFAULT_SENTENCE_RANGE:
|
|
1
|
+
import { RandexNumberRange } from "../interfaces";
|
|
2
|
+
export declare const DEFAULT_WORD_RANGE: RandexNumberRange;
|
|
3
|
+
export declare const DEFAULT_SENTENCE_RANGE: RandexNumberRange;
|
|
4
|
+
export declare const DEFAULT_PHRASE_RANGE: RandexNumberRange;
|
package/lib/basic/const.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_SENTENCE_RANGE = exports.DEFAULT_WORD_RANGE = void 0;
|
|
3
|
+
exports.DEFAULT_PHRASE_RANGE = exports.DEFAULT_SENTENCE_RANGE = exports.DEFAULT_WORD_RANGE = void 0;
|
|
4
4
|
exports.DEFAULT_WORD_RANGE = [2, 10];
|
|
5
5
|
exports.DEFAULT_SENTENCE_RANGE = [3, 15];
|
|
6
|
+
exports.DEFAULT_PHRASE_RANGE = [2, 9];
|
package/lib/basic/set.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { RandexSet,
|
|
1
|
+
import { RandexSet, RandexNumberRange } from "../interfaces";
|
|
2
2
|
export declare class RandexSetUtil {
|
|
3
|
-
static readonly defaultFileNameLength:
|
|
4
|
-
static readonly defaultExtensionLength:
|
|
3
|
+
static readonly defaultFileNameLength: RandexNumberRange;
|
|
4
|
+
static readonly defaultExtensionLength: RandexNumberRange;
|
|
5
5
|
static readonly fileNameExtraChars = "";
|
|
6
|
-
static readonly defaultEmailPrefixLength:
|
|
7
|
-
static readonly defaultHightDomainEmailLength:
|
|
8
|
-
static readonly defaultLowDomainEmailLength:
|
|
6
|
+
static readonly defaultEmailPrefixLength: RandexNumberRange;
|
|
7
|
+
static readonly defaultHightDomainEmailLength: RandexNumberRange;
|
|
8
|
+
static readonly defaultLowDomainEmailLength: RandexNumberRange;
|
|
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:
|
|
13
|
+
static getLength(reservedChars: number, length: RandexNumberRange | undefined, defaultLength: RandexNumberRange): RandexNumberRange;
|
|
14
14
|
static randomSingleNumber(length: number): number;
|
|
15
15
|
static randomRangeNumber(min: number, max: number): number;
|
|
16
|
-
static many<TItem>(count:
|
|
16
|
+
static many<TItem>(count: RandexNumberRange, callback: () => TItem): TItem[];
|
|
17
17
|
}
|
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, RandexNumberRange } 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 RandexNumberRange;
|
|
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, RandexNumberRange } from "../interfaces";
|
|
2
2
|
export declare function randexEmail(options?: RandexEmailOptions): string;
|
|
3
|
-
export declare function randexEmail(prefixLength:
|
|
3
|
+
export declare function randexEmail(prefixLength: RandexNumberRange, lowDomainLength?: RandexNumberRange, hightDomainLength?: RandexNumberRange): string;
|
|
4
4
|
export declare function randexEmail(domain: string): string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { RandexFileNameOptions,
|
|
1
|
+
import { RandexFileNameOptions, RandexNumberRange } 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: RandexNumberRange, extensionLength?: RandexNumberRange): string;
|
|
4
|
+
export declare function randexFileName(fileNameLength: RandexNumberRange, extension: string): string;
|
|
5
5
|
export declare function randexFileName(extension: string): string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { RandexAlphabet, RandexFullNameOptions,
|
|
1
|
+
import { RandexAlphabet, RandexFullNameOptions, RandexNumberRange } from "../interfaces";
|
|
2
2
|
export declare function randexFullName(options?: RandexFullNameOptions): string;
|
|
3
|
-
export declare function randexFullName(length:
|
|
3
|
+
export declare function randexFullName(length: RandexNumberRange): 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: RandexNumberRange): string;
|
|
6
|
+
export declare function randexFullName(alphabet: RandexAlphabet, firstLength: RandexNumberRange, secondLength: RandexNumberRange): string;
|
package/lib/custom/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RandexNumberRange } 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
|
+
import { randexPhrase } from "./phrase";
|
|
7
8
|
import { randexRandom } from "./random";
|
|
8
9
|
import { randexSentence } from "./sentence";
|
|
9
10
|
import { randexSingleName } from "./singleName";
|
|
@@ -23,21 +24,28 @@ export declare class Randex {
|
|
|
23
24
|
static username: typeof randexUsername;
|
|
24
25
|
static word: typeof randexWord;
|
|
25
26
|
static sentence: typeof randexSentence;
|
|
26
|
-
static
|
|
27
|
+
static phrase: typeof randexPhrase;
|
|
28
|
+
static many(count: RandexNumberRange): {
|
|
27
29
|
word: {
|
|
28
30
|
(options?: import("../interfaces").RandexWordOptions | undefined): string[];
|
|
29
|
-
(length:
|
|
31
|
+
(length: RandexNumberRange): string[];
|
|
30
32
|
(alphabet?: import("../interfaces").RandexAlphabet | undefined): string[];
|
|
31
|
-
(alphabet: import("../interfaces").RandexAlphabet, length:
|
|
33
|
+
(alphabet: import("../interfaces").RandexAlphabet, length: RandexNumberRange): string[];
|
|
34
|
+
};
|
|
35
|
+
phrase: {
|
|
36
|
+
(options?: import("../interfaces").RandexPhraseOptions | undefined): string[];
|
|
37
|
+
(words: RandexNumberRange): string[];
|
|
38
|
+
(alphabet?: import("../interfaces").RandexAlphabet | undefined): string[];
|
|
39
|
+
(alphabet: import("../interfaces").RandexAlphabet, words: RandexNumberRange): string[];
|
|
32
40
|
};
|
|
33
41
|
sentence: {
|
|
34
42
|
(options?: import("../interfaces").RandexSentenceOptions | undefined): string[];
|
|
35
|
-
(
|
|
43
|
+
(words: RandexNumberRange): string[];
|
|
36
44
|
(alphabet?: import("../interfaces").RandexAlphabet | undefined): string[];
|
|
37
|
-
(alphabet: import("../interfaces").RandexAlphabet,
|
|
45
|
+
(alphabet: import("../interfaces").RandexAlphabet, words: RandexNumberRange): string[];
|
|
38
46
|
};
|
|
39
47
|
number: {
|
|
40
|
-
(length:
|
|
48
|
+
(length: RandexNumberRange, options?: import("../interfaces").RandomNumberOptions | undefined): number[];
|
|
41
49
|
(from: number, to: number, options?: import("../interfaces").RandomNumberOptions | undefined): number[];
|
|
42
50
|
};
|
|
43
51
|
};
|
package/lib/custom/index.js
CHANGED
|
@@ -6,6 +6,7 @@ var email_1 = require("./email");
|
|
|
6
6
|
var filenameX_1 = require("./filenameX");
|
|
7
7
|
var fullnameX_1 = require("./fullnameX");
|
|
8
8
|
var number_1 = require("./number");
|
|
9
|
+
var phrase_1 = require("./phrase");
|
|
9
10
|
var random_1 = require("./random");
|
|
10
11
|
var sentence_1 = require("./sentence");
|
|
11
12
|
var singleName_1 = require("./singleName");
|
|
@@ -44,7 +45,7 @@ var Randex = /** @class */ (function () {
|
|
|
44
45
|
return result;
|
|
45
46
|
};
|
|
46
47
|
Randex.many = function (count) {
|
|
47
|
-
return { word: (0, word_1.randexManyWord)(count), sentence: (0, sentence_1.randexManySentence)(count), number: (0, number_1.randexManyNumber)(count) };
|
|
48
|
+
return { word: (0, word_1.randexManyWord)(count), phrase: (0, phrase_1.randexManyPhrase)(count), sentence: (0, sentence_1.randexManySentence)(count), number: (0, number_1.randexManyNumber)(count) };
|
|
48
49
|
};
|
|
49
50
|
Randex.random = random_1.randexRandom;
|
|
50
51
|
Randex.bool = bool_1.randexBool;
|
|
@@ -56,6 +57,7 @@ var Randex = /** @class */ (function () {
|
|
|
56
57
|
Randex.username = username_1.randexUsername;
|
|
57
58
|
Randex.word = word_1.randexWord;
|
|
58
59
|
Randex.sentence = sentence_1.randexSentence;
|
|
60
|
+
Randex.phrase = phrase_1.randexPhrase;
|
|
59
61
|
return Randex;
|
|
60
62
|
}());
|
|
61
63
|
exports.Randex = Randex;
|
package/lib/custom/number.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function randexNumber(length:
|
|
1
|
+
import { RandexNumberRange, RandomNumberOptions } from "../interfaces";
|
|
2
|
+
export declare function randexNumber(length: RandexNumberRange, options?: RandomNumberOptions): number;
|
|
3
3
|
export declare function randexNumber(from: number, to: number, options?: RandomNumberOptions): number;
|
|
4
|
-
export declare function randexManyNumber(count:
|
|
5
|
-
(length:
|
|
4
|
+
export declare function randexManyNumber(count: RandexNumberRange): {
|
|
5
|
+
(length: RandexNumberRange, options?: RandomNumberOptions): number[];
|
|
6
6
|
(from: number, to: number, options?: RandomNumberOptions): number[];
|
|
7
7
|
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { RandexAlphabet, RandexNumberRange, RandexPhraseOptions } from "../interfaces";
|
|
2
|
+
export declare function randexPhrase(options?: RandexPhraseOptions): string;
|
|
3
|
+
export declare function randexPhrase(words: RandexNumberRange): string;
|
|
4
|
+
export declare function randexPhrase(alphabet?: RandexAlphabet): string;
|
|
5
|
+
export declare function randexPhrase(alphabet: RandexAlphabet, words: RandexNumberRange): string;
|
|
6
|
+
export declare function randexManyPhrase(count: RandexNumberRange): {
|
|
7
|
+
(options?: RandexPhraseOptions): string[];
|
|
8
|
+
(words: RandexNumberRange): string[];
|
|
9
|
+
(alphabet?: RandexAlphabet): string[];
|
|
10
|
+
(alphabet: RandexAlphabet, words: RandexNumberRange): string[];
|
|
11
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.randexManyPhrase = exports.randexPhrase = 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 randexPhrase(p1, p2) {
|
|
9
|
+
var length = const_1.DEFAULT_PHRASE_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.words) {
|
|
26
|
+
length = options.words;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
var words = (0, word_1.randexManyWord)(length)(alphabet);
|
|
30
|
+
return words.join(" ");
|
|
31
|
+
}
|
|
32
|
+
exports.randexPhrase = randexPhrase;
|
|
33
|
+
function randexManyPhrase(count) {
|
|
34
|
+
function many(p1, p2) {
|
|
35
|
+
return set_1.RandexSetUtil.many(count, function () { return randexPhrase(p1, p2); });
|
|
36
|
+
}
|
|
37
|
+
return many;
|
|
38
|
+
}
|
|
39
|
+
exports.randexManyPhrase = randexManyPhrase;
|
package/lib/custom/sentence.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { RandexAlphabet,
|
|
1
|
+
import { RandexAlphabet, RandexNumberRange, RandexSentenceOptions } from "../interfaces";
|
|
2
2
|
export declare function randexSentence(options?: RandexSentenceOptions): string;
|
|
3
|
-
export declare function randexSentence(length:
|
|
3
|
+
export declare function randexSentence(length: RandexNumberRange): string;
|
|
4
4
|
export declare function randexSentence(alphabet?: RandexAlphabet): string;
|
|
5
|
-
export declare function randexSentence(alphabet: RandexAlphabet, length:
|
|
6
|
-
export declare function randexManySentence(count:
|
|
5
|
+
export declare function randexSentence(alphabet: RandexAlphabet, length: RandexNumberRange): string;
|
|
6
|
+
export declare function randexManySentence(count: RandexNumberRange): {
|
|
7
7
|
(options?: RandexSentenceOptions): string[];
|
|
8
|
-
(
|
|
8
|
+
(words: RandexNumberRange): string[];
|
|
9
9
|
(alphabet?: RandexAlphabet): string[];
|
|
10
|
-
(alphabet: RandexAlphabet,
|
|
10
|
+
(alphabet: RandexAlphabet, words: RandexNumberRange): string[];
|
|
11
11
|
};
|
package/lib/custom/sentence.js
CHANGED
|
@@ -22,8 +22,8 @@ function randexSentence(p1, p2) {
|
|
|
22
22
|
if (options.alphabet) {
|
|
23
23
|
alphabet = options.alphabet;
|
|
24
24
|
}
|
|
25
|
-
if (options.
|
|
26
|
-
length = options.
|
|
25
|
+
if (options.words) {
|
|
26
|
+
length = options.words;
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
var words = (0, word_1.randexManyWord)(length)(alphabet);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { RandexAlphabet,
|
|
1
|
+
import { RandexAlphabet, RandexNumberRange, RandexWordOptions } from "../interfaces";
|
|
2
2
|
export declare function randexSingleName(options?: RandexWordOptions): string;
|
|
3
|
-
export declare function randexSingleName(length:
|
|
3
|
+
export declare function randexSingleName(length: RandexNumberRange): 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: RandexNumberRange): string;
|
package/lib/custom/username.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function randexUsername(options?: RandexUsernameOptions |
|
|
1
|
+
import { RandexNumberRange, RandexUsernameOptions } from "../interfaces";
|
|
2
|
+
export declare function randexUsername(options?: RandexUsernameOptions | RandexNumberRange): string;
|
package/lib/custom/word.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { RandexAlphabet,
|
|
1
|
+
import { RandexAlphabet, RandexNumberRange, RandexWordOptions } from "../interfaces";
|
|
2
2
|
export declare function randexWord(options?: RandexWordOptions): string;
|
|
3
|
-
export declare function randexWord(length:
|
|
3
|
+
export declare function randexWord(length: RandexNumberRange): 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: RandexNumberRange): string;
|
|
6
|
+
export declare function randexManyWord(count: RandexNumberRange): {
|
|
7
7
|
(options?: RandexWordOptions): string[];
|
|
8
|
-
(length:
|
|
8
|
+
(length: RandexNumberRange): string[];
|
|
9
9
|
(alphabet?: RandexAlphabet): string[];
|
|
10
|
-
(alphabet: RandexAlphabet, length:
|
|
10
|
+
(alphabet: RandexAlphabet, length: RandexNumberRange): string[];
|
|
11
11
|
};
|
package/lib/interfaces/base.d.ts
CHANGED
|
@@ -4,11 +4,11 @@ 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 RandexNumberRange = number | [number, number];
|
|
8
8
|
interface RandexItemBasicOptions {
|
|
9
9
|
set?: RandexSet;
|
|
10
10
|
charRange?: string;
|
|
11
|
-
length?:
|
|
11
|
+
length?: RandexNumberRange;
|
|
12
12
|
}
|
|
13
13
|
export interface RandexContentSetOptions extends Omit<RandexItemBasicOptions, "set"> {
|
|
14
14
|
set: RandexSet;
|
|
@@ -16,6 +16,6 @@ export interface RandexContentSetOptions extends Omit<RandexItemBasicOptions, "s
|
|
|
16
16
|
export interface RandexContentRangeOptions extends Omit<RandexItemBasicOptions, "charRange"> {
|
|
17
17
|
charRange: string;
|
|
18
18
|
}
|
|
19
|
-
export type RandexContentArrayOptions = [RandexSet, string |
|
|
19
|
+
export type RandexContentArrayOptions = [RandexSet, string | RandexNumberRange] | [RandexSet, string, RandexNumberRange];
|
|
20
20
|
export type RandexContentOptions = RandexContentSetOptions | RandexContentRangeOptions | RandexContentArrayOptions | RandexSet;
|
|
21
21
|
export {};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RandexNumberRange } from "./base";
|
|
2
2
|
interface BasicEmailOptions {
|
|
3
|
-
prefixLength?:
|
|
3
|
+
prefixLength?: RandexNumberRange;
|
|
4
4
|
}
|
|
5
5
|
interface DomainLengthEmailOptions {
|
|
6
|
-
hightDomainLength?:
|
|
7
|
-
lowDomainLength?:
|
|
6
|
+
hightDomainLength?: RandexNumberRange;
|
|
7
|
+
lowDomainLength?: RandexNumberRange;
|
|
8
8
|
}
|
|
9
9
|
interface DomainEmailOptions {
|
|
10
10
|
domain?: string;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RandexNumberRange } from "./base";
|
|
2
2
|
interface BasicFileNameOptions {
|
|
3
|
-
fileNameLength?:
|
|
3
|
+
fileNameLength?: RandexNumberRange;
|
|
4
4
|
}
|
|
5
5
|
interface ExtensionLengthFileNameOptions {
|
|
6
|
-
extensionLength?:
|
|
6
|
+
extensionLength?: RandexNumberRange;
|
|
7
7
|
}
|
|
8
8
|
interface ExtensionFileNameOptions {
|
|
9
9
|
extension?: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { RandexAlphabet,
|
|
1
|
+
import { RandexAlphabet, RandexNumberRange } from "./base";
|
|
2
2
|
export interface RandexFullNameOptions {
|
|
3
3
|
alphabet?: RandexAlphabet;
|
|
4
|
-
firstLength?:
|
|
5
|
-
secondLength?:
|
|
4
|
+
firstLength?: RandexNumberRange;
|
|
5
|
+
secondLength?: RandexNumberRange;
|
|
6
6
|
}
|
package/lib/interfaces/index.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export interface RandexSentenceOptions {
|
|
3
|
-
alphabet?: RandexAlphabet;
|
|
4
|
-
wordRange?: RandexRange;
|
|
1
|
+
import { RandexPhraseOptions } from "./phrase";
|
|
2
|
+
export interface RandexSentenceOptions extends RandexPhraseOptions {
|
|
5
3
|
}
|
package/lib/interfaces/word.d.ts
CHANGED
|
@@ -33,7 +33,7 @@ describe("random many number", function () {
|
|
|
33
33
|
value = custom_1.Randex.many(count + 10).number([min, max]);
|
|
34
34
|
expect(value.length).toBe(count + 10);
|
|
35
35
|
});
|
|
36
|
-
it("range: fill all possible values", function () {
|
|
36
|
+
it.skip("range: fill all possible values", function () {
|
|
37
37
|
var min = 5;
|
|
38
38
|
var max = 10;
|
|
39
39
|
var count = max - min + 1;
|
|
@@ -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("phrase", function () {
|
|
6
|
+
it("default", function () {
|
|
7
|
+
test_util_1.TestUtil.loop(function () {
|
|
8
|
+
var text = custom_1.Randex.phrase();
|
|
9
|
+
expect(test_util_1.TestUtil.isPhraseValid(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.phrase(range);
|
|
16
|
+
expect(test_util_1.TestUtil.isPhraseValid(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.phrase(range);
|
|
23
|
+
expect(test_util_1.TestUtil.isPhraseValid(text, range)).toBeTruthy();
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
it("many", function () {
|
|
27
|
+
var count = 5;
|
|
28
|
+
var phrases = custom_1.Randex.many(count).phrase();
|
|
29
|
+
for (var i = 0; i < count; i++) {
|
|
30
|
+
expect(test_util_1.TestUtil.isPhraseValid(phrases[i])).toBeTruthy();
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
});
|
package/lib/test/test-util.d.ts
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RandexNumberRange, RandexSet } from "../interfaces";
|
|
2
2
|
export declare class TestUtil {
|
|
3
|
-
static testIn(value: string, length:
|
|
3
|
+
static testIn(value: string, length: RandexNumberRange | 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?: RandexNumberRange): void;
|
|
6
|
+
static testInSetRange(value: string, set: RandexSet, range: string, length?: RandexNumberRange): void;
|
|
7
|
+
static testInRange(value: string, range: string, length?: RandexNumberRange): void;
|
|
8
|
+
static testInBoth(value: string, set: RandexSet, range: string, length?: RandexNumberRange): 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(text: string, length?:
|
|
16
|
-
static isSentenceValid(text: string, length?:
|
|
17
|
-
static
|
|
18
|
-
static
|
|
15
|
+
static isWordValid(text: string, length?: RandexNumberRange): RegExpMatchArray | null;
|
|
16
|
+
static isSentenceValid(text: string, length?: RandexNumberRange): boolean;
|
|
17
|
+
static isPhraseValid(text: string, length?: RandexNumberRange): boolean;
|
|
18
|
+
static isUpperCharValid(value: string, length?: RandexNumberRange): RegExpMatchArray | null;
|
|
19
|
+
static isLowerCharValid(value: string, length?: RandexNumberRange): RegExpMatchArray | null;
|
|
19
20
|
static isFullNameValid(email: string): RegExpMatchArray | null;
|
|
20
21
|
static isFileNameValid(email: string): RegExpMatchArray | null;
|
|
21
22
|
static inNumberRange(value: number, range: [number, number]): boolean;
|
package/lib/test/test-util.js
CHANGED
|
@@ -94,6 +94,17 @@ var TestUtil = /** @class */ (function () {
|
|
|
94
94
|
return splits.length === length;
|
|
95
95
|
}
|
|
96
96
|
};
|
|
97
|
+
TestUtil.isPhraseValid = function (text, length) {
|
|
98
|
+
if (length === void 0) { length = const_1.DEFAULT_PHRASE_RANGE; }
|
|
99
|
+
var splits = text.split(" ");
|
|
100
|
+
if (Array.isArray(length)) {
|
|
101
|
+
var min = length[0], max = length[1];
|
|
102
|
+
return splits.length >= min && splits.length <= max;
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
return splits.length === length;
|
|
106
|
+
}
|
|
107
|
+
};
|
|
97
108
|
TestUtil.isUpperCharValid = function (value, length) {
|
|
98
109
|
if (length === void 0) { length = 1; }
|
|
99
110
|
var l = TestUtil.getLength(length);
|