@kottetall/random 0.0.4 → 0.0.6
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/lib/constants/name.constant.d.ts +10 -0
- package/lib/constants/name.constant.d.ts.map +1 -0
- package/lib/constants/name.constant.js +199 -0
- package/lib/constants/random.constant.d.ts +11 -4
- package/lib/constants/random.constant.d.ts.map +1 -1
- package/lib/constants/random.constant.js +81 -5
- package/lib/constants/time.constant.d.ts +8 -0
- package/lib/constants/time.constant.d.ts.map +1 -0
- package/lib/constants/time.constant.js +10 -0
- package/lib/index.d.ts +56 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +111 -3
- package/lib/types/name.type.d.ts +3 -0
- package/lib/types/name.type.d.ts.map +1 -0
- package/lib/types/name.type.js +2 -0
- package/lib/types/random.type.d.ts +2 -1
- package/lib/types/random.type.d.ts.map +1 -1
- package/package.json +7 -4
- package/readme.md +13 -2
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const gender: {
|
|
2
|
+
readonly MALE: "male";
|
|
3
|
+
readonly FEMALE: "female";
|
|
4
|
+
readonly UNISEX: "unisex";
|
|
5
|
+
};
|
|
6
|
+
export declare const firstNameNeutral: readonly ["Alex", "Ari", "Ash", "Avery", "Bo", "Cai", "Kai", "Casey", "Chris", "Dani", "Eli", "Emi", "Jay", "Jesse", "Jordan", "Lee", "Lian", "Luca", "Luka", "Max", "Mika", "Mica", "Quinn", "Ren", "Rio", "Robin", "Sam", "Sky", "Sora", "Tao", "Taylor", "Toni", "Yuri", "Zion"];
|
|
7
|
+
export declare const firstNameMale: readonly ["Adam", "Adrian", "Ahmed", "Ahmad", "Alan", "Alejandro", "André", "Antonio", "Arjun", "Ben", "Carlos", "Daniel", "David", "Diego", "Ethan", "Felix", "Gabriel", "Hassan", "Hugo", "Ibrahim", "Ivan", "Jack", "James", "Jason", "John", "Joseph", "Julian", "Kevin", "Leo", "Lucas", "Luis", "Marco", "Mark", "Martin", "Mateo", "Michael", "Mohammed", "Muhammad", "Nico", "Noah", "Oliver", "Omar", "Oscar", "Paul", "Rafael", "Samir", "Sebastian", "Simon", "Thomas", "Victor", "William", "Yusuf", "Youssef", "Zayn"];
|
|
8
|
+
export declare const firstNameFemale: readonly ["Aisha", "Ayesha", "Alice", "Amelia", "Ana", "Anna", "Aya", "Bea", "Carla", "Clara", "Diana", "Elena", "Ella", "Emma", "Eva", "Fatima", "Hana", "Hanna", "Isabella", "Jade", "Julia", "Khadija", "Lara", "Leila", "Layla", "Lina", "Lucia", "Maria", "Maya", "Mina", "Nadia", "Naomi", "Nina", "Olivia", "Rania", "Rosa", "Sara", "Sarah", "Sofia", "Sophia", "Tara", "Yara", "Zara"];
|
|
9
|
+
export declare const lastname: readonly ["Ali", "Ahmed", "Anderson", "Brown", "Chen", "Garcia", "Hassan", "Ivanov", "Khan", "Kim", "Lee", "Li", "Lopez", "Martin", "Mohamed", "Nguyen", "Patel", "Rodriguez", "Singh", "Smith", "Wang", "Zhang", "Andersson", "Anderson", "Baker", "Bianchi", "Black", "Blanco", "Clark", "Costa", "Dubois", "Evans", "Fischer", "Fisher", "Fontana", "Gonzalez", "Hansen", "Johansson", "Jones", "Kowalski", "Larsen", "Müller", "Muller", "Novak", "Petrov", "Rossi", "Schmidt", "Schmidt", "Silva", "Taylor", "Walker", "White"];
|
|
10
|
+
//# sourceMappingURL=name.constant.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"name.constant.d.ts","sourceRoot":"","sources":["../../src/constants/name.constant.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM;;;;CAIT,CAAC;AAEX,eAAO,MAAM,gBAAgB,qRAmCnB,CAAC;AAEX,eAAO,MAAM,aAAa,qgBAuDhB,CAAC;AAEX,eAAO,MAAM,eAAe,iYA4ClB,CAAC;AAEX,eAAO,MAAM,QAAQ,sgBAqDX,CAAC"}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.lastname = exports.firstNameFemale = exports.firstNameMale = exports.firstNameNeutral = exports.gender = void 0;
|
|
4
|
+
exports.gender = {
|
|
5
|
+
MALE: "male",
|
|
6
|
+
FEMALE: "female",
|
|
7
|
+
UNISEX: "unisex",
|
|
8
|
+
};
|
|
9
|
+
exports.firstNameNeutral = [
|
|
10
|
+
"Alex",
|
|
11
|
+
"Ari",
|
|
12
|
+
"Ash",
|
|
13
|
+
"Avery",
|
|
14
|
+
"Bo",
|
|
15
|
+
"Cai",
|
|
16
|
+
"Kai",
|
|
17
|
+
"Casey",
|
|
18
|
+
"Chris",
|
|
19
|
+
"Dani",
|
|
20
|
+
"Eli",
|
|
21
|
+
"Emi",
|
|
22
|
+
"Jay",
|
|
23
|
+
"Jesse",
|
|
24
|
+
"Jordan",
|
|
25
|
+
"Lee",
|
|
26
|
+
"Lian",
|
|
27
|
+
"Luca",
|
|
28
|
+
"Luka",
|
|
29
|
+
"Max",
|
|
30
|
+
"Mika",
|
|
31
|
+
"Mica",
|
|
32
|
+
"Quinn",
|
|
33
|
+
"Ren",
|
|
34
|
+
"Rio",
|
|
35
|
+
"Robin",
|
|
36
|
+
"Sam",
|
|
37
|
+
"Sky",
|
|
38
|
+
"Sora",
|
|
39
|
+
"Tao",
|
|
40
|
+
"Taylor",
|
|
41
|
+
"Toni",
|
|
42
|
+
"Yuri",
|
|
43
|
+
"Zion",
|
|
44
|
+
];
|
|
45
|
+
exports.firstNameMale = [
|
|
46
|
+
"Adam",
|
|
47
|
+
"Adrian",
|
|
48
|
+
"Ahmed",
|
|
49
|
+
"Ahmad",
|
|
50
|
+
"Alan",
|
|
51
|
+
"Alejandro",
|
|
52
|
+
"André",
|
|
53
|
+
"Antonio",
|
|
54
|
+
"Arjun",
|
|
55
|
+
"Ben",
|
|
56
|
+
"Carlos",
|
|
57
|
+
"Daniel",
|
|
58
|
+
"David",
|
|
59
|
+
"Diego",
|
|
60
|
+
"Ethan",
|
|
61
|
+
"Felix",
|
|
62
|
+
"Gabriel",
|
|
63
|
+
"Hassan",
|
|
64
|
+
"Hugo",
|
|
65
|
+
"Ibrahim",
|
|
66
|
+
"Ivan",
|
|
67
|
+
"Jack",
|
|
68
|
+
"James",
|
|
69
|
+
"Jason",
|
|
70
|
+
"John",
|
|
71
|
+
"Joseph",
|
|
72
|
+
"Julian",
|
|
73
|
+
"Kevin",
|
|
74
|
+
"Leo",
|
|
75
|
+
"Lucas",
|
|
76
|
+
"Luis",
|
|
77
|
+
"Marco",
|
|
78
|
+
"Mark",
|
|
79
|
+
"Martin",
|
|
80
|
+
"Mateo",
|
|
81
|
+
"Michael",
|
|
82
|
+
"Mohammed",
|
|
83
|
+
"Muhammad",
|
|
84
|
+
"Nico",
|
|
85
|
+
"Noah",
|
|
86
|
+
"Oliver",
|
|
87
|
+
"Omar",
|
|
88
|
+
"Oscar",
|
|
89
|
+
"Paul",
|
|
90
|
+
"Rafael",
|
|
91
|
+
"Samir",
|
|
92
|
+
"Sebastian",
|
|
93
|
+
"Simon",
|
|
94
|
+
"Thomas",
|
|
95
|
+
"Victor",
|
|
96
|
+
"William",
|
|
97
|
+
"Yusuf",
|
|
98
|
+
"Youssef",
|
|
99
|
+
"Zayn",
|
|
100
|
+
];
|
|
101
|
+
exports.firstNameFemale = [
|
|
102
|
+
"Aisha",
|
|
103
|
+
"Ayesha",
|
|
104
|
+
"Alice",
|
|
105
|
+
"Amelia",
|
|
106
|
+
"Ana",
|
|
107
|
+
"Anna",
|
|
108
|
+
"Aya",
|
|
109
|
+
"Bea",
|
|
110
|
+
"Carla",
|
|
111
|
+
"Clara",
|
|
112
|
+
"Diana",
|
|
113
|
+
"Elena",
|
|
114
|
+
"Ella",
|
|
115
|
+
"Emma",
|
|
116
|
+
"Eva",
|
|
117
|
+
"Fatima",
|
|
118
|
+
"Hana",
|
|
119
|
+
"Hanna",
|
|
120
|
+
"Isabella",
|
|
121
|
+
"Jade",
|
|
122
|
+
"Julia",
|
|
123
|
+
"Khadija",
|
|
124
|
+
"Lara",
|
|
125
|
+
"Leila",
|
|
126
|
+
"Layla",
|
|
127
|
+
"Lina",
|
|
128
|
+
"Lucia",
|
|
129
|
+
"Maria",
|
|
130
|
+
"Maya",
|
|
131
|
+
"Mina",
|
|
132
|
+
"Nadia",
|
|
133
|
+
"Naomi",
|
|
134
|
+
"Nina",
|
|
135
|
+
"Olivia",
|
|
136
|
+
"Rania",
|
|
137
|
+
"Rosa",
|
|
138
|
+
"Sara",
|
|
139
|
+
"Sarah",
|
|
140
|
+
"Sofia",
|
|
141
|
+
"Sophia",
|
|
142
|
+
"Tara",
|
|
143
|
+
"Yara",
|
|
144
|
+
"Zara",
|
|
145
|
+
];
|
|
146
|
+
exports.lastname = [
|
|
147
|
+
"Ali",
|
|
148
|
+
"Ahmed",
|
|
149
|
+
"Anderson",
|
|
150
|
+
"Brown",
|
|
151
|
+
"Chen",
|
|
152
|
+
"Garcia",
|
|
153
|
+
"Hassan",
|
|
154
|
+
"Ivanov",
|
|
155
|
+
"Khan",
|
|
156
|
+
"Kim",
|
|
157
|
+
"Lee",
|
|
158
|
+
"Li",
|
|
159
|
+
"Lopez",
|
|
160
|
+
"Martin",
|
|
161
|
+
"Mohamed",
|
|
162
|
+
"Nguyen",
|
|
163
|
+
"Patel",
|
|
164
|
+
"Rodriguez",
|
|
165
|
+
"Singh",
|
|
166
|
+
"Smith",
|
|
167
|
+
"Wang",
|
|
168
|
+
"Zhang",
|
|
169
|
+
"Andersson",
|
|
170
|
+
"Anderson",
|
|
171
|
+
"Baker",
|
|
172
|
+
"Bianchi",
|
|
173
|
+
"Black",
|
|
174
|
+
"Blanco",
|
|
175
|
+
"Clark",
|
|
176
|
+
"Costa",
|
|
177
|
+
"Dubois",
|
|
178
|
+
"Evans",
|
|
179
|
+
"Fischer",
|
|
180
|
+
"Fisher",
|
|
181
|
+
"Fontana",
|
|
182
|
+
"Gonzalez",
|
|
183
|
+
"Hansen",
|
|
184
|
+
"Johansson",
|
|
185
|
+
"Jones",
|
|
186
|
+
"Kowalski",
|
|
187
|
+
"Larsen",
|
|
188
|
+
"Müller",
|
|
189
|
+
"Muller",
|
|
190
|
+
"Novak",
|
|
191
|
+
"Petrov",
|
|
192
|
+
"Rossi",
|
|
193
|
+
"Schmidt",
|
|
194
|
+
"Schmidt",
|
|
195
|
+
"Silva",
|
|
196
|
+
"Taylor",
|
|
197
|
+
"Walker",
|
|
198
|
+
"White",
|
|
199
|
+
];
|
|
@@ -1,13 +1,20 @@
|
|
|
1
|
+
import { HttpCodes } from "../types/random.type";
|
|
1
2
|
export declare const casing: {
|
|
2
3
|
readonly LOWER: "lower";
|
|
3
4
|
readonly UPPER: "upper";
|
|
4
5
|
};
|
|
5
6
|
export declare const booleanString: {
|
|
6
|
-
readonly
|
|
7
|
-
readonly
|
|
8
|
-
readonly TRUE_UPPERCASE: "TRUE";
|
|
9
|
-
readonly FALSE_UPPERCASE: "FALSE";
|
|
7
|
+
readonly TRUE: "true";
|
|
8
|
+
readonly FALSE: "false";
|
|
10
9
|
};
|
|
11
10
|
export declare const falsyValues: readonly [null, undefined, false, number, 0, 0, 0n, ""];
|
|
12
11
|
export declare const truthyValues: readonly [true, {}, readonly [], 42, "0", "false", Date, -42, 12n, 3.14, -3.14, number, number];
|
|
12
|
+
/**
|
|
13
|
+
* Based of https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status
|
|
14
|
+
*/
|
|
15
|
+
export declare const httpCodes: readonly [100, 101, 102, 103, 200, 201, 202, 203, 204, 205, 206, 207, 208, 226, 300, 301, 302, 303, 304, 305, 306, 307, 308, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 421, 422, 423, 424, 425, 426, 428, 429, 431, 451, 500, 501, 502, 503, 504, 505, 506, 507, 508, 510, 511];
|
|
16
|
+
/**
|
|
17
|
+
* Based of https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status
|
|
18
|
+
*/
|
|
19
|
+
export declare const httpCodesDictionary: Record<HttpCodes, string>;
|
|
13
20
|
//# sourceMappingURL=random.constant.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"random.constant.d.ts","sourceRoot":"","sources":["../../src/constants/random.constant.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM;;;CAGT,CAAC;AAEX,eAAO,MAAM,aAAa
|
|
1
|
+
{"version":3,"file":"random.constant.d.ts","sourceRoot":"","sources":["../../src/constants/random.constant.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,eAAO,MAAM,MAAM;;;CAGT,CAAC;AAEX,eAAO,MAAM,aAAa;;;CAGhB,CAAC;AAEX,eAAO,MAAM,WAAW,yDAUd,CAAC;AAEX,eAAO,MAAM,YAAY,iGAef,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,SAAS,sUAMZ,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,mBAAmB,EAAE,MAAM,CAAC,SAAS,EAAE,MAAM,CAgEhD,CAAC"}
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.truthyValues = exports.falsyValues = exports.booleanString = exports.casing = void 0;
|
|
3
|
+
exports.httpCodesDictionary = exports.httpCodes = exports.truthyValues = exports.falsyValues = exports.booleanString = exports.casing = void 0;
|
|
4
4
|
exports.casing = {
|
|
5
5
|
LOWER: "lower",
|
|
6
6
|
UPPER: "upper",
|
|
7
7
|
};
|
|
8
8
|
exports.booleanString = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
TRUE_UPPERCASE: "TRUE",
|
|
12
|
-
FALSE_UPPERCASE: "FALSE",
|
|
9
|
+
TRUE: "true",
|
|
10
|
+
FALSE: "false",
|
|
13
11
|
};
|
|
14
12
|
exports.falsyValues = [
|
|
15
13
|
// Based on https://developer.mozilla.org/en-US/docs/Glossary/Falsy
|
|
@@ -38,3 +36,81 @@ exports.truthyValues = [
|
|
|
38
36
|
Infinity,
|
|
39
37
|
-Infinity,
|
|
40
38
|
];
|
|
39
|
+
/**
|
|
40
|
+
* Based of https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status
|
|
41
|
+
*/
|
|
42
|
+
exports.httpCodes = [
|
|
43
|
+
100, 101, 102, 103, 200, 201, 202, 203, 204, 205, 206, 207, 208, 226, 300,
|
|
44
|
+
301, 302, 303, 304, 305, 306, 307, 308, 400, 401, 402, 403, 404, 405, 406,
|
|
45
|
+
407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 421, 422, 423,
|
|
46
|
+
424, 425, 426, 428, 429, 431, 451, 500, 501, 502, 503, 504, 505, 506, 507,
|
|
47
|
+
508, 510, 511,
|
|
48
|
+
];
|
|
49
|
+
/**
|
|
50
|
+
* Based of https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status
|
|
51
|
+
*/
|
|
52
|
+
exports.httpCodesDictionary = {
|
|
53
|
+
100: "Continue",
|
|
54
|
+
101: "Switching Protocols",
|
|
55
|
+
102: "Processing Deprecated",
|
|
56
|
+
103: "Early Hints",
|
|
57
|
+
200: "OK",
|
|
58
|
+
201: "Created",
|
|
59
|
+
202: "Accepted",
|
|
60
|
+
203: "Non-Authoritative Information",
|
|
61
|
+
204: "No Content",
|
|
62
|
+
205: "Reset Content",
|
|
63
|
+
206: "Partial Content",
|
|
64
|
+
207: "Multi-Status",
|
|
65
|
+
208: "Already Reported",
|
|
66
|
+
226: "IM Used",
|
|
67
|
+
300: "Multiple Choices",
|
|
68
|
+
301: "Moved Permanently",
|
|
69
|
+
302: "Found",
|
|
70
|
+
303: "See Other",
|
|
71
|
+
304: "Not Modified",
|
|
72
|
+
305: "Use Proxy",
|
|
73
|
+
306: "unused",
|
|
74
|
+
307: "Temporary Redirect",
|
|
75
|
+
308: "Permanent Redirect",
|
|
76
|
+
400: "Bad Request",
|
|
77
|
+
401: "Unauthorized",
|
|
78
|
+
402: "Payment Required",
|
|
79
|
+
403: "Forbidden",
|
|
80
|
+
404: "Not Found",
|
|
81
|
+
405: "Method Not Allowed",
|
|
82
|
+
406: "Not Acceptable",
|
|
83
|
+
407: "Proxy Authentication Required",
|
|
84
|
+
408: "Request Timeout",
|
|
85
|
+
409: "Conflict",
|
|
86
|
+
410: "Gone",
|
|
87
|
+
411: "Length Required",
|
|
88
|
+
412: "Precondition Failed",
|
|
89
|
+
413: "Content Too Large",
|
|
90
|
+
414: "URI Too Long",
|
|
91
|
+
415: "Unsupported Media Type",
|
|
92
|
+
416: "Range Not Satisfiable",
|
|
93
|
+
417: "Expectation Failed",
|
|
94
|
+
418: "I'm a teapot",
|
|
95
|
+
421: "Misdirected Request",
|
|
96
|
+
422: "Unprocessable Content",
|
|
97
|
+
423: "Locked",
|
|
98
|
+
424: "Failed Dependency",
|
|
99
|
+
425: "Too Early Experimental",
|
|
100
|
+
426: "Upgrade Required",
|
|
101
|
+
428: "Precondition Required",
|
|
102
|
+
429: "Too Many Requests",
|
|
103
|
+
431: "Request Header Fields Too Large",
|
|
104
|
+
451: "Unavailable For Legal Reasons",
|
|
105
|
+
500: "Internal Server Error",
|
|
106
|
+
501: "Not Implemented",
|
|
107
|
+
502: "Bad Gateway",
|
|
108
|
+
503: "Service Unavailable",
|
|
109
|
+
504: "Gateway Timeout",
|
|
110
|
+
505: "HTTP Version Not Supported",
|
|
111
|
+
506: "Variant Also Negotiates",
|
|
112
|
+
507: "Insufficient Storage",
|
|
113
|
+
508: "Loop Detected",
|
|
114
|
+
510: "Not Extended",
|
|
115
|
+
511: "Network Authentication Required",
|
|
116
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"time.constant.d.ts","sourceRoot":"","sources":["../../src/constants/time.constant.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM;;;;;;CAMT,CAAC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Casing } from "./types/random.type";
|
|
2
2
|
import { ObjectValues } from "./types/utils.type";
|
|
3
|
+
import { Gender } from "./types/name.type";
|
|
3
4
|
export declare class Random {
|
|
4
5
|
static intBetween(min: number, max: number): number;
|
|
5
6
|
static boolean(): boolean;
|
|
@@ -47,5 +48,60 @@ export declare class Random {
|
|
|
47
48
|
* @returns
|
|
48
49
|
*/
|
|
49
50
|
static uuid(): `${string}-${string}-${string}-${string}-${string}`;
|
|
51
|
+
/**
|
|
52
|
+
* Has a n% chance of throwing a error
|
|
53
|
+
* @param probabilityOfError - The probability of a error beeing thrown - i.e 0.2 = 20% chance
|
|
54
|
+
* @param errorMessage - The errormessage to be used instead of the default one
|
|
55
|
+
* @param callback - The callback that should be run if there's no error
|
|
56
|
+
* @returns
|
|
57
|
+
*/
|
|
58
|
+
static throwError(probabilityOfError: number, errorMessage?: string, callback?: Function): void;
|
|
59
|
+
/**
|
|
60
|
+
*
|
|
61
|
+
* @param minMs - Minimum milliseconds to delay
|
|
62
|
+
* @param maxMs - Maximum milliseconds to delay
|
|
63
|
+
* @param value - Optional return value
|
|
64
|
+
* @returns
|
|
65
|
+
*/
|
|
66
|
+
static delay<T>(minMs: number, maxMs: number, value?: T): Promise<T | undefined>;
|
|
67
|
+
/**
|
|
68
|
+
* Returns a name
|
|
69
|
+
* @param nameGender - Only male, female or unisex. If omitted, the name could be either one
|
|
70
|
+
* @returns
|
|
71
|
+
*/
|
|
72
|
+
static firstName(nameGender?: Gender): string;
|
|
73
|
+
/**
|
|
74
|
+
* Gives a surname/last name
|
|
75
|
+
* @returns
|
|
76
|
+
*/
|
|
77
|
+
static lastName(): "Lee" | "Taylor" | "Ahmed" | "Hassan" | "Martin" | "Ali" | "Anderson" | "Brown" | "Chen" | "Garcia" | "Ivanov" | "Khan" | "Kim" | "Li" | "Lopez" | "Mohamed" | "Nguyen" | "Patel" | "Rodriguez" | "Singh" | "Smith" | "Wang" | "Zhang" | "Andersson" | "Baker" | "Bianchi" | "Black" | "Blanco" | "Clark" | "Costa" | "Dubois" | "Evans" | "Fischer" | "Fisher" | "Fontana" | "Gonzalez" | "Hansen" | "Johansson" | "Jones" | "Kowalski" | "Larsen" | "Müller" | "Muller" | "Novak" | "Petrov" | "Rossi" | "Schmidt" | "Silva" | "Walker" | "White";
|
|
78
|
+
/**
|
|
79
|
+
* Gives a full name - first and last name
|
|
80
|
+
* @param nameGender
|
|
81
|
+
* @returns
|
|
82
|
+
*/
|
|
83
|
+
static fullName(nameGender?: Gender): string;
|
|
84
|
+
/**
|
|
85
|
+
* Get a http code i.e 200, 400
|
|
86
|
+
* @returns
|
|
87
|
+
*/
|
|
88
|
+
static httpStatusCode(): 100 | 101 | 102 | 103 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511;
|
|
89
|
+
/**
|
|
90
|
+
* Get a http status i.e Created, Accepted
|
|
91
|
+
* @returns
|
|
92
|
+
*/
|
|
93
|
+
static httpStatus(): string;
|
|
94
|
+
/**
|
|
95
|
+
* Returns a specific time as a localeTimeString
|
|
96
|
+
* @returns
|
|
97
|
+
*/
|
|
98
|
+
static time(): string;
|
|
99
|
+
/**
|
|
100
|
+
* Returns a date (and time) within the given range
|
|
101
|
+
* @param min - first date in range
|
|
102
|
+
* @param max - last date in range
|
|
103
|
+
* @returns
|
|
104
|
+
*/
|
|
105
|
+
static date(min: Date, max: Date): Date;
|
|
50
106
|
}
|
|
51
107
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAiB,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAqB,MAAM,oBAAoB,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,qBAAa,MAAM;IACjB,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM;IAY1C,MAAM,CAAC,OAAO;IAId;;;;OAIG;IACH,MAAM,CAAC,aAAa,CAAC,aAAa,CAAC,EAAE,MAAM;IAM3C;;;OAGG;IACH,MAAM,CAAC,UAAU;IAIjB;;;OAGG;IACH,MAAM,CAAC,KAAK;IAIZ;;;OAGG;IACH,MAAM,CAAC,MAAM;IAIb;;;;OAIG;IACH,MAAM,CAAC,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,GAAG,CAAC;IAMnC;;;;OAIG;IACH,MAAM,CAAC,UAAU,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC;IAK/D;;;;OAIG;IACH,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,MAAM;IAYnC;;;OAGG;IACH,MAAM,CAAC,IAAI;IAIX;;;;;;OAMG;IACH,MAAM,CAAC,UAAU,CACf,kBAAkB,EAAE,MAAM,EAC1B,YAAY,CAAC,EAAE,MAAM,EACrB,QAAQ,CAAC,EAAE,QAAQ,GAClB,IAAI;IAkBP;;;;;;OAMG;WACU,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC;IAS7D;;;;OAIG;IACH,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,MAAM;IAepC;;;OAGG;IACH,MAAM,CAAC,QAAQ;IAIf;;;;OAIG;IACH,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM;IAInC;;;OAGG;IACH,MAAM,CAAC,cAAc;IAIrB;;;OAGG;IACH,MAAM,CAAC,UAAU;IAKjB;;;OAGG;IACH,MAAM,CAAC,IAAI;IAKX;;;;;OAKG;IACH,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI;CAUjC"}
|
package/lib/index.js
CHANGED
|
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Random = void 0;
|
|
4
4
|
const chars_constant_1 = require("./constants/chars.constant");
|
|
5
5
|
const random_constant_1 = require("./constants/random.constant");
|
|
6
|
+
const name_constant_1 = require("./constants/name.constant");
|
|
7
|
+
const time_constant_1 = require("./constants/time.constant");
|
|
6
8
|
class Random {
|
|
7
9
|
static intBetween(min, max) {
|
|
8
10
|
// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random
|
|
@@ -26,9 +28,7 @@ class Random {
|
|
|
26
28
|
static booleanString(booleanCasing) {
|
|
27
29
|
if (!booleanCasing)
|
|
28
30
|
booleanCasing = random_constant_1.casing.LOWER;
|
|
29
|
-
const result = Random.boolean()
|
|
30
|
-
? random_constant_1.booleanString.TRUE_LOWERCASE
|
|
31
|
-
: random_constant_1.booleanString.FALSE_UPPERCASE;
|
|
31
|
+
const result = Random.boolean() ? random_constant_1.booleanString.TRUE : random_constant_1.booleanString.FALSE;
|
|
32
32
|
return booleanCasing === random_constant_1.casing.LOWER ? result : result.toUpperCase();
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
@@ -93,5 +93,113 @@ class Random {
|
|
|
93
93
|
static uuid() {
|
|
94
94
|
return crypto.randomUUID();
|
|
95
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Has a n% chance of throwing a error
|
|
98
|
+
* @param probabilityOfError - The probability of a error beeing thrown - i.e 0.2 = 20% chance
|
|
99
|
+
* @param errorMessage - The errormessage to be used instead of the default one
|
|
100
|
+
* @param callback - The callback that should be run if there's no error
|
|
101
|
+
* @returns
|
|
102
|
+
*/
|
|
103
|
+
static throwError(probabilityOfError, errorMessage, callback) {
|
|
104
|
+
if (probabilityOfError < 0 || probabilityOfError > 1) {
|
|
105
|
+
// Trying a warning instead of throwing a error since it would probably
|
|
106
|
+
// be masked by the actual intent - throwing a error sometimes
|
|
107
|
+
console.warn("The probability needs to be between 0 and 1");
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
if (Math.random() < probabilityOfError) {
|
|
111
|
+
errorMessage ??= "This is a randomly triggered error";
|
|
112
|
+
throw new Error(errorMessage);
|
|
113
|
+
}
|
|
114
|
+
if (callback) {
|
|
115
|
+
callback();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
*
|
|
120
|
+
* @param minMs - Minimum milliseconds to delay
|
|
121
|
+
* @param maxMs - Maximum milliseconds to delay
|
|
122
|
+
* @param value - Optional return value
|
|
123
|
+
* @returns
|
|
124
|
+
*/
|
|
125
|
+
static async delay(minMs, maxMs, value) {
|
|
126
|
+
return new Promise((resolve, reject) => {
|
|
127
|
+
const delayInMs = Random.intBetween(minMs, maxMs);
|
|
128
|
+
setTimeout(() => {
|
|
129
|
+
resolve(value);
|
|
130
|
+
}, delayInMs);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Returns a name
|
|
135
|
+
* @param nameGender - Only male, female or unisex. If omitted, the name could be either one
|
|
136
|
+
* @returns
|
|
137
|
+
*/
|
|
138
|
+
static firstName(nameGender) {
|
|
139
|
+
const namePool = [];
|
|
140
|
+
if (!nameGender || nameGender === name_constant_1.gender.UNISEX) {
|
|
141
|
+
namePool.push(...name_constant_1.firstNameNeutral);
|
|
142
|
+
}
|
|
143
|
+
if (!nameGender || nameGender === name_constant_1.gender.MALE) {
|
|
144
|
+
namePool.push(...name_constant_1.firstNameMale);
|
|
145
|
+
}
|
|
146
|
+
if (!nameGender || nameGender === name_constant_1.gender.FEMALE) {
|
|
147
|
+
namePool.push(...name_constant_1.firstNameFemale);
|
|
148
|
+
}
|
|
149
|
+
return Random.fromArray(namePool);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Gives a surname/last name
|
|
153
|
+
* @returns
|
|
154
|
+
*/
|
|
155
|
+
static lastName() {
|
|
156
|
+
return Random.fromArray([...name_constant_1.lastname]);
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Gives a full name - first and last name
|
|
160
|
+
* @param nameGender
|
|
161
|
+
* @returns
|
|
162
|
+
*/
|
|
163
|
+
static fullName(nameGender) {
|
|
164
|
+
return `${Random.firstName(nameGender)} ${Random.lastName()}`;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Get a http code i.e 200, 400
|
|
168
|
+
* @returns
|
|
169
|
+
*/
|
|
170
|
+
static httpStatusCode() {
|
|
171
|
+
return Random.fromArray([...random_constant_1.httpCodes]);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Get a http status i.e Created, Accepted
|
|
175
|
+
* @returns
|
|
176
|
+
*/
|
|
177
|
+
static httpStatus() {
|
|
178
|
+
const randomStatusCode = Random.httpStatusCode();
|
|
179
|
+
return random_constant_1.httpCodesDictionary[randomStatusCode];
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Returns a specific time as a localeTimeString
|
|
183
|
+
* @returns
|
|
184
|
+
*/
|
|
185
|
+
static time() {
|
|
186
|
+
const randomMillis = Random.intBetween(0, time_constant_1.millis.DAY);
|
|
187
|
+
return new Date(randomMillis).toLocaleTimeString();
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Returns a date (and time) within the given range
|
|
191
|
+
* @param min - first date in range
|
|
192
|
+
* @param max - last date in range
|
|
193
|
+
* @returns
|
|
194
|
+
*/
|
|
195
|
+
static date(min, max) {
|
|
196
|
+
if (max.getTime() < min.getTime()) {
|
|
197
|
+
const oldMin = min;
|
|
198
|
+
min = max;
|
|
199
|
+
max = oldMin;
|
|
200
|
+
}
|
|
201
|
+
const randomDate = Random.intBetween(min.getTime(), max.getTime());
|
|
202
|
+
return new Date(randomDate);
|
|
203
|
+
}
|
|
96
204
|
}
|
|
97
205
|
exports.Random = Random;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"name.type.d.ts","sourceRoot":"","sources":["../../src/types/name.type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAEpD,MAAM,MAAM,MAAM,GAAG,CAAC,OAAO,MAAM,CAAC,CAAC,MAAM,OAAO,MAAM,CAAC,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { booleanString, casing } from "../constants/random.constant";
|
|
1
|
+
import { booleanString, casing, httpCodes } from "../constants/random.constant";
|
|
2
2
|
export type Casing = (typeof casing)[keyof typeof casing];
|
|
3
3
|
export type BooleanString = (typeof booleanString)[keyof typeof booleanString];
|
|
4
|
+
export type HttpCodes = (typeof httpCodes)[number];
|
|
4
5
|
//# sourceMappingURL=random.type.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"random.type.d.ts","sourceRoot":"","sources":["../../src/types/random.type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"random.type.d.ts","sourceRoot":"","sources":["../../src/types/random.type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAEhF,MAAM,MAAM,MAAM,GAAG,CAAC,OAAO,MAAM,CAAC,CAAC,MAAM,OAAO,MAAM,CAAC,CAAC;AAE1D,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,OAAO,aAAa,CAAC,CAAC;AAE/E,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kottetall/random",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -22,11 +22,14 @@
|
|
|
22
22
|
"helpers",
|
|
23
23
|
"javascript",
|
|
24
24
|
"node",
|
|
25
|
-
"array",
|
|
26
|
-
"object",
|
|
27
25
|
"picker",
|
|
28
26
|
"random-picker",
|
|
29
|
-
"random-value"
|
|
27
|
+
"random-value",
|
|
28
|
+
"test data",
|
|
29
|
+
"mock data",
|
|
30
|
+
"mock",
|
|
31
|
+
"random data generation",
|
|
32
|
+
"random name"
|
|
30
33
|
],
|
|
31
34
|
"author": "",
|
|
32
35
|
"license": "ISC",
|
package/readme.md
CHANGED
|
@@ -6,8 +6,8 @@ This package was originally created for personal use in my own projects, but it
|
|
|
6
6
|
|
|
7
7
|
## Features
|
|
8
8
|
|
|
9
|
-
- Get a random value from an array
|
|
10
|
-
- Get a random
|
|
9
|
+
- Get a random value from an array / object
|
|
10
|
+
- Get a random name - first, last, full
|
|
11
11
|
- Get a random letter
|
|
12
12
|
- Get a random truthy/falsy value
|
|
13
13
|
- And more...
|
|
@@ -23,6 +23,17 @@ npm install @kottetall/random
|
|
|
23
23
|
|
|
24
24
|
## Usage
|
|
25
25
|
|
|
26
|
+
### Random names
|
|
27
|
+
|
|
28
|
+
```js
|
|
29
|
+
import { Random } from "@kottetall/random";
|
|
30
|
+
|
|
31
|
+
console.log(Random.firstName()); // Jack
|
|
32
|
+
console.log(Random.firstName("female")); // Sofia
|
|
33
|
+
console.log(Random.lastName()); // White
|
|
34
|
+
console.log(Random.fullName()); // Jack Hassan
|
|
35
|
+
```
|
|
36
|
+
|
|
26
37
|
### Random value from an array
|
|
27
38
|
|
|
28
39
|
```js
|