randex 0.23.0 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -0
- package/lib/custom/index.d.ts +7 -3
- package/lib/custom/index.js +23 -1
- package/lib/custom/{singleName.d.ts → word.d.ts} +1 -1
- package/lib/test/test-util.d.ts +2 -0
- package/lib/test/test-util.js +10 -2
- package/lib/test/word.test.d.ts +1 -0
- package/lib/test/word.test.js +12 -0
- package/package.json +1 -1
- /package/lib/custom/{singleName.js → word.js} +0 -0
package/README.md
CHANGED
|
@@ -22,6 +22,7 @@ Strings:
|
|
|
22
22
|
- [email](#email)
|
|
23
23
|
- [singleName](#singlename)
|
|
24
24
|
- [fullName](#fullname)
|
|
25
|
+
- [word](#word)
|
|
25
26
|
|
|
26
27
|
Numbers:
|
|
27
28
|
- [number](#number)
|
|
@@ -301,6 +302,50 @@ Options:
|
|
|
301
302
|
|alphabet|[RandexAlphabet](#randexalphabet) | Defined alphabet. Default: `english` |
|
|
302
303
|
|
|
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] |
|
|
346
|
+
|alphabet|[RandexAlphabet](#randexalphabet) | Defined alphabet. Default: `english` |
|
|
347
|
+
|
|
348
|
+
|
|
304
349
|
## number
|
|
305
350
|
|
|
306
351
|
Generates random number from a range of numbers.
|
package/lib/custom/index.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { RandexAlphabet, RandexContentOptions, RandexLength } from "../interfaces";
|
|
2
2
|
import { RandexEmailOptions } from "./email";
|
|
3
3
|
import { RandexFileNameOptions } from "./filename";
|
|
4
|
-
import {
|
|
4
|
+
import { RandexWordOptions } from "./word";
|
|
5
5
|
import { RandomNumberOptions } from "./number";
|
|
6
6
|
import { RandexUsernameOptions } from "./username";
|
|
7
7
|
import { RandexFullNameOptions } from "./fullname";
|
|
8
8
|
export * from "./email";
|
|
9
9
|
export * from "./filename";
|
|
10
|
-
export * from "./
|
|
10
|
+
export * from "./word";
|
|
11
11
|
export * from "./username";
|
|
12
12
|
export * from "./fullname";
|
|
13
13
|
export * from "./number";
|
|
@@ -32,10 +32,14 @@ export declare class Randex {
|
|
|
32
32
|
static fullName(alphabet?: RandexAlphabet): any;
|
|
33
33
|
static fullName(alphabet: RandexAlphabet, length: RandexLength): any;
|
|
34
34
|
static fullName(alphabet: RandexAlphabet, firstLength: RandexLength, secondLength: RandexLength): any;
|
|
35
|
-
static singleName(options?:
|
|
35
|
+
static singleName(options?: RandexWordOptions): any;
|
|
36
36
|
static singleName(length: RandexLength): any;
|
|
37
37
|
static singleName(alphabet?: RandexAlphabet): any;
|
|
38
38
|
static singleName(alphabet: RandexAlphabet, length: RandexLength): any;
|
|
39
|
+
static word(options?: RandexWordOptions): any;
|
|
40
|
+
static word(length: RandexLength): any;
|
|
41
|
+
static word(alphabet?: RandexAlphabet): any;
|
|
42
|
+
static word(alphabet: RandexAlphabet, length: RandexLength): any;
|
|
39
43
|
static numberArray(length: RandexLength, count: number): number[];
|
|
40
44
|
private static getNumberBase;
|
|
41
45
|
private static getNumberValue;
|
package/lib/custom/index.js
CHANGED
|
@@ -19,7 +19,7 @@ var set_1 = require("../basic/set");
|
|
|
19
19
|
var type_1 = require("../basic/type");
|
|
20
20
|
__exportStar(require("./email"), exports);
|
|
21
21
|
__exportStar(require("./filename"), exports);
|
|
22
|
-
__exportStar(require("./
|
|
22
|
+
__exportStar(require("./word"), exports);
|
|
23
23
|
__exportStar(require("./username"), exports);
|
|
24
24
|
__exportStar(require("./fullname"), exports);
|
|
25
25
|
__exportStar(require("./number"), exports);
|
|
@@ -260,6 +260,28 @@ var Randex = /** @class */ (function () {
|
|
|
260
260
|
var currentLength = set_1.RandexSetUtil.getLength(1, length, [1, 9]);
|
|
261
261
|
return Randex.random([alphabet, "u"], [[alphabet, "l"], currentLength]);
|
|
262
262
|
};
|
|
263
|
+
Randex.word = function (p1, p2) {
|
|
264
|
+
var length = [2, 10];
|
|
265
|
+
var alphabet = "english";
|
|
266
|
+
if (type_1.RandexTypeParser.isLength(p1)) {
|
|
267
|
+
length = p1;
|
|
268
|
+
}
|
|
269
|
+
else if (type_1.RandexTypeParser.inAlphabet(p1)) {
|
|
270
|
+
alphabet = p1;
|
|
271
|
+
if (type_1.RandexTypeParser.isLength(p2)) {
|
|
272
|
+
length = p2;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
else if (typeof p1 === "object") {
|
|
276
|
+
if (p1.alphabet) {
|
|
277
|
+
alphabet = p1.alphabet;
|
|
278
|
+
}
|
|
279
|
+
if (p1.length) {
|
|
280
|
+
length = p1.length;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return Randex.random([[alphabet, "l"], length]);
|
|
284
|
+
};
|
|
263
285
|
Randex.numberArray = function (length, count) {
|
|
264
286
|
var min = 0;
|
|
265
287
|
var max = 0;
|
package/lib/test/test-util.d.ts
CHANGED
|
@@ -12,9 +12,11 @@ export declare class TestUtil {
|
|
|
12
12
|
static isEmailValid(email: string): RegExpMatchArray | null;
|
|
13
13
|
static isUsernameValid(email: string): RegExpMatchArray | null;
|
|
14
14
|
static isNameValid(email: string): RegExpMatchArray | null;
|
|
15
|
+
static isWordValid(word: string, length?: RandexLength): RegExpMatchArray | null;
|
|
15
16
|
static isUpperCharValid(value: string, length?: RandexLength): RegExpMatchArray | null;
|
|
16
17
|
static isLowerCharValid(value: string, length?: RandexLength): RegExpMatchArray | null;
|
|
17
18
|
static isFullNameValid(email: string): RegExpMatchArray | null;
|
|
18
19
|
static isFileNameValid(email: string): RegExpMatchArray | null;
|
|
19
20
|
static inNumberRange(value: number, range: [number, number]): boolean;
|
|
21
|
+
private static getLength;
|
|
20
22
|
}
|
package/lib/test/test-util.js
CHANGED
|
@@ -77,14 +77,19 @@ var TestUtil = /** @class */ (function () {
|
|
|
77
77
|
TestUtil.isNameValid = function (email) {
|
|
78
78
|
return String(email).match(/^[A-Z][a-z]{1,}$/);
|
|
79
79
|
};
|
|
80
|
+
TestUtil.isWordValid = function (word, length) {
|
|
81
|
+
if (length === void 0) { length = 2; }
|
|
82
|
+
var l = TestUtil.getLength(length);
|
|
83
|
+
return String(word).match(new RegExp("^[a-z]{".concat(l, "}$")));
|
|
84
|
+
};
|
|
80
85
|
TestUtil.isUpperCharValid = function (value, length) {
|
|
81
86
|
if (length === void 0) { length = 1; }
|
|
82
|
-
var l =
|
|
87
|
+
var l = TestUtil.getLength(length);
|
|
83
88
|
return String(value).match(new RegExp("^[A-Z]{".concat(l, "}$")));
|
|
84
89
|
};
|
|
85
90
|
TestUtil.isLowerCharValid = function (value, length) {
|
|
86
91
|
if (length === void 0) { length = 1; }
|
|
87
|
-
var l =
|
|
92
|
+
var l = TestUtil.getLength(length);
|
|
88
93
|
return String(value).match(new RegExp("^[a-z]{".concat(l, "}$")));
|
|
89
94
|
};
|
|
90
95
|
TestUtil.isFullNameValid = function (email) {
|
|
@@ -98,6 +103,9 @@ var TestUtil = /** @class */ (function () {
|
|
|
98
103
|
TestUtil.inNumberRange = function (value, range) {
|
|
99
104
|
return value >= range[0] && value <= range[1];
|
|
100
105
|
};
|
|
106
|
+
TestUtil.getLength = function (length) {
|
|
107
|
+
return Array.isArray(length) ? "".concat(length[0], ",").concat(length[1]) : length;
|
|
108
|
+
};
|
|
101
109
|
return TestUtil;
|
|
102
110
|
}());
|
|
103
111
|
exports.TestUtil = TestUtil;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var custom_1 = require("../custom");
|
|
4
|
+
var test_util_1 = require("./test-util");
|
|
5
|
+
describe("word", function () {
|
|
6
|
+
it("classic", function () {
|
|
7
|
+
test_util_1.TestUtil.loop(function () {
|
|
8
|
+
var w = custom_1.Randex.word();
|
|
9
|
+
expect(test_util_1.TestUtil.isWordValid(w, [2, 10])).toBeTruthy();
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
});
|
package/package.json
CHANGED
|
File without changes
|