randex 0.23.0 → 0.25.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 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.
@@ -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 { RandexSingleNameOptions } from "./singleName";
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 "./singleName";
10
+ export * from "./word";
11
11
  export * from "./username";
12
12
  export * from "./fullname";
13
13
  export * from "./number";
@@ -20,22 +20,26 @@ export declare class Randex {
20
20
  static arrayItem<T>(array: T[], defaultValue: T): T;
21
21
  static array<T>(array: T[], count: number): T[];
22
22
  static bool(): boolean;
23
- static email(options?: RandexEmailOptions): any;
24
- static email(prefixLength: RandexLength, lowDomainLength?: RandexLength, hightDomainLength?: RandexLength): any;
25
- static email(domain: string): any;
26
- static fileName(options?: RandexFileNameOptions): any;
27
- static fileName(fileNameLength: RandexLength, extensionLength?: RandexLength): any;
28
- static fileName(fileNameLength: RandexLength, extension: string): any;
29
- static fileName(extension: string): any;
30
- static fullName(options?: RandexFullNameOptions): any;
31
- static fullName(length: RandexLength): any;
32
- static fullName(alphabet?: RandexAlphabet): any;
33
- static fullName(alphabet: RandexAlphabet, length: RandexLength): any;
34
- static fullName(alphabet: RandexAlphabet, firstLength: RandexLength, secondLength: RandexLength): any;
35
- static singleName(options?: RandexSingleNameOptions): any;
36
- static singleName(length: RandexLength): any;
37
- static singleName(alphabet?: RandexAlphabet): any;
38
- static singleName(alphabet: RandexAlphabet, length: RandexLength): any;
23
+ static email(options?: RandexEmailOptions): string;
24
+ static email(prefixLength: RandexLength, lowDomainLength?: RandexLength, hightDomainLength?: RandexLength): string;
25
+ static email(domain: string): string;
26
+ static fileName(options?: RandexFileNameOptions): string;
27
+ static fileName(fileNameLength: RandexLength, extensionLength?: RandexLength): string;
28
+ static fileName(fileNameLength: RandexLength, extension: string): string;
29
+ static fileName(extension: string): string;
30
+ static fullName(options?: RandexFullNameOptions): string;
31
+ static fullName(length: RandexLength): string;
32
+ static fullName(alphabet?: RandexAlphabet): string;
33
+ static fullName(alphabet: RandexAlphabet, length: RandexLength): string;
34
+ static fullName(alphabet: RandexAlphabet, firstLength: RandexLength, secondLength: RandexLength): string;
35
+ static singleName(options?: RandexWordOptions): string;
36
+ static singleName(length: RandexLength): string;
37
+ static singleName(alphabet?: RandexAlphabet): string;
38
+ static singleName(alphabet: RandexAlphabet, length: RandexLength): string;
39
+ static word(options?: RandexWordOptions): string;
40
+ static word(length: RandexLength): string;
41
+ static word(alphabet?: RandexAlphabet): string;
42
+ static word(alphabet: RandexAlphabet, length: RandexLength): string;
39
43
  static numberArray(length: RandexLength, count: number): number[];
40
44
  private static getNumberBase;
41
45
  private static getNumberValue;
@@ -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("./singleName"), exports);
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;
@@ -1,5 +1,5 @@
1
1
  import { RandexAlphabet, RandexLength } from "../interfaces";
2
- export interface RandexSingleNameOptions {
2
+ export interface RandexWordOptions {
3
3
  alphabet?: RandexAlphabet;
4
4
  length?: RandexLength;
5
5
  }
@@ -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
  }
@@ -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 = Array.isArray(length) ? "".concat(length[0], ",").concat(length[1]) : length;
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 = Array.isArray(length) ? "".concat(length[0], ",").concat(length[1]) : length;
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "randex",
3
- "version": "0.23.0",
3
+ "version": "0.25.0",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
File without changes