-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstring.ts
More file actions
400 lines (365 loc) · 8.32 KB
/
string.ts
File metadata and controls
400 lines (365 loc) · 8.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
export function toTitleCase(str: string): string {
return str
.toLowerCase() // Convert entire string to lowercase first
.split(' ') // Split the string into an array of words
.map((word) => word.charAt(0).toUpperCase() + word.slice(1)) // Capitalize first letter of each word
.join(' '); // Join the array of words back into a single string
}
export const toCamelCase = (str: string): string => {
if (!str) return str;
return str
.replace(/(?:^\w|[A-Z]|\b\w)/g, (word, index) => (index === 0 ? word.toLowerCase() : word.toUpperCase()))
.replace(/[\s:,()&/\-\+]+/g, '');
};
export const toPlural = (singular: string, plural: string, count: number, showCount = true, zero = ''): string => {
if (count === 0 && zero) return zero;
const output = count === 1 ? singular : plural || `${singular}s`;
return showCount ? `${count} ${output}` : output;
};
export const toPascalCase = (str) => {
return str.replace(/(^\w|_\w)/g, (match) => match.replace('_', '').toUpperCase());
};
export const camelize = toCamelCase;
export const pascalize = toPascalCase;
export const pluralize = toPlural;
export const getFirstName = (str: string): string => str.split(' ')[0];
export const getNameInitials = (str: string): string => {
const words = str.split(' ');
return words.length > 1
? `${words[0][0].toUpperCase()}${words[words.length - 1][0].toUpperCase()}`
: words[0][0].toUpperCase();
};
export function removeComments(str) {
// Regular expression for removing single-line and multi-line comments
const regex = /\/\/.*|\/\*[^]*?\*\//g;
return str.replace(regex, '');
}
export function cleanJSON(str) {
return removeComments(
str
.replace('```json\n', '')
.replace('\n```', '')
.replace(/\/\/.*|\/\*[^]*?\*\//g, '')
);
}
// List of 100+ unique fantasy and anime names
const allNames: string[] = [
'Aragorn',
'Legolas',
'Gimli',
'Frodo',
'Gandalf',
'Boromir',
'Samwise',
'Merry',
'Pippin',
'Elrond',
'Galadriel',
'Saruman',
'Sauron',
'Bilbo',
'Thorin',
'Eowyn',
'Faramir',
'Denethor',
'Treebeard',
'Gollum',
'Gon Freecss',
'Killua Zoldyck',
'Kurapika',
'Leorio Paradinight',
'Hisoka Morow',
'Chrollo Lucilfer',
'Illumi Zoldyck',
'Mito Freecss',
'Meruem',
'Isaac Netero',
'Zushi',
'Komugi',
'Feitan Portor',
'Shizuku Murasaki',
'Shalnark',
'Wing',
'Biscuit Krueger',
'Palm Siberia',
'Neferpitou',
'Naruto Uzumaki',
'Sasuke Uchiha',
'Sakura Haruno',
'Kakashi Hatake',
'Itachi Uchiha',
'Hinata Hyuga',
'Shikamaru Nara',
'Gaara',
'Rock Lee',
'Tsunade',
'Jiraiya',
'Minato Namikaze',
'Tobirama Senju',
'Obito Uchiha',
'Kiba Inuzuka',
'Temari',
'Kankuro',
'Deidara',
'Sasori',
'Kisame Hoshigaki',
'Tenten',
'Monkey D. Luffy',
'Roronoa Zoro',
'Nami',
'Usopp',
'Sanji',
'Tony Tony Chopper',
'Nico Robin',
'Franky',
'Brook',
'Jinbe',
'Portgas D. Ace',
'Sabo',
'Shanks',
'Blackbeard',
'Boa Hancock',
'Trafalgar D. Water Law',
'Eustass Kid',
'Charlotte Katakuri',
'Donquixote Doflamingo',
'Dracule Mihawk',
'Goku',
'Vegeta',
'Gohan',
'Piccolo',
'Trunks',
'Goten',
'Bulma',
'Frieza',
'Cell',
'Majin Buu',
'Krillin',
'Android 18',
'Tien Shinhan',
'Yamcha',
'Chi-Chi',
'Videl',
'Beerus',
'Whis',
'Zamasu',
'Hit',
'Jiren',
'Eren Yeager',
'Mikasa Ackerman',
'Armin Arlert',
'Levi Ackerman',
'Erwin Smith',
'Historia Reiss',
'Hange Zoë',
'Reiner Braun',
'Annie Leonhart',
'Jean Kirstein',
'Connie Springer',
'Sasha Blouse',
'Zeke Yeager',
'Gabi Braun',
'Falco Grice',
'Ymir',
'Bertolt Hoover',
'Marco Bott',
'Grisha Yeager',
'Natsu Dragneel',
'Lucy Heartfilia',
'Gray Fullbuster',
'Erza Scarlet',
'Wendy Marvell',
'Gajeel Redfox',
'Happy',
'Mirajane Strauss',
'Laxus Dreyar',
'Juvia Lockser',
'Elfman Strauss',
'Cana Alberona',
'Gildarts Clive',
'Makarov Dreyar',
'Loki',
'Ultear Milkovich',
'Rufus Lore',
'Sting Eucliffe',
'Freed Justine',
'Boss Makarov',
'Edward Elric',
'Alphonse Elric',
'Roy Mustang',
'Riza Hawkeye',
'Winry Rockbell',
'Scar',
'Maes Hughes',
'Alex Louis Armstrong',
'Lust',
'Envy',
'Gluttony',
'Sloth',
'Greed',
'Father',
'Izumi Curtis',
'Van Hohenheim',
'Shou Tucker',
'Ling Yao',
'Lan Fan',
'Sig Curtis',
'Vanilla Ice',
'Izuku Midoriya',
'Katsuki Bakugo',
'Ochaco Uraraka',
'Shoto Todoroki',
'Tenya Iida',
'All Might',
'Shota Aizawa',
'Momo Yaoyorozu',
'Tsuyu Asui',
'Fumikage Tokoyami',
'Denki Kaminari',
'Kirishima Eijiro',
'Mina Ashido',
'Nejire Hado',
'Hanta Sero',
'Eijiro Kirishima',
'Todoroki Fuyumi',
'Froppy (Tsuyu Asui)',
'Minoru Mineta',
'Mirio Togata',
'Kirito',
'Asuna Yuuki',
'Klein',
'Leafa',
'Sinon',
'Yui',
'Agil',
'Silica',
'Eugeo',
'Alice Zuberg',
'Lisbeth',
'Suguha Kirigaya',
'Licht (Death Gun)',
'Elder Ayana',
'Diabel',
'Yuri Nara',
'Shino Asada',
'Tanjiro Kamado',
'Nezuko Kamado',
'Zenitsu Agatsuma',
'Inosuke Hashibira',
'Kanao Tsuyuri',
'Rengoku Kyojuro',
'Tengen Uzui',
'Muzan Kibutsuji',
'Giyu Tomioka',
'Shinobu Kocho',
'Obanai Iguro',
'Sanemi Shinazugawa',
'Muichiro Tokito',
'Gyomei Himejima',
'Kyojuro Rengoku',
'Tomioka Giyu',
'Asta',
'Yuno',
'Noelle Silva',
'Julius Novachrono',
'Luck Voltia',
'Tank Gandalf',
'Vash the Stampede',
'Spike Spiegel',
'Alucard',
'Simon',
'Kamina',
'Yoko Littner',
'Lelouch Lamperouge',
'C.C.',
'Kallen Kozuki',
'Saber (Artoria Pendragon)',
'Shirou Emiya',
'Rin Tohsaka',
'Kiritsugu Emiya',
'Saitama',
'Genos',
'Tatsumaki',
'Bang',
'Fubuki',
'King',
'Orochimaru',
'Madara Uchiha',
'Hashirama Senju',
'Kushina Uzumaki',
'Shikamaru Nara',
'Might Guy',
'Neji Hyuga',
'Choji Akimichi',
'Ino Yamanaka',
'Shino Aburame',
];
// Remove any duplicates to ensure uniqueness
const uniqueNames: string[] = Array.from(new Set(allNames));
// Fisher-Yates Shuffle Algorithm to randomize the array
function shuffle(array: string[]): void {
for (let i = array.length - 1; i > 0; i--) {
const j: number = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
}
// Initialize remainingNames with a shuffled copy of uniqueNames
let remainingNames: string[] = [...uniqueNames];
shuffle(remainingNames);
export function randomName(): string {
return remainingNames.pop()!;
}
// helper.ts
export interface ParsedCookie {
name: string;
value: string;
domain: string;
path: string;
secure: boolean;
httpOnly?: boolean;
sameSite?: 'Strict' | 'Lax' | 'None';
}
/**
* Parses a document.cookie string into an array of unique cookie objects compatible with Puppeteer.
* Filters out non-essential and problematic cookies to prevent conflicts.
* @param cookieString - The raw cookie string from document.cookie
* @param url - The URL for which the cookies are valid (e.g., 'https://my.wealthsimple.com')
* @returns Array of parsed and unique cookies
*/
export function parseAndFilterCookies(cookieString: string, domain: string): ParsedCookie[] {
// Define non-essential and problematic cookies to exclude
const excludeCookies = new Set([
// '_ga',
// '_gcl_au',
// '_tt_enable_cookie',
// '_ttp',
// '_rdt_uuid',
// '_ScCbts',
// '_sctr',
// 'ajs_user_id',
// 'ajs_anonymous_id',
// '_dd_s',
// '_oauth2_access_v2', // Exclude this problematic cookie for now
// Add any other non-essential or problematic cookie names here
]);
// Split the cookie string into individual cookies
const cookieArray = cookieString.split('; ').map((cookie) => {
const [name, ...rest] = cookie.split('=');
const value = rest.join('=');
return { name: decodeURIComponent(name), value: value }; // Do not decode value
});
// Filter out non-essential and problematic cookies
const essentialCookies = cookieArray.filter((cookie) => !excludeCookies.has(cookie.name));
// Eliminate duplicates by name, keeping last occurrence
const uniqueCookiesMap: Map<string, ParsedCookie> = new Map();
essentialCookies.forEach((cookie) => {
uniqueCookiesMap.set(cookie.name, {
name: cookie.name,
value: cookie.value,
domain: domain,
path: '/',
secure: true, // As per your tip
});
});
return Array.from(uniqueCookiesMap.values());
}