@anddone/coretestautomation 1.0.1
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/.github/workflows/npm-release.yml +102 -0
- package/dist/api/base.api.d.ts +32 -0
- package/dist/api/base.api.d.ts.map +1 -0
- package/dist/api/base.api.js +7 -0
- package/dist/api/base.api.js.map +1 -0
- package/dist/api/headers.d.ts +6 -0
- package/dist/api/headers.d.ts.map +1 -0
- package/dist/api/headers.js +23 -0
- package/dist/api/headers.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/pages/basepage.d.ts +6 -0
- package/dist/pages/basepage.d.ts.map +1 -0
- package/dist/pages/basepage.js +10 -0
- package/dist/pages/basepage.js.map +1 -0
- package/dist/testData/api.data.json +6 -0
- package/dist/utils/apiUtils.d.ts +123 -0
- package/dist/utils/apiUtils.d.ts.map +1 -0
- package/dist/utils/apiUtils.js +264 -0
- package/dist/utils/apiUtils.js.map +1 -0
- package/dist/utils/assertionUtils.d.ts +223 -0
- package/dist/utils/assertionUtils.d.ts.map +1 -0
- package/dist/utils/assertionUtils.js +400 -0
- package/dist/utils/assertionUtils.js.map +1 -0
- package/dist/utils/commonUtils.d.ts +590 -0
- package/dist/utils/commonUtils.d.ts.map +1 -0
- package/dist/utils/commonUtils.js +1292 -0
- package/dist/utils/commonUtils.js.map +1 -0
- package/dist/utils/fakerStaticData.d.ts +16 -0
- package/dist/utils/fakerStaticData.d.ts.map +1 -0
- package/dist/utils/fakerStaticData.js +88 -0
- package/dist/utils/fakerStaticData.js.map +1 -0
- package/dist/utils/fileCommonUtils.d.ts +22 -0
- package/dist/utils/fileCommonUtils.d.ts.map +1 -0
- package/dist/utils/fileCommonUtils.js +243 -0
- package/dist/utils/fileCommonUtils.js.map +1 -0
- package/dist/utils/generationUtils.d.ts +424 -0
- package/dist/utils/generationUtils.d.ts.map +1 -0
- package/dist/utils/generationUtils.js +869 -0
- package/dist/utils/generationUtils.js.map +1 -0
- package/dist/utils/pageUtils.d.ts +90 -0
- package/dist/utils/pageUtils.d.ts.map +1 -0
- package/dist/utils/pageUtils.js +214 -0
- package/dist/utils/pageUtils.js.map +1 -0
- package/dist/utils/tableUtils.d.ts +304 -0
- package/dist/utils/tableUtils.d.ts.map +1 -0
- package/dist/utils/tableUtils.js +555 -0
- package/dist/utils/tableUtils.js.map +1 -0
- package/dist/utils/validationUtils.d.ts +80 -0
- package/dist/utils/validationUtils.d.ts.map +1 -0
- package/dist/utils/validationUtils.js +172 -0
- package/dist/utils/validationUtils.js.map +1 -0
- package/package.json +23 -0
- package/playwright.config.ts +79 -0
- package/src/api/base.api.ts +39 -0
- package/src/api/headers.ts +17 -0
- package/src/index.ts +12 -0
- package/src/pages/basepage.ts +11 -0
- package/src/testData/api.data.json +6 -0
- package/src/types/pdf-parse.d.ts +6 -0
- package/src/utils/apiUtils.ts +307 -0
- package/src/utils/assertionUtils.ts +455 -0
- package/src/utils/commonUtils.ts +1544 -0
- package/src/utils/fakerStaticData.ts +91 -0
- package/src/utils/fileCommonUtils.ts +239 -0
- package/src/utils/generationUtils.ts +929 -0
- package/src/utils/pageUtils.ts +224 -0
- package/src/utils/tableUtils.ts +715 -0
- package/src/utils/validationUtils.ts +179 -0
- package/tsconfig.json +19 -0
|
@@ -0,0 +1,869 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GenerationUtils = void 0;
|
|
4
|
+
const date_fns_1 = require("date-fns");
|
|
5
|
+
const date_fns_tz_1 = require("date-fns-tz");
|
|
6
|
+
const fakerStaticData_1 = require("./fakerStaticData");
|
|
7
|
+
class GenerationUtils {
|
|
8
|
+
/**
|
|
9
|
+
* Returns a random integer between min and max (inclusive).
|
|
10
|
+
*
|
|
11
|
+
* @param min Minimum number (inclusive)
|
|
12
|
+
* @param max Maximum number (inclusive)
|
|
13
|
+
* @returns Random number between min and max
|
|
14
|
+
*
|
|
15
|
+
* Example:
|
|
16
|
+
* randomNumber(1, 10) → 7
|
|
17
|
+
*/
|
|
18
|
+
static randomNumber(min, max) {
|
|
19
|
+
try {
|
|
20
|
+
if (min > max) {
|
|
21
|
+
return 0;
|
|
22
|
+
}
|
|
23
|
+
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return 0;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Returns a random floating-point number between min and max.
|
|
31
|
+
*
|
|
32
|
+
* @param min Minimum number
|
|
33
|
+
* @param max Maximum number
|
|
34
|
+
* @param decimals Number of decimal places (default: 2)
|
|
35
|
+
* @returns Random float between min and max
|
|
36
|
+
*
|
|
37
|
+
* Example:
|
|
38
|
+
* randomFloat(1, 5, 2) → 3.47
|
|
39
|
+
*/
|
|
40
|
+
static randomFloat(min, max, decimals = 2) {
|
|
41
|
+
try {
|
|
42
|
+
if (min > max) {
|
|
43
|
+
return 0;
|
|
44
|
+
}
|
|
45
|
+
const value = Math.random() * (max - min) + min;
|
|
46
|
+
return Number(value.toFixed(decimals));
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return 0;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Returns a random boolean value.
|
|
54
|
+
*
|
|
55
|
+
* @returns true or false
|
|
56
|
+
*
|
|
57
|
+
* Example:
|
|
58
|
+
* randomBoolean() → true
|
|
59
|
+
*/
|
|
60
|
+
static randomBoolean() {
|
|
61
|
+
try {
|
|
62
|
+
return Math.random() < 0.5;
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Returns a random element from an array.
|
|
70
|
+
*
|
|
71
|
+
* @param values Array of values
|
|
72
|
+
* @returns Random element or null if array is empty
|
|
73
|
+
*
|
|
74
|
+
* Example:
|
|
75
|
+
* randomFromArray(["A", "B", "C"]) → "B"
|
|
76
|
+
*/
|
|
77
|
+
static randomFromArray(values) {
|
|
78
|
+
try {
|
|
79
|
+
if (!values || values.length === 0)
|
|
80
|
+
return null;
|
|
81
|
+
const index = Math.floor(Math.random() * values.length);
|
|
82
|
+
return values[index];
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Returns a random valid index for an array.
|
|
90
|
+
*
|
|
91
|
+
* @param max Length of the array
|
|
92
|
+
* @returns Random index between 0 and max - 1
|
|
93
|
+
*
|
|
94
|
+
* Example:
|
|
95
|
+
* randomIndex(5) → 3
|
|
96
|
+
*/
|
|
97
|
+
static randomIndex(max) {
|
|
98
|
+
try {
|
|
99
|
+
if (max <= 0) {
|
|
100
|
+
return 0;
|
|
101
|
+
}
|
|
102
|
+
return Math.floor(Math.random() * max);
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
return 0;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Returns a random alphabetic string (A–Z, a–z).
|
|
110
|
+
*
|
|
111
|
+
* @param length Length of the string
|
|
112
|
+
* @returns Random alphabetic string
|
|
113
|
+
*
|
|
114
|
+
* Example:
|
|
115
|
+
* randomAlphaString(5) → "aZxQe"
|
|
116
|
+
*/
|
|
117
|
+
static randomAlphaString(length) {
|
|
118
|
+
try {
|
|
119
|
+
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
120
|
+
return this.generateRandomFromCharset(chars, length);
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
return "";
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Returns a random numeric string (0–9).
|
|
128
|
+
*
|
|
129
|
+
* @param length Length of the string
|
|
130
|
+
* @returns Random numeric string
|
|
131
|
+
*
|
|
132
|
+
* Example:
|
|
133
|
+
* randomNumericString(4) → "4829"
|
|
134
|
+
*/
|
|
135
|
+
static randomNumericString(length) {
|
|
136
|
+
try {
|
|
137
|
+
const chars = "0123456789";
|
|
138
|
+
return this.generateRandomFromCharset(chars, length);
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
return "";
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Returns a random alphanumeric string (letters + numbers).
|
|
146
|
+
*
|
|
147
|
+
* @param length Length of the string
|
|
148
|
+
* @returns Random alphanumeric string
|
|
149
|
+
*
|
|
150
|
+
* Example:
|
|
151
|
+
* randomAlphaNumericString(8) → "A9bX2Lq7"
|
|
152
|
+
*/
|
|
153
|
+
static randomAlphaNumericString(length) {
|
|
154
|
+
try {
|
|
155
|
+
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
156
|
+
return this.generateRandomFromCharset(chars, length);
|
|
157
|
+
}
|
|
158
|
+
catch {
|
|
159
|
+
return "";
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Internal helper to generate random string from a given character set.
|
|
164
|
+
*
|
|
165
|
+
* @param chars Allowed characters
|
|
166
|
+
* @param length Length of string
|
|
167
|
+
* @returns Random string
|
|
168
|
+
*/
|
|
169
|
+
static generateRandomFromCharset(chars, length) {
|
|
170
|
+
try {
|
|
171
|
+
if (length <= 0)
|
|
172
|
+
return "";
|
|
173
|
+
let result = "";
|
|
174
|
+
for (let i = 0; i < length; i++) {
|
|
175
|
+
result += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
176
|
+
}
|
|
177
|
+
return result;
|
|
178
|
+
}
|
|
179
|
+
catch {
|
|
180
|
+
return "";
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Returns a random first name.
|
|
185
|
+
*
|
|
186
|
+
* @returns Random first name
|
|
187
|
+
*
|
|
188
|
+
* Example:
|
|
189
|
+
* randomFirstName() → "Rahul"
|
|
190
|
+
*/
|
|
191
|
+
static randomFirstName() {
|
|
192
|
+
try {
|
|
193
|
+
return fakerStaticData_1.FIRST_NAMES[Math.floor(Math.random() * fakerStaticData_1.FIRST_NAMES.length)];
|
|
194
|
+
}
|
|
195
|
+
catch {
|
|
196
|
+
return "";
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Returns a random last name.
|
|
201
|
+
*
|
|
202
|
+
* @returns Random last name
|
|
203
|
+
*
|
|
204
|
+
* Example:
|
|
205
|
+
* randomLastName() → "Sharma"
|
|
206
|
+
*/
|
|
207
|
+
static randomLastName() {
|
|
208
|
+
try {
|
|
209
|
+
return fakerStaticData_1.LAST_NAMES[Math.floor(Math.random() * fakerStaticData_1.LAST_NAMES.length)];
|
|
210
|
+
}
|
|
211
|
+
catch {
|
|
212
|
+
return "";
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Returns a random full name (first name + last name).
|
|
217
|
+
*
|
|
218
|
+
* @returns Random full name
|
|
219
|
+
*
|
|
220
|
+
* Example:
|
|
221
|
+
* randomFullName() → "Rahul Sharma"
|
|
222
|
+
*/
|
|
223
|
+
static randomFullName() {
|
|
224
|
+
try {
|
|
225
|
+
return `${this.randomFirstName()} ${this.randomLastName()}`;
|
|
226
|
+
}
|
|
227
|
+
catch {
|
|
228
|
+
return "";
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Returns a random username generated from name and number.
|
|
233
|
+
*
|
|
234
|
+
* @returns Random username
|
|
235
|
+
*
|
|
236
|
+
* Example:
|
|
237
|
+
* randomUsername() → "rahul.sharma482"
|
|
238
|
+
*/
|
|
239
|
+
static randomUsername() {
|
|
240
|
+
try {
|
|
241
|
+
const first = this.randomFirstName().toLowerCase();
|
|
242
|
+
const last = this.randomLastName().toLowerCase();
|
|
243
|
+
const number = Math.floor(Math.random() * 1000);
|
|
244
|
+
return `${first}.${last}${number}`;
|
|
245
|
+
}
|
|
246
|
+
catch {
|
|
247
|
+
return "";
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Returns a random email address.
|
|
252
|
+
*
|
|
253
|
+
* @returns Random email string
|
|
254
|
+
*
|
|
255
|
+
* Example:
|
|
256
|
+
* randomEmail() → "rahul.sharma482@gmail.com"
|
|
257
|
+
*/
|
|
258
|
+
static randomEmail() {
|
|
259
|
+
try {
|
|
260
|
+
const first = this.randomFirstName().toLowerCase();
|
|
261
|
+
const last = this.randomLastName().toLowerCase();
|
|
262
|
+
const number = Math.floor(Math.random() * 1000);
|
|
263
|
+
const domain = fakerStaticData_1.EMAIL_DOMAINS[Math.floor(Math.random() * fakerStaticData_1.EMAIL_DOMAINS.length)];
|
|
264
|
+
return `${first}.${last}${number}@${domain}`;
|
|
265
|
+
}
|
|
266
|
+
catch {
|
|
267
|
+
return "";
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Returns a random country calling code.
|
|
272
|
+
*
|
|
273
|
+
* @returns Country code string (e.g. "+91")
|
|
274
|
+
*
|
|
275
|
+
* Example:
|
|
276
|
+
* randomCountryCode() → "+91"
|
|
277
|
+
*/
|
|
278
|
+
static randomCountryCode() {
|
|
279
|
+
try {
|
|
280
|
+
return fakerStaticData_1.COUNTRY_CODES[Math.floor(Math.random() * fakerStaticData_1.COUNTRY_CODES.length)];
|
|
281
|
+
}
|
|
282
|
+
catch {
|
|
283
|
+
return "";
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Returns a random phone number with country code.
|
|
288
|
+
*
|
|
289
|
+
* @returns Phone number string
|
|
290
|
+
*
|
|
291
|
+
* Example:
|
|
292
|
+
* randomPhoneNumber() → "+91 9876543210"
|
|
293
|
+
*/
|
|
294
|
+
static randomPhoneNumber() {
|
|
295
|
+
try {
|
|
296
|
+
const countryCode = this.randomCountryCode();
|
|
297
|
+
// Generate a 10-digit phone number
|
|
298
|
+
let number = "";
|
|
299
|
+
for (let i = 0; i < 10; i++) {
|
|
300
|
+
number += Math.floor(Math.random() * 10);
|
|
301
|
+
}
|
|
302
|
+
return `${countryCode} ${number}`;
|
|
303
|
+
}
|
|
304
|
+
catch {
|
|
305
|
+
return "";
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Returns a random US phone number.
|
|
310
|
+
*
|
|
311
|
+
* Format: +1 XXX-XXX-XXXX
|
|
312
|
+
*
|
|
313
|
+
* @returns US phone number string
|
|
314
|
+
*
|
|
315
|
+
* Example:
|
|
316
|
+
* getRandomUSPhoneNumber() → "+1 415-782-3490"
|
|
317
|
+
*/
|
|
318
|
+
static getRandomUSPhoneNumber() {
|
|
319
|
+
try {
|
|
320
|
+
const countryCode = "+1";
|
|
321
|
+
// Area code (2–9 followed by 2 digits)
|
|
322
|
+
const areaCode = Math.floor(Math.random() * 8 + 2).toString() +
|
|
323
|
+
Math.floor(Math.random() * 10) +
|
|
324
|
+
Math.floor(Math.random() * 10);
|
|
325
|
+
// Exchange code (2–9 followed by 2 digits)
|
|
326
|
+
const exchangeCode = Math.floor(Math.random() * 8 + 2).toString() +
|
|
327
|
+
Math.floor(Math.random() * 10) +
|
|
328
|
+
Math.floor(Math.random() * 10);
|
|
329
|
+
// Line number (4 digits)
|
|
330
|
+
const lineNumber = Math.floor(1000 + Math.random() * 9000);
|
|
331
|
+
return `${countryCode} ${areaCode}-${exchangeCode}-${lineNumber}`;
|
|
332
|
+
}
|
|
333
|
+
catch {
|
|
334
|
+
return "";
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Generates a random user object containing basic identity and contact details.
|
|
339
|
+
*
|
|
340
|
+
* @returns Generated fields include:
|
|
341
|
+
* - First name
|
|
342
|
+
* - Last name
|
|
343
|
+
* - Full name (first + last)
|
|
344
|
+
* - Username (lowercased name with numeric suffix)
|
|
345
|
+
* - Email address (using common email domains)
|
|
346
|
+
*
|
|
347
|
+
* - Generic phone number (with random country code)
|
|
348
|
+
* - US-specific phone number
|
|
349
|
+
*/
|
|
350
|
+
static generateUserObject() {
|
|
351
|
+
try {
|
|
352
|
+
const firstName = this.randomFirstName();
|
|
353
|
+
const lastName = this.randomLastName();
|
|
354
|
+
const fullName = firstName + " " + lastName;
|
|
355
|
+
const number = Math.floor(Math.random() * 1000);
|
|
356
|
+
const username = `${firstName.toLowerCase()}.${lastName.toLowerCase()}${number}`;
|
|
357
|
+
const domain = fakerStaticData_1.EMAIL_DOMAINS[Math.floor(Math.random() * fakerStaticData_1.EMAIL_DOMAINS.length)];
|
|
358
|
+
const email = `${firstName}.${lastName}${number}@${domain}`;
|
|
359
|
+
const phoneNo = this.randomPhoneNumber();
|
|
360
|
+
const usPhone = this.getRandomUSPhoneNumber();
|
|
361
|
+
return {
|
|
362
|
+
firstName,
|
|
363
|
+
lastName,
|
|
364
|
+
fullName,
|
|
365
|
+
username,
|
|
366
|
+
email,
|
|
367
|
+
phoneNo,
|
|
368
|
+
usPhone,
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
catch {
|
|
372
|
+
return {
|
|
373
|
+
firstName: "",
|
|
374
|
+
lastName: "",
|
|
375
|
+
fullName: "",
|
|
376
|
+
username: "",
|
|
377
|
+
email: "",
|
|
378
|
+
phoneNo: "",
|
|
379
|
+
usPhone: "",
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
static generateIndiaPincode(prefix) {
|
|
384
|
+
try {
|
|
385
|
+
let pincode = prefix;
|
|
386
|
+
for (let i = 0; i < 5; i++) {
|
|
387
|
+
pincode += Math.floor(Math.random() * 10);
|
|
388
|
+
}
|
|
389
|
+
return pincode;
|
|
390
|
+
}
|
|
391
|
+
catch {
|
|
392
|
+
return "";
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Returns a random India location (country, state, city).
|
|
397
|
+
*
|
|
398
|
+
* @returns Object containing country, state, and city
|
|
399
|
+
*
|
|
400
|
+
* Example:
|
|
401
|
+
* getRandomIndiaLocation()
|
|
402
|
+
* → { country: "India", state: "Karnataka", city: "Bengaluru", pincode: "560102" }
|
|
403
|
+
*/
|
|
404
|
+
static getRandomIndiaLocation() {
|
|
405
|
+
try {
|
|
406
|
+
const stateObj = fakerStaticData_1.INDIA_LOCATIONS[Math.floor(Math.random() * fakerStaticData_1.INDIA_LOCATIONS.length)];
|
|
407
|
+
const city = stateObj.cities[Math.floor(Math.random() * stateObj.cities.length)];
|
|
408
|
+
const pincode = this.generateIndiaPincode(stateObj.pincodePrefix);
|
|
409
|
+
return {
|
|
410
|
+
country: "India",
|
|
411
|
+
state: stateObj.state,
|
|
412
|
+
city,
|
|
413
|
+
pincode
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
catch {
|
|
417
|
+
return {
|
|
418
|
+
country: "",
|
|
419
|
+
state: "",
|
|
420
|
+
city: "",
|
|
421
|
+
pincode: ""
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
static generateUSZipCode() {
|
|
426
|
+
try {
|
|
427
|
+
let zip = "";
|
|
428
|
+
for (let i = 0; i < 5; i++) {
|
|
429
|
+
zip += Math.floor(Math.random() * 10);
|
|
430
|
+
}
|
|
431
|
+
return zip;
|
|
432
|
+
}
|
|
433
|
+
catch {
|
|
434
|
+
return "";
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* Returns a random USA location (country, state, city).
|
|
439
|
+
*
|
|
440
|
+
* @returns Object containing country, state, and city
|
|
441
|
+
*
|
|
442
|
+
* Example:
|
|
443
|
+
* getRandomUSALocation()
|
|
444
|
+
* → { country: "United States", state: "California", city: "San Diego" }
|
|
445
|
+
*/
|
|
446
|
+
static getRandomUSALocation() {
|
|
447
|
+
try {
|
|
448
|
+
const stateObj = fakerStaticData_1.USA_LOCATIONS[Math.floor(Math.random() * fakerStaticData_1.USA_LOCATIONS.length)];
|
|
449
|
+
const city = stateObj.cities[Math.floor(Math.random() * stateObj.cities.length)];
|
|
450
|
+
return {
|
|
451
|
+
country: "United States",
|
|
452
|
+
state: stateObj.state,
|
|
453
|
+
city,
|
|
454
|
+
zipCode: this.generateUSZipCode()
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
catch {
|
|
458
|
+
return {
|
|
459
|
+
country: "",
|
|
460
|
+
state: "",
|
|
461
|
+
city: "",
|
|
462
|
+
zipCode: ""
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* Returns a random address line.
|
|
468
|
+
*
|
|
469
|
+
* @returns Random address line
|
|
470
|
+
*
|
|
471
|
+
* Example:
|
|
472
|
+
* randomAddressLine() → "Flat 302, MG Road"
|
|
473
|
+
*/
|
|
474
|
+
static randomAddressLine() {
|
|
475
|
+
try {
|
|
476
|
+
const buildingNumber = Math.floor(Math.random() * 900) + 100;
|
|
477
|
+
const street = fakerStaticData_1.STREET_NAMES[Math.floor(Math.random() * fakerStaticData_1.STREET_NAMES.length)];
|
|
478
|
+
return `Flat ${buildingNumber}, ${street}`;
|
|
479
|
+
}
|
|
480
|
+
catch {
|
|
481
|
+
return "";
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* Returns a random UUID.
|
|
486
|
+
*
|
|
487
|
+
* @returns Random UUID string
|
|
488
|
+
*
|
|
489
|
+
* Example:
|
|
490
|
+
* randomUUID() → "f47ac10b-58cc-4372-a567-0e02b2c3d479"
|
|
491
|
+
*/
|
|
492
|
+
static randomUUID() {
|
|
493
|
+
try {
|
|
494
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, char => {
|
|
495
|
+
const rand = Math.random() * 16 | 0;
|
|
496
|
+
const value = char === "x" ? rand : (rand & 0x3 | 0x8);
|
|
497
|
+
return value.toString(16);
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
catch {
|
|
501
|
+
return "";
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* Returns a random lorem sentence.
|
|
506
|
+
*
|
|
507
|
+
* @param wordCount Optional number of words in the sentence
|
|
508
|
+
* @returns Random lorem sentence string
|
|
509
|
+
*
|
|
510
|
+
* Example:
|
|
511
|
+
* randomLoremSentence() → "Lorem ipsum dolor sit amet."
|
|
512
|
+
* randomLoremSentence(8) → "Lorem ipsum dolor sit amet consectetur elit."
|
|
513
|
+
*/
|
|
514
|
+
static randomLoremSentence(wordCount = 8) {
|
|
515
|
+
try {
|
|
516
|
+
if (wordCount <= 0)
|
|
517
|
+
return "";
|
|
518
|
+
const words = [];
|
|
519
|
+
for (let i = 0; i < wordCount; i++) {
|
|
520
|
+
words.push(fakerStaticData_1.LOREM_WORDS[i % fakerStaticData_1.LOREM_WORDS.length]);
|
|
521
|
+
}
|
|
522
|
+
const sentence = words.join(" ").charAt(0).toUpperCase() +
|
|
523
|
+
words.join(" ").slice(1) +
|
|
524
|
+
".";
|
|
525
|
+
return sentence;
|
|
526
|
+
}
|
|
527
|
+
catch {
|
|
528
|
+
return "";
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
/**
|
|
532
|
+
* Returns the current date formatted in the given timezone.
|
|
533
|
+
*
|
|
534
|
+
* @param timezone IANA timezone
|
|
535
|
+
* @param format date-fns format string
|
|
536
|
+
* @returns formatted date string
|
|
537
|
+
*
|
|
538
|
+
* Example:
|
|
539
|
+
* getCurrentDateByTimezoneFormat("Asia/Kolkata", "dd/MM/yyyy") → "07/01/2026"
|
|
540
|
+
*/
|
|
541
|
+
static getCurrentDateByTimezoneFormat(timezone, format) {
|
|
542
|
+
try {
|
|
543
|
+
const currentDate = new Date();
|
|
544
|
+
return (0, date_fns_tz_1.formatInTimeZone)(currentDate, timezone, format);
|
|
545
|
+
}
|
|
546
|
+
catch {
|
|
547
|
+
return "";
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
/**
|
|
551
|
+
* Parses a date string using the provided format.
|
|
552
|
+
*
|
|
553
|
+
* @param dateStr input date string
|
|
554
|
+
* @param format date-fns format describing the input
|
|
555
|
+
* @returns Date object if valid, otherwise null
|
|
556
|
+
*
|
|
557
|
+
* Example:
|
|
558
|
+
* parseDate("02/Jan/2003", "dd/MMM/yyyy") -> 2003-01-01T18:30:00.000Z
|
|
559
|
+
*/
|
|
560
|
+
static parseDate(dateStr, format) {
|
|
561
|
+
try {
|
|
562
|
+
if (!dateStr || !format)
|
|
563
|
+
return null;
|
|
564
|
+
const parsedDate = (0, date_fns_1.parse)(dateStr, format, new Date());
|
|
565
|
+
return (0, date_fns_1.isValid)(parsedDate) ? parsedDate : null;
|
|
566
|
+
}
|
|
567
|
+
catch {
|
|
568
|
+
return null;
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
/**
|
|
572
|
+
* Converts a date string from one format to another.
|
|
573
|
+
*
|
|
574
|
+
* @param dateStr input date string
|
|
575
|
+
* @param inputFormat format of input string
|
|
576
|
+
* @param outputFormat desired output format
|
|
577
|
+
* @returns formatted date string or null if invalid
|
|
578
|
+
*
|
|
579
|
+
* Example:
|
|
580
|
+
* convertDateFormat("2026-01-07", "yyyy-MM-dd", "dd/MM/yyyy") → "07/01/2026"
|
|
581
|
+
*/
|
|
582
|
+
static convertDateFormat(dateStr, inputFormat, outputFormat) {
|
|
583
|
+
try {
|
|
584
|
+
if (!dateStr || !inputFormat || !outputFormat)
|
|
585
|
+
return null;
|
|
586
|
+
const parsedDate = this.parseDate(dateStr, inputFormat);
|
|
587
|
+
if (parsedDate == null)
|
|
588
|
+
return null;
|
|
589
|
+
return (0, date_fns_1.format)(parsedDate, outputFormat);
|
|
590
|
+
}
|
|
591
|
+
catch {
|
|
592
|
+
return null;
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
/**
|
|
596
|
+
* Removes the time portion from a Date and normalizes it to local midnight.
|
|
597
|
+
*
|
|
598
|
+
* @param date Date object
|
|
599
|
+
* @returns Date with time set to 00:00 or null if invalid
|
|
600
|
+
*
|
|
601
|
+
* Example:
|
|
602
|
+
* normalizeToDateOnly(new Date("2026-01-07T10:30:00")) -> 2024-01-14T18:30:00.000Z
|
|
603
|
+
*/
|
|
604
|
+
static normalizeToDateOnly(date) {
|
|
605
|
+
try {
|
|
606
|
+
if (!(0, date_fns_1.isValid)(date))
|
|
607
|
+
return null;
|
|
608
|
+
return new Date(date.getFullYear(), date.getMonth(), date.getDate());
|
|
609
|
+
}
|
|
610
|
+
catch {
|
|
611
|
+
return null;
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
/**
|
|
615
|
+
* Adjusts a date by adding or subtracting days, months, and/or years.
|
|
616
|
+
*
|
|
617
|
+
* Positive values add time, negative values subtract time.
|
|
618
|
+
*
|
|
619
|
+
* @param date Base date to adjust
|
|
620
|
+
* @param options Object containing days, months, and/or years
|
|
621
|
+
* @returns Adjusted Date or null if input date is invalid
|
|
622
|
+
*
|
|
623
|
+
* Example:
|
|
624
|
+
* adjustDate(new Date(), { days: 5 })
|
|
625
|
+
* adjustDate(new Date(), { months: -2 })
|
|
626
|
+
* adjustDate(new Date(), { years: 1, days: 10 })
|
|
627
|
+
*/
|
|
628
|
+
static adjustDate(date, options) {
|
|
629
|
+
try {
|
|
630
|
+
if (!(0, date_fns_1.isValid)(date))
|
|
631
|
+
return null;
|
|
632
|
+
let result = date;
|
|
633
|
+
if (options.years) {
|
|
634
|
+
result = (0, date_fns_1.addYears)(result, options.years);
|
|
635
|
+
}
|
|
636
|
+
if (options.months) {
|
|
637
|
+
result = (0, date_fns_1.addMonths)(result, options.months);
|
|
638
|
+
}
|
|
639
|
+
if (options.days) {
|
|
640
|
+
result = (0, date_fns_1.addDays)(result, options.days);
|
|
641
|
+
}
|
|
642
|
+
return result;
|
|
643
|
+
}
|
|
644
|
+
catch {
|
|
645
|
+
return null;
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
/**
|
|
649
|
+
* Adjusts the current date by adding or subtracting days, months, and/or years.
|
|
650
|
+
*
|
|
651
|
+
* Positive values add time, negative values subtract time.
|
|
652
|
+
*
|
|
653
|
+
* @param options Object containing days, months, and/or years
|
|
654
|
+
* @returns Adjusted Date or null if input date is invalid
|
|
655
|
+
*
|
|
656
|
+
* Example:
|
|
657
|
+
* adjustDate({ days: 5 })
|
|
658
|
+
* adjustDate({ months: -2 })
|
|
659
|
+
* adjustDate({ years: 1, days: 10 })
|
|
660
|
+
*/
|
|
661
|
+
static adjustFromCurrentDate(options) {
|
|
662
|
+
try {
|
|
663
|
+
const date = new Date();
|
|
664
|
+
if (!(0, date_fns_1.isValid)(date))
|
|
665
|
+
return null;
|
|
666
|
+
let result = date;
|
|
667
|
+
if (options.years) {
|
|
668
|
+
result = (0, date_fns_1.addYears)(result, options.years);
|
|
669
|
+
}
|
|
670
|
+
if (options.months) {
|
|
671
|
+
result = (0, date_fns_1.addMonths)(result, options.months);
|
|
672
|
+
}
|
|
673
|
+
if (options.days) {
|
|
674
|
+
result = (0, date_fns_1.addDays)(result, options.days);
|
|
675
|
+
}
|
|
676
|
+
return result;
|
|
677
|
+
}
|
|
678
|
+
catch {
|
|
679
|
+
return null;
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
/**
|
|
683
|
+
* Extracts day, month, and year from a Date object.
|
|
684
|
+
*
|
|
685
|
+
* @param date Date object
|
|
686
|
+
* @returns {{ day: number; month: number; year: number } | null}
|
|
687
|
+
* Object containing day (1–31), month (1–12), and year
|
|
688
|
+
*/
|
|
689
|
+
static getDayMonthYear(date) {
|
|
690
|
+
try {
|
|
691
|
+
if (!(date instanceof Date) || !(0, date_fns_1.isValid)(date))
|
|
692
|
+
return null;
|
|
693
|
+
return {
|
|
694
|
+
day: date.getDate(),
|
|
695
|
+
month: date.getMonth() + 1,
|
|
696
|
+
year: date.getFullYear()
|
|
697
|
+
};
|
|
698
|
+
}
|
|
699
|
+
catch {
|
|
700
|
+
return null;
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
/**
|
|
704
|
+
* Splits a string using a string or regex delimiter.
|
|
705
|
+
*
|
|
706
|
+
* @param value Input string to split
|
|
707
|
+
* @param delimiter String or RegExp used as delimiter
|
|
708
|
+
* @returns Array of split values (trimmed, non-empty)
|
|
709
|
+
*
|
|
710
|
+
* Examples:
|
|
711
|
+
* splitByDelimiter("A,B,C", ",") → ["A", "B", "C"]
|
|
712
|
+
* splitByDelimiter("A | B | C", "|") → ["A", "B", "C"]
|
|
713
|
+
* splitByDelimiter("A,B;C|D", /[,;|]/) → ["A", "B", "C", "D"]
|
|
714
|
+
*/
|
|
715
|
+
static splitByDelimiter(value, delimiter) {
|
|
716
|
+
try {
|
|
717
|
+
if (!value || !delimiter)
|
|
718
|
+
return [];
|
|
719
|
+
return value
|
|
720
|
+
.split(delimiter)
|
|
721
|
+
.map(item => item.trim())
|
|
722
|
+
.filter(item => item.length > 0);
|
|
723
|
+
}
|
|
724
|
+
catch {
|
|
725
|
+
return [];
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
/**
|
|
729
|
+
* Returns the first regex match found in a string.
|
|
730
|
+
*
|
|
731
|
+
* If the regex contains capturing groups, the full match is returned.
|
|
732
|
+
*
|
|
733
|
+
* @param value Input string
|
|
734
|
+
* @param pattern Regular expression
|
|
735
|
+
* @returns First matched string or null if no match
|
|
736
|
+
*
|
|
737
|
+
* Example:
|
|
738
|
+
* getFirstMatch("Amount: $250", /\d+/) → "250"
|
|
739
|
+
*/
|
|
740
|
+
static getFirstMatch(value, pattern) {
|
|
741
|
+
try {
|
|
742
|
+
if (!value || !pattern)
|
|
743
|
+
return null;
|
|
744
|
+
const match = value.match(pattern);
|
|
745
|
+
return match ? match[0] : null;
|
|
746
|
+
}
|
|
747
|
+
catch {
|
|
748
|
+
return null;
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
/**
|
|
752
|
+
* Returns all matches of a regex pattern found in a string.
|
|
753
|
+
*
|
|
754
|
+
* Note: For full functionality, the regex should have the global (g) flag.
|
|
755
|
+
*
|
|
756
|
+
* @param value Input string
|
|
757
|
+
* @param pattern Regular expression (preferably with /g)
|
|
758
|
+
* @returns Array of matched strings (empty array if no matches)
|
|
759
|
+
*
|
|
760
|
+
* Example:
|
|
761
|
+
* getAllMatches("IDs: 12, 45, 78", /\d+/g) → ["12", "45", "78"]
|
|
762
|
+
*/
|
|
763
|
+
static getAllMatches(value, pattern) {
|
|
764
|
+
try {
|
|
765
|
+
if (!value || !pattern)
|
|
766
|
+
return [];
|
|
767
|
+
const matches = value.match(pattern);
|
|
768
|
+
return matches ? matches : [];
|
|
769
|
+
}
|
|
770
|
+
catch {
|
|
771
|
+
return [];
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
/**
|
|
775
|
+
* This method is to get total technology fee
|
|
776
|
+
* @since 13-01-2026
|
|
777
|
+
* @param fixedFee number
|
|
778
|
+
* @param percentageFee number
|
|
779
|
+
* @param amount number
|
|
780
|
+
* @returns number | null
|
|
781
|
+
*/
|
|
782
|
+
static getTotalFees(fixedFee, percentageFee, amount) {
|
|
783
|
+
try {
|
|
784
|
+
if (isNaN(fixedFee) ||
|
|
785
|
+
isNaN(percentageFee) ||
|
|
786
|
+
isNaN(amount)) {
|
|
787
|
+
throw new Error('Invalid number input');
|
|
788
|
+
}
|
|
789
|
+
const totalTechFees = (amount / 100) * percentageFee + fixedFee;
|
|
790
|
+
return totalTechFees;
|
|
791
|
+
}
|
|
792
|
+
catch {
|
|
793
|
+
return null;
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
/**
|
|
797
|
+
* This method is get total amount as per passed fixed & percentage fee and amount
|
|
798
|
+
* @since 13-01-2026
|
|
799
|
+
* @param fixedFee number
|
|
800
|
+
* @param percentageFee number
|
|
801
|
+
* @param amount number
|
|
802
|
+
* @returns number | null
|
|
803
|
+
*/
|
|
804
|
+
static getTotalAmount(fixedFee, percentageFee, amount) {
|
|
805
|
+
try {
|
|
806
|
+
const techFee = this.getTotalFees(fixedFee, percentageFee, amount);
|
|
807
|
+
if (techFee === null) {
|
|
808
|
+
throw new Error('Fee calculation failed');
|
|
809
|
+
}
|
|
810
|
+
return techFee + amount;
|
|
811
|
+
}
|
|
812
|
+
catch {
|
|
813
|
+
return null;
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
/**
|
|
817
|
+
* Returns the difference between two dates in years.
|
|
818
|
+
*
|
|
819
|
+
* @param date1 Start date
|
|
820
|
+
* @param date2 End date
|
|
821
|
+
* @returns Difference in days or null if invalid
|
|
822
|
+
*/
|
|
823
|
+
static getDifferenceInDays(date1, date2) {
|
|
824
|
+
try {
|
|
825
|
+
if (!(0, date_fns_1.isValid)(date1) || !(0, date_fns_1.isValid)(date2))
|
|
826
|
+
return null;
|
|
827
|
+
return (0, date_fns_1.differenceInDays)(date2, date1);
|
|
828
|
+
}
|
|
829
|
+
catch {
|
|
830
|
+
return null;
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
/**
|
|
834
|
+
* Returns the difference between two dates in years.
|
|
835
|
+
*
|
|
836
|
+
* @param date1 Start date
|
|
837
|
+
* @param date2 End date
|
|
838
|
+
* @returns Difference in months or null if invalid
|
|
839
|
+
*/
|
|
840
|
+
static getDifferenceInMonths(date1, date2) {
|
|
841
|
+
try {
|
|
842
|
+
if (!(0, date_fns_1.isValid)(date1) || !(0, date_fns_1.isValid)(date2))
|
|
843
|
+
return null;
|
|
844
|
+
return (0, date_fns_1.differenceInMonths)(date2, date1);
|
|
845
|
+
}
|
|
846
|
+
catch {
|
|
847
|
+
return null;
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
/**
|
|
851
|
+
* Returns the difference between two dates in years.
|
|
852
|
+
*
|
|
853
|
+
* @param date1 Start date
|
|
854
|
+
* @param date2 End date
|
|
855
|
+
* @returns Difference in years or null if invalid
|
|
856
|
+
*/
|
|
857
|
+
static getDifferenceInYears(date1, date2) {
|
|
858
|
+
try {
|
|
859
|
+
if (!(0, date_fns_1.isValid)(date1) || !(0, date_fns_1.isValid)(date2))
|
|
860
|
+
return null;
|
|
861
|
+
return (0, date_fns_1.differenceInYears)(date2, date1);
|
|
862
|
+
}
|
|
863
|
+
catch {
|
|
864
|
+
return null;
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
exports.GenerationUtils = GenerationUtils;
|
|
869
|
+
//# sourceMappingURL=generationUtils.js.map
|