@nestia/e2e 0.4.2 → 0.5.0-dev.20240617

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.
@@ -1,161 +1,161 @@
1
- import { back_inserter, randint } from "tstl";
2
- import { sample as _Sample } from "tstl/ranges";
3
-
4
- /**
5
- * Random data generator.
6
- *
7
- * @author Jeongho Nam - https://github.com/samchon
8
- */
9
- export namespace RandomGenerator {
10
- /* ----------------------------------------------------------------
11
- IDENTIFICATIONS
12
- ---------------------------------------------------------------- */
13
- const CHARACTERS = "abcdefghijklmnopqrstuvwxyz";
14
- const LETTERS: string = "0123456789" + CHARACTERS;
15
-
16
- /**
17
- * Generate random alphabets
18
- *
19
- * @param length Length of alphabets
20
- * @returns Generated alphabets
21
- */
22
- export const alphabets = (length: number): string =>
23
- new Array(length)
24
- .fill("")
25
- .map(() => CHARACTERS[randint(0, CHARACTERS.length - 1)])
26
- .join("");
27
-
28
- /**
29
- * Generate random alpha-numeric characters.
30
- *
31
- * Generate random string constructed with only alphabets and numbers.
32
- *
33
- * @param length Length of characters
34
- * @returns Generated string
35
- */
36
- export const alphaNumeric = (length: number): string =>
37
- new Array(length)
38
- .fill("")
39
- .map(() => LETTERS[randint(0, LETTERS.length - 1)])
40
- .join("");
41
-
42
- /**
43
- * Generate random name.
44
- *
45
- * @param length Length of paragraph, default is 2 or 3
46
- * @returns Generated name
47
- */
48
- export const name = (length: number = randint(2, 3)): string =>
49
- paragraph(length)();
50
-
51
- /**
52
- * Generate random paragraph.
53
- *
54
- * @param sentences Number of sentences
55
- * @returns Paragraph generator
56
- */
57
- export const paragraph =
58
- (sentences: number = randint(2, 5)) =>
59
- /**
60
- * @param wordMin Minimum number of characters in a sentence
61
- * @param wordMax Maximum number of characters in a sentence
62
- * @returns Generated paragraph
63
- */
64
- (wordMin: number = 3, wordMax: number = 7): string =>
65
- new Array(sentences)
66
- .fill("")
67
- .map(() => alphabets(randint(wordMin, wordMax)))
68
- .join(" ");
69
-
70
- /**
71
- * Generate random content.
72
- *
73
- * @param paragraphes Number of paragraphes
74
- * @returns Currying function
75
- */
76
- export const content =
77
- (paragraphes: number = randint(3, 8)) =>
78
- /**
79
- * @param sentenceMin Minimum number of sentences in a paragraph
80
- * @param sentenceMax Maximum number of sentences in a paragraph
81
- * @returns Currying function
82
- */
83
- (sentenceMin: number = 10, sentenceMax: number = 40) =>
84
- /**
85
- * @param wordMin Minimum number of characters in a sentence
86
- * @param wordMax Maximum number of characters in a sentence
87
- * @returns Content generator
88
- */
89
- (wordMin: number = 1, wordMax: number = 7): string =>
90
- new Array(paragraphes)
91
- .fill("")
92
- .map(() =>
93
- paragraph(randint(sentenceMin, sentenceMax))(wordMin, wordMax),
94
- )
95
- .join("\n\n");
96
-
97
- /**
98
- * Generate random substring.
99
- *
100
- * @param content Target content
101
- * @returns Random substring
102
- */
103
- export const substring = (content: string): string => {
104
- const first: number = randint(0, content.length - 1);
105
- const last: number = randint(first + 1, content.length);
106
-
107
- return content.substring(first, last).trim();
108
- };
109
-
110
- /**
111
- * Generate random mobile number.
112
- *
113
- * @param prefix Prefix string, default is "010"
114
- * @returns Random mobile number
115
- * @example 0103340067
116
- */
117
- export const mobile = (prefix: string = "010"): string =>
118
- [
119
- prefix,
120
- (() => {
121
- const value = randint(0, 9999);
122
- return value.toString().padStart(value < 1_000 ? 3 : 4, "0");
123
- })(),
124
- randint(0, 9999).toString().padStart(4, "0"),
125
- ].join("");
126
-
127
- /**
128
- * Generate random date.
129
- *
130
- * @param from Start date
131
- * @param range Range of random milliseconds
132
- * @returns Random date
133
- */
134
- export const date =
135
- (from: Date) =>
136
- (range: number): Date =>
137
- new Date(from.getTime() + randint(0, range));
138
-
139
- /**
140
- * Pick random elements from an array.
141
- *
142
- * @param array Target array
143
- * @param count Number of count to pick
144
- * @returns Sampled array
145
- */
146
- export const sample =
147
- <T>(array: T[]) =>
148
- (count: number): T[] => {
149
- const ret: T[] = [];
150
- _Sample(array, back_inserter(ret), count);
151
- return ret;
152
- };
153
-
154
- /**
155
- * Pick random element from an array.
156
- *
157
- * @param array Target array
158
- * @returns picked element
159
- */
160
- export const pick = <T>(array: T[]): T => array[randint(0, array.length - 1)];
161
- }
1
+ import { back_inserter, randint } from "tstl";
2
+ import { ranges } from "tstl";
3
+
4
+ /**
5
+ * Random data generator.
6
+ *
7
+ * @author Jeongho Nam - https://github.com/samchon
8
+ */
9
+ export namespace RandomGenerator {
10
+ /* ----------------------------------------------------------------
11
+ IDENTIFICATIONS
12
+ ---------------------------------------------------------------- */
13
+ const CHARACTERS = "abcdefghijklmnopqrstuvwxyz";
14
+ const LETTERS: string = "0123456789" + CHARACTERS;
15
+
16
+ /**
17
+ * Generate random alphabets
18
+ *
19
+ * @param length Length of alphabets
20
+ * @returns Generated alphabets
21
+ */
22
+ export const alphabets = (length: number): string =>
23
+ new Array(length)
24
+ .fill("")
25
+ .map(() => CHARACTERS[randint(0, CHARACTERS.length - 1)])
26
+ .join("");
27
+
28
+ /**
29
+ * Generate random alpha-numeric characters.
30
+ *
31
+ * Generate random string constructed with only alphabets and numbers.
32
+ *
33
+ * @param length Length of characters
34
+ * @returns Generated string
35
+ */
36
+ export const alphaNumeric = (length: number): string =>
37
+ new Array(length)
38
+ .fill("")
39
+ .map(() => LETTERS[randint(0, LETTERS.length - 1)])
40
+ .join("");
41
+
42
+ /**
43
+ * Generate random name.
44
+ *
45
+ * @param length Length of paragraph, default is 2 or 3
46
+ * @returns Generated name
47
+ */
48
+ export const name = (length: number = randint(2, 3)): string =>
49
+ paragraph(length)();
50
+
51
+ /**
52
+ * Generate random paragraph.
53
+ *
54
+ * @param sentences Number of sentences
55
+ * @returns Paragraph generator
56
+ */
57
+ export const paragraph =
58
+ (sentences: number = randint(2, 5)) =>
59
+ /**
60
+ * @param wordMin Minimum number of characters in a sentence
61
+ * @param wordMax Maximum number of characters in a sentence
62
+ * @returns Generated paragraph
63
+ */
64
+ (wordMin: number = 3, wordMax: number = 7): string =>
65
+ new Array(sentences)
66
+ .fill("")
67
+ .map(() => alphabets(randint(wordMin, wordMax)))
68
+ .join(" ");
69
+
70
+ /**
71
+ * Generate random content.
72
+ *
73
+ * @param paragraphes Number of paragraphes
74
+ * @returns Currying function
75
+ */
76
+ export const content =
77
+ (paragraphes: number = randint(3, 8)) =>
78
+ /**
79
+ * @param sentenceMin Minimum number of sentences in a paragraph
80
+ * @param sentenceMax Maximum number of sentences in a paragraph
81
+ * @returns Currying function
82
+ */
83
+ (sentenceMin: number = 10, sentenceMax: number = 40) =>
84
+ /**
85
+ * @param wordMin Minimum number of characters in a sentence
86
+ * @param wordMax Maximum number of characters in a sentence
87
+ * @returns Content generator
88
+ */
89
+ (wordMin: number = 1, wordMax: number = 7): string =>
90
+ new Array(paragraphes)
91
+ .fill("")
92
+ .map(() =>
93
+ paragraph(randint(sentenceMin, sentenceMax))(wordMin, wordMax),
94
+ )
95
+ .join("\n\n");
96
+
97
+ /**
98
+ * Generate random substring.
99
+ *
100
+ * @param content Target content
101
+ * @returns Random substring
102
+ */
103
+ export const substring = (content: string): string => {
104
+ const first: number = randint(0, content.length - 1);
105
+ const last: number = randint(first + 1, content.length);
106
+
107
+ return content.substring(first, last).trim();
108
+ };
109
+
110
+ /**
111
+ * Generate random mobile number.
112
+ *
113
+ * @param prefix Prefix string, default is "010"
114
+ * @returns Random mobile number
115
+ * @example 0103340067
116
+ */
117
+ export const mobile = (prefix: string = "010"): string =>
118
+ [
119
+ prefix,
120
+ (() => {
121
+ const value = randint(0, 9999);
122
+ return value.toString().padStart(value < 1_000 ? 3 : 4, "0");
123
+ })(),
124
+ randint(0, 9999).toString().padStart(4, "0"),
125
+ ].join("");
126
+
127
+ /**
128
+ * Generate random date.
129
+ *
130
+ * @param from Start date
131
+ * @param range Range of random milliseconds
132
+ * @returns Random date
133
+ */
134
+ export const date =
135
+ (from: Date) =>
136
+ (range: number): Date =>
137
+ new Date(from.getTime() + randint(0, range));
138
+
139
+ /**
140
+ * Pick random elements from an array.
141
+ *
142
+ * @param array Target array
143
+ * @param count Number of count to pick
144
+ * @returns Sampled array
145
+ */
146
+ export const sample =
147
+ <T>(array: T[]) =>
148
+ (count: number): T[] => {
149
+ const ret: T[] = [];
150
+ ranges.sample(array, back_inserter(ret), count);
151
+ return ret;
152
+ };
153
+
154
+ /**
155
+ * Pick random element from an array.
156
+ *
157
+ * @param array Target array
158
+ * @returns picked element
159
+ */
160
+ export const pick = <T>(array: T[]): T => array[randint(0, array.length - 1)];
161
+ }
package/src/StopWatch.ts CHANGED
@@ -1,38 +1,38 @@
1
- /**
2
- * Elapsed time measurement utility.
3
- *
4
- * @author Sachon
5
- */
6
- export namespace StopWatch {
7
- /**
8
- * Type of task.
9
- */
10
- export type Task<T> = () => Promise<T>;
11
-
12
- /**
13
- *
14
- * @param task
15
- * @returns
16
- */
17
- export const measure = async <T>(task: Task<T>): Promise<[T, number]> => {
18
- const time: number = Date.now();
19
- const output: T = await task();
20
- return [output, Date.now() - time];
21
- };
22
-
23
- /**
24
- *
25
- * @param title
26
- * @param task
27
- * @returns
28
- */
29
- export const trace =
30
- (title: string) =>
31
- async <T>(task: Task<T>): Promise<[T, number]> => {
32
- process.stdout.write(` - ${title}: `);
33
- const res: [T, number] = await measure(task);
34
-
35
- console.log(`${res[1].toLocaleString()} ms`);
36
- return res;
37
- };
38
- }
1
+ /**
2
+ * Elapsed time measurement utility.
3
+ *
4
+ * @author Sachon
5
+ */
6
+ export namespace StopWatch {
7
+ /**
8
+ * Type of task.
9
+ */
10
+ export type Task<T> = () => Promise<T>;
11
+
12
+ /**
13
+ *
14
+ * @param task
15
+ * @returns
16
+ */
17
+ export const measure = async <T>(task: Task<T>): Promise<[T, number]> => {
18
+ const time: number = Date.now();
19
+ const output: T = await task();
20
+ return [output, Date.now() - time];
21
+ };
22
+
23
+ /**
24
+ *
25
+ * @param title
26
+ * @param task
27
+ * @returns
28
+ */
29
+ export const trace =
30
+ (title: string) =>
31
+ async <T>(task: Task<T>): Promise<[T, number]> => {
32
+ process.stdout.write(` - ${title}: `);
33
+ const res: [T, number] = await measure(task);
34
+
35
+ console.log(`${res[1].toLocaleString()} ms`);
36
+ return res;
37
+ };
38
+ }