randex 0.26.0 → 0.28.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 +80 -45
- 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 +14 -6
- package/lib/custom/index.js +4 -2
- package/lib/custom/number.d.ts +2 -2
- package/lib/custom/number.js +1 -1
- package/lib/custom/random.js +2 -2
- 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 +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/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/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/README.md
CHANGED
|
@@ -17,12 +17,13 @@ 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)
|
|
@@ -118,6 +119,84 @@ Options:
|
|
|
118
119
|
|range|`string`| Range or custom chars |
|
|
119
120
|
|length|[RandexLength](#randexlength) | Length of chars |
|
|
120
121
|
|
|
122
|
+
## word
|
|
123
|
+
|
|
124
|
+
Randoms a simple word.
|
|
125
|
+
|
|
126
|
+
```ts
|
|
127
|
+
import Randex from "randex";
|
|
128
|
+
|
|
129
|
+
// default
|
|
130
|
+
Randex.word();
|
|
131
|
+
// kpmld
|
|
132
|
+
|
|
133
|
+
// with length 5 chars
|
|
134
|
+
Randex.word({ length: 5 });
|
|
135
|
+
// or short:
|
|
136
|
+
Randex.word(5);
|
|
137
|
+
// imphs
|
|
138
|
+
|
|
139
|
+
// with 2 min and 5 max chars
|
|
140
|
+
Randex.word({ length: [2, 5] });
|
|
141
|
+
// or short:
|
|
142
|
+
Randex.word([2, 5]);
|
|
143
|
+
// kslg
|
|
144
|
+
|
|
145
|
+
// name from french alphabet
|
|
146
|
+
Randex.word({ alphabet: "french" });
|
|
147
|
+
// or short:
|
|
148
|
+
Randex.word("french");
|
|
149
|
+
// dbïœ
|
|
150
|
+
|
|
151
|
+
// name from french alphabet with length
|
|
152
|
+
Randex.word({ alphabet: "french", length: 10 });
|
|
153
|
+
// or short:
|
|
154
|
+
Randex.word("french", 10);
|
|
155
|
+
// rsîrjhjôôw
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Options:
|
|
159
|
+
| Name | Type| Description|
|
|
160
|
+
| ------------------------ | ---- |------------ |
|
|
161
|
+
|length|[RandexLength](#randexlength) | Length of chars. Default: [2,10] |
|
|
162
|
+
|alphabet|[RandexAlphabet](#randexalphabet) | Defined alphabet. Default: `english` |
|
|
163
|
+
|
|
164
|
+
## sentence
|
|
165
|
+
|
|
166
|
+
Randoms a sentence.
|
|
167
|
+
|
|
168
|
+
```ts
|
|
169
|
+
import Randex from "randex";
|
|
170
|
+
|
|
171
|
+
// default word range is from 3 to 15
|
|
172
|
+
Randex.sentence();
|
|
173
|
+
// Gpgowb te vdancy poluwsd sswl aqxq.
|
|
174
|
+
|
|
175
|
+
// with length 5 chars
|
|
176
|
+
Randex.sentence({ wordRange: 5 });
|
|
177
|
+
// or:
|
|
178
|
+
Randex.sentence(5);
|
|
179
|
+
// Xja wyfbhnhtl ptn shemiukme poyyjtr.
|
|
180
|
+
|
|
181
|
+
// with word range
|
|
182
|
+
Randex.sentence({ wordRange: [3, 6] });
|
|
183
|
+
// or:
|
|
184
|
+
Randex.sentence([3, 6]);
|
|
185
|
+
// Vg nfobxcwg tmhfu hiqonw.
|
|
186
|
+
|
|
187
|
+
// name from french alphabet
|
|
188
|
+
Randex.sentence({ alphabet: "french" });
|
|
189
|
+
// or:
|
|
190
|
+
Randex.sentence("french");
|
|
191
|
+
// Ê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.
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
Options:
|
|
195
|
+
| Name | Type| Description|
|
|
196
|
+
| ------------------------ | ---- |------------ |
|
|
197
|
+
|length|[RandexLength](#randexlength) | Length of chars. Default: [2,10] |
|
|
198
|
+
|alphabet|[RandexAlphabet](#randexalphabet) | Defined alphabet. Default: `english` |
|
|
199
|
+
|
|
121
200
|
## fileName
|
|
122
201
|
|
|
123
202
|
Randoms file name.
|
|
@@ -302,50 +381,6 @@ Options:
|
|
|
302
381
|
|alphabet|[RandexAlphabet](#randexalphabet) | Defined alphabet. Default: `english` |
|
|
303
382
|
|
|
304
383
|
|
|
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
384
|
## number
|
|
350
385
|
|
|
351
386
|
Generates random number from a range of numbers.
|
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,23 @@ export declare class Randex {
|
|
|
18
19
|
static fileName: typeof randexFileName;
|
|
19
20
|
static fullName: typeof randexFullName;
|
|
20
21
|
static singleName: typeof randexSingleName;
|
|
21
|
-
static
|
|
22
|
-
static numberArray(length: RandexLength, count: number): number[];
|
|
22
|
+
static numberArray(length: RandexRange, count: number): number[];
|
|
23
23
|
static number: typeof randexNumber;
|
|
24
24
|
static username: typeof randexUsername;
|
|
25
|
-
static
|
|
25
|
+
static word: typeof randexWord;
|
|
26
|
+
static sentence: typeof randexSentence;
|
|
27
|
+
static many(count: RandexRange): {
|
|
26
28
|
word: {
|
|
27
29
|
(options?: import("../interfaces").RandexWordOptions | undefined): string[];
|
|
28
|
-
(length:
|
|
30
|
+
(length: RandexRange): string[];
|
|
31
|
+
(alphabet?: import("../interfaces").RandexAlphabet | undefined): string[];
|
|
32
|
+
(alphabet: import("../interfaces").RandexAlphabet, length: RandexRange): string[];
|
|
33
|
+
};
|
|
34
|
+
sentence: {
|
|
35
|
+
(options?: import("../interfaces").RandexSentenceOptions | undefined): string[];
|
|
36
|
+
(length: RandexRange): string[];
|
|
29
37
|
(alphabet?: import("../interfaces").RandexAlphabet | undefined): string[];
|
|
30
|
-
(alphabet: import("../interfaces").RandexAlphabet, length:
|
|
38
|
+
(alphabet: import("../interfaces").RandexAlphabet, length: RandexRange): string[];
|
|
31
39
|
};
|
|
32
40
|
};
|
|
33
41
|
}
|
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");
|
|
@@ -68,7 +69,7 @@ var Randex = /** @class */ (function () {
|
|
|
68
69
|
return result;
|
|
69
70
|
};
|
|
70
71
|
Randex.many = function (count) {
|
|
71
|
-
return { word: (0, word_1.randexManyWord)(count) };
|
|
72
|
+
return { word: (0, word_1.randexManyWord)(count), sentence: (0, sentence_1.randexManySentence)(count) };
|
|
72
73
|
};
|
|
73
74
|
Randex.random = random_1.randexRandom;
|
|
74
75
|
Randex.bool = bool_1.randexBool;
|
|
@@ -76,9 +77,10 @@ var Randex = /** @class */ (function () {
|
|
|
76
77
|
Randex.fileName = filenameX_1.randexFileName;
|
|
77
78
|
Randex.fullName = fullnameX_1.randexFullName;
|
|
78
79
|
Randex.singleName = singleName_1.randexSingleName;
|
|
79
|
-
Randex.word = word_1.randexWord;
|
|
80
80
|
Randex.number = number_1.randexNumber;
|
|
81
81
|
Randex.username = username_1.randexUsername;
|
|
82
|
+
Randex.word = word_1.randexWord;
|
|
83
|
+
Randex.sentence = sentence_1.randexSentence;
|
|
82
84
|
return Randex;
|
|
83
85
|
}());
|
|
84
86
|
exports.Randex = Randex;
|
package/lib/custom/number.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
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;
|
package/lib/custom/number.js
CHANGED
|
@@ -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
|
}
|
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
|
}
|
|
@@ -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,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 RandexRange = number | [number, number];
|
|
8
8
|
interface RandexItemBasicOptions {
|
|
9
9
|
set?: RandexSet;
|
|
10
10
|
range?: string;
|
|
11
|
-
length?:
|
|
11
|
+
length?: RandexRange;
|
|
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, "range"> {
|
|
17
17
|
range: 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
|
@@ -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
|
});
|