randex 1.1.0 → 1.4.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.
Files changed (50) hide show
  1. package/.vscode/settings.json +1 -1
  2. package/README.md +20 -0
  3. package/eslint.config.js +29 -0
  4. package/lib/basic/set.js +48 -51
  5. package/lib/basic/type.js +27 -34
  6. package/lib/custom/bool.js +1 -2
  7. package/lib/custom/email.js +8 -9
  8. package/lib/custom/filenameX.js +7 -8
  9. package/lib/custom/fullnameX.js +7 -8
  10. package/lib/custom/index.d.ts +10 -8
  11. package/lib/custom/index.js +64 -45
  12. package/lib/custom/number.js +11 -12
  13. package/lib/custom/phrase.js +11 -12
  14. package/lib/custom/random.js +23 -29
  15. package/lib/custom/sentence.js +13 -14
  16. package/lib/custom/singleName.js +7 -8
  17. package/lib/custom/username.js +6 -7
  18. package/lib/custom/word.js +9 -10
  19. package/lib/index.js +1 -2
  20. package/lib/test/array.test.js +10 -13
  21. package/lib/test/arrayItem.test.js +17 -0
  22. package/lib/test/email.test.js +35 -35
  23. package/lib/test/filename.test.js +38 -38
  24. package/lib/test/fullname.test.js +7 -7
  25. package/lib/test/markdown.test.js +14 -14
  26. package/lib/test/name.test.js +13 -13
  27. package/lib/test/number.many.test.js +21 -24
  28. package/lib/test/number.test.js +26 -27
  29. package/lib/test/params.test.js +51 -51
  30. package/lib/test/phrase.test.js +22 -22
  31. package/lib/test/random.test.js +36 -38
  32. package/lib/test/sentence.test.js +22 -22
  33. package/lib/test/{set-util.test.js → setUtil.test.js} +7 -7
  34. package/lib/test/shuffle.test.d.ts +1 -0
  35. package/lib/test/shuffle.test.js +14 -0
  36. package/lib/test/spreader.test.js +13 -12
  37. package/lib/test/testUtil.js +121 -0
  38. package/lib/test/type.test.js +11 -14
  39. package/lib/test/username.test.js +11 -11
  40. package/lib/test/word.test.js +16 -16
  41. package/lib/utils/spreader.d.ts +1 -0
  42. package/lib/utils/spreader.js +19 -25
  43. package/package.json +4 -4
  44. package/.eslintignore +0 -3
  45. package/.eslintrc.js +0 -3
  46. package/lib/test/array-item.test.js +0 -18
  47. package/lib/test/test-util.js +0 -134
  48. /package/lib/test/{array-item.test.d.ts → arrayItem.test.d.ts} +0 -0
  49. /package/lib/test/{set-util.test.d.ts → setUtil.test.d.ts} +0 -0
  50. /package/lib/test/{test-util.d.ts → testUtil.d.ts} +0 -0
@@ -1,27 +1,28 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var set_1 = require("../basic/set");
4
- var spreader_1 = require("../utils/spreader");
5
- describe("RandexSpreader", function () {
6
- it("spreads from temp items without replacement", function () {
7
- var picker = new spreader_1.RandexSpreader(["a", "b", "c"]);
8
- var randomSpy = jest.spyOn(set_1.RandexSetUtil, "randomSingleNumber");
3
+ /* eslint-disable no-underscore-dangle */
4
+ const set_1 = require("../basic/set");
5
+ const spreader_1 = require("../utils/spreader");
6
+ describe("RandexSpreader", () => {
7
+ it("spreads from temp items without replacement", () => {
8
+ const picker = new spreader_1.RandexSpreader(["a", "b", "c"]);
9
+ const randomSpy = jest.spyOn(set_1.RandexSetUtil, "randomSingleNumber");
9
10
  randomSpy.mockReturnValueOnce(1).mockReturnValueOnce(0).mockReturnValueOnce(0);
10
11
  expect(picker.spread(3)).toEqual(["b", "a", "c"]);
11
12
  expect(picker._tempItems).toEqual([]);
12
13
  randomSpy.mockRestore();
13
14
  });
14
- it("keeps refilling until it returns the requested count", function () {
15
- var picker = new spreader_1.RandexSpreader([1, 2]);
16
- var randomSpy = jest.spyOn(set_1.RandexSetUtil, "randomSingleNumber");
15
+ it("keeps refilling until it returns the requested count", () => {
16
+ const picker = new spreader_1.RandexSpreader([1, 2]);
17
+ const randomSpy = jest.spyOn(set_1.RandexSetUtil, "randomSingleNumber");
17
18
  randomSpy.mockReturnValueOnce(0).mockReturnValueOnce(0).mockReturnValueOnce(1).mockReturnValueOnce(0).mockReturnValueOnce(0);
18
19
  expect(picker.spread(5)).toEqual([1, 2, 2, 1, 1]);
19
20
  expect(picker._tempItems).toEqual([2]);
20
21
  randomSpy.mockRestore();
21
22
  });
22
- it("refills temp items until the requested count is reached", function () {
23
- var picker = new spreader_1.RandexSpreader(["x", "y"]);
24
- var randomSpy = jest.spyOn(set_1.RandexSetUtil, "randomSingleNumber");
23
+ it("refills temp items until the requested count is reached", () => {
24
+ const picker = new spreader_1.RandexSpreader(["x", "y"]);
25
+ const randomSpy = jest.spyOn(set_1.RandexSetUtil, "randomSingleNumber");
25
26
  randomSpy.mockReturnValueOnce(1).mockReturnValueOnce(0).mockReturnValueOnce(0);
26
27
  expect(picker.spread(3)).toEqual(["y", "x", "x"]);
27
28
  expect(picker._tempItems).toEqual(["y"]);
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TestUtil = void 0;
4
+ const const_1 = require("../basic/const");
5
+ const set_1 = require("../basic/set");
6
+ class TestUtil {
7
+ static testIn(value, length = 1, action) {
8
+ if (typeof length === "number") {
9
+ expect(value.length).toBe(length);
10
+ }
11
+ else if (Array.isArray(length)) {
12
+ const [min, max] = length;
13
+ expect(value.length).toBeGreaterThanOrEqual(min);
14
+ expect(value.length).toBeLessThanOrEqual(max);
15
+ }
16
+ if (value) {
17
+ action();
18
+ }
19
+ }
20
+ static loop(action) {
21
+ for (let i = 0; i < 100; i++) {
22
+ action(i);
23
+ }
24
+ }
25
+ static testInSet(value, set, length = 1) {
26
+ TestUtil.testIn(value, length, () => {
27
+ expect(TestUtil.inSet(value, set)).toBeTruthy();
28
+ });
29
+ }
30
+ static testInSetRange(value, set, range, length = 1) {
31
+ TestUtil.testIn(value, length, () => {
32
+ expect(TestUtil.inSet(value, set, range)).toBeTruthy();
33
+ });
34
+ }
35
+ static testInRange(value, range, length = 1) {
36
+ TestUtil.testIn(value, length, () => {
37
+ expect(TestUtil.inRange(value, range)).toBeTruthy();
38
+ });
39
+ }
40
+ static testInBoth(value, set, range, length = 1) {
41
+ TestUtil.testIn(value, length, () => {
42
+ expect(TestUtil.inBoth(value, set, range)).toBeTruthy();
43
+ });
44
+ }
45
+ static inRange(value, range) {
46
+ for (let i = 0; i < value.length; i++) {
47
+ if (!range.includes(value[i])) {
48
+ return false;
49
+ }
50
+ }
51
+ return value.length > 0;
52
+ }
53
+ static inSet(value, set, range) {
54
+ const fullRange = set_1.RandexSetUtil.toRange(set) + (range ? range : "");
55
+ return TestUtil.inRange(value, fullRange);
56
+ }
57
+ static inBoth(value, set, range) {
58
+ const fullRange = set_1.RandexSetUtil.toRange(set) + range;
59
+ return TestUtil.inRange(value, fullRange);
60
+ }
61
+ static isEmailValid(email) {
62
+ return String(email)
63
+ .toLowerCase()
64
+ .match(/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|.(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/);
65
+ }
66
+ static isUsernameValid(email) {
67
+ return String(email)
68
+ .toLowerCase()
69
+ .match(/^[a-z][a-z0-9]{5,}$/);
70
+ }
71
+ static isNameValid(email) {
72
+ return String(email).match(/^[A-Z][a-z]{1,}$/);
73
+ }
74
+ static isWordValid(text, length = const_1.DEFAULT_WORD_RANGE) {
75
+ const l = TestUtil.getLength(length);
76
+ return String(text).match(new RegExp(`^[a-z]{${l}}$`));
77
+ }
78
+ static isSentenceValid(text, length = const_1.DEFAULT_SENTENCE_RANGE) {
79
+ const splits = text.split(" ");
80
+ if (Array.isArray(length)) {
81
+ const [min, max] = length;
82
+ return splits.length >= min && splits.length <= max;
83
+ }
84
+ else {
85
+ return splits.length === length;
86
+ }
87
+ }
88
+ static isPhraseValid(text, length = const_1.DEFAULT_PHRASE_RANGE) {
89
+ const splits = text.split(" ");
90
+ if (Array.isArray(length)) {
91
+ const [min, max] = length;
92
+ return splits.length >= min && splits.length <= max;
93
+ }
94
+ else {
95
+ return splits.length === length;
96
+ }
97
+ }
98
+ static isUpperCharValid(value, length = 1) {
99
+ const l = TestUtil.getLength(length);
100
+ return String(value).match(new RegExp(`^[A-Z]{${l}}$`));
101
+ }
102
+ static isLowerCharValid(value, length = 1) {
103
+ const l = TestUtil.getLength(length);
104
+ return String(value).match(new RegExp(`^[a-z]{${l}}$`));
105
+ }
106
+ static isFullNameValid(email) {
107
+ return String(email).match(/^[A-Z][a-z]{1,}[ ][A-Z][a-z]{1,}$/);
108
+ }
109
+ static isFileNameValid(email) {
110
+ return String(email)
111
+ .toLowerCase()
112
+ .match(/^[a-z0-9_.]{2,}$/);
113
+ }
114
+ static inNumberRange(value, range) {
115
+ return value >= range[0] && value <= range[1];
116
+ }
117
+ static getLength(length) {
118
+ return Array.isArray(length) ? `${length[0]},${length[1]}` : length;
119
+ }
120
+ }
121
+ exports.TestUtil = TestUtil;
@@ -1,23 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var type_1 = require("../basic/type");
4
- function isLength(value, expectedResult) {
5
- if (expectedResult === void 0) { expectedResult = true; }
6
- var result = type_1.RandexTypeParser.isLength(value);
3
+ const type_1 = require("../basic/type");
4
+ function isLength(value, expectedResult = true) {
5
+ const result = type_1.RandexTypeParser.isLength(value);
7
6
  expect(expectedResult).toBe(result);
8
7
  }
9
- function isSetSingle(value, expectedResult) {
10
- if (expectedResult === void 0) { expectedResult = true; }
11
- var result = type_1.RandexTypeParser.isSetSingle(value);
8
+ function isSetSingle(value, expectedResult = true) {
9
+ const result = type_1.RandexTypeParser.isSetSingle(value);
12
10
  expect(expectedResult).toBe(result);
13
11
  }
14
- function isSet(value, expectedResult) {
15
- if (expectedResult === void 0) { expectedResult = true; }
16
- var result = type_1.RandexTypeParser.isSet(value);
12
+ function isSet(value, expectedResult = true) {
13
+ const result = type_1.RandexTypeParser.isSet(value);
17
14
  expect(expectedResult).toBe(result);
18
15
  }
19
- describe("type", function () {
20
- it("isLength", function () {
16
+ describe("type", () => {
17
+ it("isLength", () => {
21
18
  // true
22
19
  isLength(1);
23
20
  isLength([1, 2]);
@@ -26,7 +23,7 @@ describe("type", function () {
26
23
  isLength("hi", false);
27
24
  isLength(null, false);
28
25
  });
29
- it("isSetSingle", function () {
26
+ it("isSetSingle", () => {
30
27
  // true
31
28
  isSetSingle("english");
32
29
  isSetSingle("hex");
@@ -39,7 +36,7 @@ describe("type", function () {
39
36
  isSetSingle(null, false);
40
37
  isSetSingle(["lower", "english"], false);
41
38
  });
42
- it("RandomSet", function () {
39
+ it("RandomSet", () => {
43
40
  // true single
44
41
  isSet("english");
45
42
  isSet("hex");
@@ -1,16 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var custom_1 = require("../custom");
4
- var test_util_1 = require("./test-util");
5
- describe("randomEmail", function () {
6
- it("simple", function () {
7
- test_util_1.TestUtil.loop(function () {
8
- var value = custom_1.Randex.username();
9
- expect(test_util_1.TestUtil.isUsernameValid(value)).toBeTruthy();
3
+ const custom_1 = require("../custom");
4
+ const testUtil_1 = require("./testUtil");
5
+ describe("randomEmail", () => {
6
+ it("simple", () => {
7
+ testUtil_1.TestUtil.loop(() => {
8
+ const value = custom_1.Randex.username();
9
+ expect(testUtil_1.TestUtil.isUsernameValid(value)).toBeTruthy();
10
10
  });
11
11
  });
12
- it("options", function () {
13
- var value = custom_1.Randex.username({ length: 5 });
12
+ it("options", () => {
13
+ let value = custom_1.Randex.username({ length: 5 });
14
14
  expect(value.length).toBe(5);
15
15
  value = custom_1.Randex.username(5);
16
16
  expect(value.length).toBe(5);
@@ -21,8 +21,8 @@ describe("randomEmail", function () {
21
21
  expect(value.length).toBe(5);
22
22
  //
23
23
  value = custom_1.Randex.username({ length: [1, 5] });
24
- expect(test_util_1.TestUtil.inNumberRange(value.length, [1, 5])).toBeTruthy();
24
+ expect(testUtil_1.TestUtil.inNumberRange(value.length, [1, 5])).toBeTruthy();
25
25
  value = custom_1.Randex.username([1, 5]);
26
- expect(test_util_1.TestUtil.inNumberRange(value.length, [1, 5])).toBeTruthy();
26
+ expect(testUtil_1.TestUtil.inNumberRange(value.length, [1, 5])).toBeTruthy();
27
27
  });
28
28
  });
@@ -1,26 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var const_1 = require("../basic/const");
4
- var custom_1 = require("../custom");
5
- var test_util_1 = require("./test-util");
6
- describe("word", function () {
7
- it("classic", function () {
8
- test_util_1.TestUtil.loop(function () {
9
- var w = custom_1.Randex.word();
10
- expect(test_util_1.TestUtil.isWordValid(w, const_1.DEFAULT_WORD_RANGE)).toBeTruthy();
3
+ const const_1 = require("../basic/const");
4
+ const custom_1 = require("../custom");
5
+ const testUtil_1 = require("./testUtil");
6
+ describe("word", () => {
7
+ it("classic", () => {
8
+ testUtil_1.TestUtil.loop(() => {
9
+ const w = custom_1.Randex.word();
10
+ expect(testUtil_1.TestUtil.isWordValid(w, const_1.DEFAULT_WORD_RANGE)).toBeTruthy();
11
11
  });
12
12
  });
13
- it("many - number", function () {
14
- var count = 5;
15
- var ws = custom_1.Randex.many(count).word();
13
+ it("many - number", () => {
14
+ const count = 5;
15
+ const ws = custom_1.Randex.many(count).word();
16
16
  expect(ws.length).toBe(count);
17
- for (var i = 0; i < count; i++) {
18
- expect(test_util_1.TestUtil.isWordValid(ws[i], const_1.DEFAULT_WORD_RANGE)).toBeTruthy();
17
+ for (let i = 0; i < count; i++) {
18
+ expect(testUtil_1.TestUtil.isWordValid(ws[i], const_1.DEFAULT_WORD_RANGE)).toBeTruthy();
19
19
  }
20
20
  });
21
- it("many - range", function () {
22
- var count = [5, 10];
23
- var ws = custom_1.Randex.many(count).word();
21
+ it("many - range", () => {
22
+ const count = [5, 10];
23
+ const ws = custom_1.Randex.many(count).word();
24
24
  expect(ws.length).toBeGreaterThanOrEqual(5);
25
25
  expect(ws.length).toBeLessThanOrEqual(10);
26
26
  });
@@ -3,5 +3,6 @@ export declare class RandexSpreader<TItem = any> {
3
3
  private readonly _items;
4
4
  private _tempItems;
5
5
  constructor(items?: TItem[]);
6
+ get isEmpty(): boolean;
6
7
  spread(count?: number): TItem[];
7
8
  }
@@ -1,39 +1,33 @@
1
1
  "use strict";
2
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
- if (ar || !(i in from)) {
5
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
- ar[i] = from[i];
7
- }
8
- }
9
- return to.concat(ar || Array.prototype.slice.call(from));
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.RandexSpreader = void 0;
13
- var set_1 = require("../basic/set");
14
- var RandexSpreader = /** @class */ (function () {
15
- function RandexSpreader(items) {
16
- if (items === void 0) { items = []; }
4
+ const set_1 = require("../basic/set");
5
+ class RandexSpreader {
6
+ items;
7
+ _items;
8
+ _tempItems;
9
+ constructor(items = []) {
17
10
  this.items = items;
18
11
  this._items = items;
19
- this._tempItems = __spreadArray([], items, true);
12
+ this._tempItems = [...items];
20
13
  }
21
- RandexSpreader.prototype.spread = function (count) {
22
- if (count === void 0) { count = 1; }
14
+ get isEmpty() {
15
+ return this._tempItems.length === 0;
16
+ }
17
+ spread(count = 1) {
23
18
  if (!this._items.length || count <= 0) {
24
19
  return [];
25
20
  }
26
- var result = [];
27
- for (var i = 0; i < count; i++) {
28
- if (!this._tempItems.length) {
29
- this._tempItems = __spreadArray([], this._items, true);
21
+ const result = [];
22
+ for (let i = 0; i < count; i++) {
23
+ if (this.isEmpty) {
24
+ this._tempItems = [...this._items];
30
25
  }
31
- var index = set_1.RandexSetUtil.randomSingleNumber(this._tempItems.length);
32
- var item = this._tempItems.splice(index, 1)[0];
26
+ const index = set_1.RandexSetUtil.randomSingleNumber(this._tempItems.length);
27
+ const [item] = this._tempItems.splice(index, 1);
33
28
  result.push(item);
34
29
  }
35
30
  return result;
36
- };
37
- return RandexSpreader;
38
- }());
31
+ }
32
+ }
39
33
  exports.RandexSpreader = RandexSpreader;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "randex",
3
- "version": "1.1.0",
3
+ "version": "1.4.0",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -19,13 +19,13 @@
19
19
  "author": "",
20
20
  "license": "ISC",
21
21
  "bugs": {},
22
+ "prettier": "eslint-config-varp/prettier",
22
23
  "devDependencies": {
23
24
  "@types/jest": "^24.9.1",
24
- "eslint-config-varp-common": "^1.0.0",
25
- "eslint-plugin-tsc": "^2.0.0",
25
+ "eslint-config-varp": "^2.16.0",
26
26
  "jest": "^24.9.0",
27
27
  "ts-jest": "^24.1.0",
28
- "typescript": "^4.2.4"
28
+ "typescript": "^5.9.3"
29
29
  },
30
30
  "keywords": [
31
31
  "random",
package/.eslintignore DELETED
@@ -1,3 +0,0 @@
1
- .*
2
- /lib
3
- node_modules
package/.eslintrc.js DELETED
@@ -1,3 +0,0 @@
1
- module.exports = {
2
- extends: ['varp-common']
3
- };
@@ -1,18 +0,0 @@
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("randomArrayItem", function () {
6
- it("param: number", function () {
7
- var array = [1, 2, 3, 4, 5, 6];
8
- var resultArray = {};
9
- test_util_1.TestUtil.loop(function () {
10
- var value = custom_1.Randex.arrayItem(array);
11
- resultArray[value] = (resultArray[value] || 0) + 1;
12
- });
13
- for (var _i = 0, array_1 = array; _i < array_1.length; _i++) {
14
- var item = array_1[_i];
15
- expect(resultArray[item]).toBeTruthy();
16
- }
17
- });
18
- });
@@ -1,134 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TestUtil = void 0;
4
- var const_1 = require("../basic/const");
5
- var set_1 = require("../basic/set");
6
- var TestUtil = /** @class */ (function () {
7
- function TestUtil() {
8
- }
9
- TestUtil.testIn = function (value, length, action) {
10
- if (length === void 0) { length = 1; }
11
- if (typeof length === "number") {
12
- expect(value.length).toBe(length);
13
- }
14
- else if (Array.isArray(length)) {
15
- var min = length[0], max = length[1];
16
- expect(value.length).toBeGreaterThanOrEqual(min);
17
- expect(value.length).toBeLessThanOrEqual(max);
18
- }
19
- if (value) {
20
- action();
21
- }
22
- };
23
- TestUtil.loop = function (action) {
24
- for (var i = 0; i < 100; i++) {
25
- action(i);
26
- }
27
- };
28
- TestUtil.testInSet = function (value, set, length) {
29
- if (length === void 0) { length = 1; }
30
- TestUtil.testIn(value, length, function () {
31
- expect(TestUtil.inSet(value, set)).toBeTruthy();
32
- });
33
- };
34
- TestUtil.testInSetRange = function (value, set, range, length) {
35
- if (length === void 0) { length = 1; }
36
- TestUtil.testIn(value, length, function () {
37
- expect(TestUtil.inSet(value, set, range)).toBeTruthy();
38
- });
39
- };
40
- TestUtil.testInRange = function (value, range, length) {
41
- if (length === void 0) { length = 1; }
42
- TestUtil.testIn(value, length, function () {
43
- expect(TestUtil.inRange(value, range)).toBeTruthy();
44
- });
45
- };
46
- TestUtil.testInBoth = function (value, set, range, length) {
47
- if (length === void 0) { length = 1; }
48
- TestUtil.testIn(value, length, function () {
49
- expect(TestUtil.inBoth(value, set, range)).toBeTruthy();
50
- });
51
- };
52
- TestUtil.inRange = function (value, range) {
53
- for (var i = 0; i < value.length; i++) {
54
- if (!range.includes(value[i])) {
55
- return false;
56
- }
57
- }
58
- return value.length > 0;
59
- };
60
- TestUtil.inSet = function (value, set, range) {
61
- var fullRange = set_1.RandexSetUtil.toRange(set) + (range ? range : "");
62
- return TestUtil.inRange(value, fullRange);
63
- };
64
- TestUtil.inBoth = function (value, set, range) {
65
- var fullRange = set_1.RandexSetUtil.toRange(set) + range;
66
- return TestUtil.inRange(value, fullRange);
67
- };
68
- TestUtil.isEmailValid = function (email) {
69
- return String(email)
70
- .toLowerCase()
71
- .match(/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|.(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/);
72
- };
73
- TestUtil.isUsernameValid = function (email) {
74
- return String(email)
75
- .toLowerCase()
76
- .match(/^[a-z][a-z0-9]{5,}$/);
77
- };
78
- TestUtil.isNameValid = function (email) {
79
- return String(email).match(/^[A-Z][a-z]{1,}$/);
80
- };
81
- TestUtil.isWordValid = function (text, length) {
82
- if (length === void 0) { length = const_1.DEFAULT_WORD_RANGE; }
83
- var l = TestUtil.getLength(length);
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
- }
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
- };
108
- TestUtil.isUpperCharValid = function (value, length) {
109
- if (length === void 0) { length = 1; }
110
- var l = TestUtil.getLength(length);
111
- return String(value).match(new RegExp("^[A-Z]{".concat(l, "}$")));
112
- };
113
- TestUtil.isLowerCharValid = function (value, length) {
114
- if (length === void 0) { length = 1; }
115
- var l = TestUtil.getLength(length);
116
- return String(value).match(new RegExp("^[a-z]{".concat(l, "}$")));
117
- };
118
- TestUtil.isFullNameValid = function (email) {
119
- return String(email).match(/^[A-Z][a-z]{1,}[ ][A-Z][a-z]{1,}$/);
120
- };
121
- TestUtil.isFileNameValid = function (email) {
122
- return String(email)
123
- .toLowerCase()
124
- .match(/^[a-z0-9_\.]{2,}$/);
125
- };
126
- TestUtil.inNumberRange = function (value, range) {
127
- return value >= range[0] && value <= range[1];
128
- };
129
- TestUtil.getLength = function (length) {
130
- return Array.isArray(length) ? "".concat(length[0], ",").concat(length[1]) : length;
131
- };
132
- return TestUtil;
133
- }());
134
- exports.TestUtil = TestUtil;
File without changes