react-native-consumet 0.4.3 → 0.6.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 (119) hide show
  1. package/android/build.gradle +1 -0
  2. package/android/generated/java/com/consumet/NativeConsumetSpec.java +8 -0
  3. package/android/generated/jni/RNConsumetSpec-generated.cpp +12 -0
  4. package/android/generated/jni/react/renderer/components/RNConsumetSpec/RNConsumetSpecJSI-generated.cpp +14 -0
  5. package/android/generated/jni/react/renderer/components/RNConsumetSpec/RNConsumetSpecJSI.h +18 -0
  6. package/android/src/main/java/com/consumet/ConsumetModule.kt +63 -38
  7. package/android/src/main/java/com/consumet/DdosGuardModule.kt +142 -0
  8. package/ios/generated/RNConsumetSpec/RNConsumetSpec-generated.mm +14 -0
  9. package/ios/generated/RNConsumetSpec/RNConsumetSpec.h +6 -0
  10. package/ios/generated/RNConsumetSpecJSI-generated.cpp +14 -0
  11. package/ios/generated/RNConsumetSpecJSI.h +18 -0
  12. package/lib/commonjs/NativeConsumet.ts +2 -0
  13. package/lib/commonjs/index.js +10 -4
  14. package/lib/commonjs/index.js.map +1 -1
  15. package/lib/commonjs/models/index.js.map +1 -1
  16. package/lib/commonjs/models/proxy.js +80 -25
  17. package/lib/commonjs/models/proxy.js.map +1 -1
  18. package/lib/commonjs/models/types.js.map +1 -1
  19. package/lib/commonjs/providers/anime/animekai.js +19 -14
  20. package/lib/commonjs/providers/anime/animekai.js.map +1 -1
  21. package/lib/commonjs/providers/anime/animepahe.js +59 -9
  22. package/lib/commonjs/providers/anime/animepahe.js.map +1 -1
  23. package/lib/commonjs/providers/anime/zoro.js +26 -19
  24. package/lib/commonjs/providers/anime/zoro.js.map +1 -1
  25. package/lib/commonjs/providers/meta/anilist.js +38 -208
  26. package/lib/commonjs/providers/meta/anilist.js.map +1 -1
  27. package/lib/commonjs/providers/meta/mal.js +4 -4
  28. package/lib/commonjs/providers/meta/mal.js.map +1 -1
  29. package/lib/commonjs/providers/meta/tmdb.js +6 -15
  30. package/lib/commonjs/providers/meta/tmdb.js.map +1 -1
  31. package/lib/commonjs/providers/movies/multimovies.js +33 -13
  32. package/lib/commonjs/providers/movies/multimovies.js.map +1 -1
  33. package/lib/commonjs/utils/index.js +4 -4
  34. package/lib/commonjs/utils/utils.js +140 -4
  35. package/lib/commonjs/utils/utils.js.map +1 -1
  36. package/lib/module/NativeConsumet.ts +2 -0
  37. package/lib/module/index.js +6 -3
  38. package/lib/module/index.js.map +1 -1
  39. package/lib/module/models/index.js.map +1 -1
  40. package/lib/module/models/proxy.js +80 -25
  41. package/lib/module/models/proxy.js.map +1 -1
  42. package/lib/module/models/types.js.map +1 -1
  43. package/lib/module/providers/anime/animekai.js +18 -14
  44. package/lib/module/providers/anime/animekai.js.map +1 -1
  45. package/lib/module/providers/anime/animepahe.js +60 -10
  46. package/lib/module/providers/anime/animepahe.js.map +1 -1
  47. package/lib/module/providers/anime/zoro.js +25 -19
  48. package/lib/module/providers/anime/zoro.js.map +1 -1
  49. package/lib/module/providers/meta/anilist.js +39 -209
  50. package/lib/module/providers/meta/anilist.js.map +1 -1
  51. package/lib/module/providers/meta/mal.js +5 -5
  52. package/lib/module/providers/meta/mal.js.map +1 -1
  53. package/lib/module/providers/meta/tmdb.js +7 -16
  54. package/lib/module/providers/meta/tmdb.js.map +1 -1
  55. package/lib/module/providers/movies/multimovies.js +33 -13
  56. package/lib/module/providers/movies/multimovies.js.map +1 -1
  57. package/lib/module/utils/index.js +2 -2
  58. package/lib/module/utils/index.js.map +1 -1
  59. package/lib/module/utils/utils.js +126 -1
  60. package/lib/module/utils/utils.js.map +1 -1
  61. package/lib/typescript/commonjs/src/NativeConsumet.d.ts +4 -0
  62. package/lib/typescript/commonjs/src/NativeConsumet.d.ts.map +1 -1
  63. package/lib/typescript/commonjs/src/index.d.ts +6 -3
  64. package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
  65. package/lib/typescript/commonjs/src/models/index.d.ts +2 -2
  66. package/lib/typescript/commonjs/src/models/index.d.ts.map +1 -1
  67. package/lib/typescript/commonjs/src/models/proxy.d.ts +6 -7
  68. package/lib/typescript/commonjs/src/models/proxy.d.ts.map +1 -1
  69. package/lib/typescript/commonjs/src/models/types.d.ts +4 -1
  70. package/lib/typescript/commonjs/src/models/types.d.ts.map +1 -1
  71. package/lib/typescript/commonjs/src/providers/anime/animekai.d.ts.map +1 -1
  72. package/lib/typescript/commonjs/src/providers/anime/animepahe.d.ts +7 -3
  73. package/lib/typescript/commonjs/src/providers/anime/animepahe.d.ts.map +1 -1
  74. package/lib/typescript/commonjs/src/providers/anime/zoro.d.ts.map +1 -1
  75. package/lib/typescript/commonjs/src/providers/meta/anilist.d.ts +0 -3
  76. package/lib/typescript/commonjs/src/providers/meta/anilist.d.ts.map +1 -1
  77. package/lib/typescript/commonjs/src/providers/meta/tmdb.d.ts.map +1 -1
  78. package/lib/typescript/commonjs/src/providers/movies/multimovies.d.ts.map +1 -1
  79. package/lib/typescript/commonjs/src/utils/index.d.ts +2 -2
  80. package/lib/typescript/commonjs/src/utils/index.d.ts.map +1 -1
  81. package/lib/typescript/commonjs/src/utils/utils.d.ts +15 -1
  82. package/lib/typescript/commonjs/src/utils/utils.d.ts.map +1 -1
  83. package/lib/typescript/module/src/NativeConsumet.d.ts +4 -0
  84. package/lib/typescript/module/src/NativeConsumet.d.ts.map +1 -1
  85. package/lib/typescript/module/src/index.d.ts +6 -3
  86. package/lib/typescript/module/src/index.d.ts.map +1 -1
  87. package/lib/typescript/module/src/models/index.d.ts +2 -2
  88. package/lib/typescript/module/src/models/index.d.ts.map +1 -1
  89. package/lib/typescript/module/src/models/proxy.d.ts +6 -7
  90. package/lib/typescript/module/src/models/proxy.d.ts.map +1 -1
  91. package/lib/typescript/module/src/models/types.d.ts +4 -1
  92. package/lib/typescript/module/src/models/types.d.ts.map +1 -1
  93. package/lib/typescript/module/src/providers/anime/animekai.d.ts.map +1 -1
  94. package/lib/typescript/module/src/providers/anime/animepahe.d.ts +7 -3
  95. package/lib/typescript/module/src/providers/anime/animepahe.d.ts.map +1 -1
  96. package/lib/typescript/module/src/providers/anime/zoro.d.ts.map +1 -1
  97. package/lib/typescript/module/src/providers/meta/anilist.d.ts +0 -3
  98. package/lib/typescript/module/src/providers/meta/anilist.d.ts.map +1 -1
  99. package/lib/typescript/module/src/providers/meta/tmdb.d.ts.map +1 -1
  100. package/lib/typescript/module/src/providers/movies/multimovies.d.ts.map +1 -1
  101. package/lib/typescript/module/src/utils/index.d.ts +2 -2
  102. package/lib/typescript/module/src/utils/index.d.ts.map +1 -1
  103. package/lib/typescript/module/src/utils/utils.d.ts +15 -1
  104. package/lib/typescript/module/src/utils/utils.d.ts.map +1 -1
  105. package/package.json +5 -2
  106. package/src/NativeConsumet.ts +2 -0
  107. package/src/index.tsx +5 -3
  108. package/src/models/index.ts +2 -0
  109. package/src/models/proxy.ts +80 -30
  110. package/src/models/types.ts +6 -1
  111. package/src/providers/anime/animekai.ts +17 -14
  112. package/src/providers/anime/animepahe.ts +70 -10
  113. package/src/providers/anime/zoro.ts +25 -20
  114. package/src/providers/meta/anilist.ts +71 -325
  115. package/src/providers/meta/mal.ts +5 -5
  116. package/src/providers/meta/tmdb.ts +7 -16
  117. package/src/providers/movies/multimovies.ts +28 -19
  118. package/src/utils/index.ts +2 -2
  119. package/src/utils/utils.ts +162 -1
@@ -12,7 +12,7 @@ import {
12
12
  type IMovieEpisode,
13
13
  } from '../../models';
14
14
  import type { IPeopleResult } from '../../models/types';
15
- import { compareTwoStrings } from '../../utils';
15
+ import { calculateStringSimilarity } from '../../utils';
16
16
  import FlixHQ from '../movies/flixhq';
17
17
  import type { AxiosAdapter } from 'axios';
18
18
 
@@ -198,20 +198,10 @@ class TMDB extends MovieParser {
198
198
  if (type === 'movie') info.episodeId = InfoFromProvider?.episodes![0]?.id;
199
199
 
200
200
  info.title = data?.title || data?.name;
201
- info.translations = data?.translations?.translations.map((translation: any) => ({
202
- title: translation.data?.title || data?.name || undefined,
203
- description: translation.data?.overview || undefined,
204
- language: translation?.english_name || undefined,
205
- }));
206
201
 
207
202
  //images
208
203
  info.image = `https://image.tmdb.org/t/p/original${data?.poster_path}`;
209
204
  info.cover = `https://image.tmdb.org/t/p/original${data?.backdrop_path}`;
210
- info.logos = data?.images?.logos.map((logo: { file_path: string; aspect_ratio: number; width: number }) => ({
211
- url: `https://image.tmdb.org/t/p/original${logo.file_path}`,
212
- aspectRatio: logo?.aspect_ratio,
213
- width: logo?.width,
214
- }));
215
205
 
216
206
  info.type = type === 'movie' ? TvType.MOVIE : TvType.TVSERIES;
217
207
  info.rating = data?.vote_average || 0;
@@ -317,7 +307,7 @@ class TMDB extends MovieParser {
317
307
  releaseDate: episode.air_date,
318
308
  description: episode.overview,
319
309
  url: episodeFromProvider?.url || undefined,
320
- img: !episode?.still_path
310
+ image: !episode?.still_path
321
311
  ? undefined
322
312
  : {
323
313
  mobile: `https://image.tmdb.org/t/p/w300${episode.still_path}`,
@@ -350,14 +340,15 @@ class TMDB extends MovieParser {
350
340
  },
351
341
  episodes: [
352
342
  {
353
- id: `${mediaId}-${type}-s1-e1`,
343
+ id: InfoFromProvider?.episodes![0]?.id!,
354
344
  uniqueId: `${mediaId}-${type}-s1-e1`,
355
345
  title: data.title || data.original_title,
356
346
  episode: 1,
357
347
  season: 1,
358
348
  releaseDate: data.release_date,
359
349
  description: data.overview,
360
- img: !data?.backdrop_path
350
+ url: InfoFromProvider?.episodes![0]?.url,
351
+ image: !data?.backdrop_path
361
352
  ? undefined
362
353
  : {
363
354
  mobile: `https://image.tmdb.org/t/p/w300${data.backdrop_path}`,
@@ -413,8 +404,8 @@ class TMDB extends MovieParser {
413
404
  if (typeof b.title === 'string') secondTitle = b.title as string;
414
405
  else secondTitle = (b?.title as string) ?? '';
415
406
 
416
- const firstRating = compareTwoStrings(targetTitle, firstTitle.toLowerCase());
417
- const secondRating = compareTwoStrings(targetTitle, secondTitle.toLowerCase());
407
+ const firstRating = calculateStringSimilarity(targetTitle, firstTitle.toLowerCase());
408
+ const secondRating = calculateStringSimilarity(targetTitle, secondTitle.toLowerCase());
418
409
 
419
410
  // Sort in descending order
420
411
  return secondRating - firstRating;
@@ -13,9 +13,9 @@ import { MixDrop, StreamTape, StreamWish, VidHide } from '../../extractors';
13
13
 
14
14
  class MultiMovies extends MovieParser {
15
15
  override readonly name = 'MultiMovies';
16
- protected override baseUrl = 'https://multimovies.guru';
16
+ protected override baseUrl = 'https://multimovies.digital';
17
17
  protected override logo =
18
- 'https://multimovies.guru/wp-content/uploads/2024/01/cropped-CompressJPEG.online_512x512_image.png';
18
+ 'https://multimovies.digital/wp-content/uploads/2024/01/cropped-CompressJPEG.online_512x512_image.png';
19
19
  protected override classPath = 'MOVIES.MultiMovies';
20
20
  override supportedTypes = new Set([TvType.MOVIE, TvType.TVSERIES]);
21
21
  constructor(customBaseURL?: string) {
@@ -258,7 +258,6 @@ class MultiMovies extends MovieParser {
258
258
  if (i === -1) {
259
259
  throw new Error(`Server ${server} not found`);
260
260
  }
261
-
262
261
  const serverUrl: URL = new URL(servers[i]!.url);
263
262
  let fileId = '';
264
263
 
@@ -383,13 +382,15 @@ class MultiMovies extends MovieParser {
383
382
  const headers = {
384
383
  'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
385
384
  };
386
-
387
- const playerRes = await this.client.post(`${this.baseUrl}/wp-admin/admin-ajax.php`, formData, {
388
- headers,
385
+ // console.log(`${this.baseUrl}/wp-admin/admin-ajax.php`, formData);
386
+ const response = await fetch(`${this.baseUrl}/wp-admin/admin-ajax.php`, {
387
+ method: 'POST',
388
+ headers: headers,
389
+ body: formData,
389
390
  });
390
-
391
- const iframeUrl =
392
- playerRes.data?.embed_url?.match(/<iframe[^>]+src="([^"]+)"[^>]*>/i)?.[1] || playerRes.data?.embed_url;
391
+ const playerRes = await response.json();
392
+ // console.log('playerRes', playerRes);
393
+ const iframeUrl = playerRes?.embed_url?.match(/<iframe[^>]+src="([^"]+)"[^>]*>/i)?.[1] || playerRes?.embed_url;
393
394
 
394
395
  // Handle non-multimovies case
395
396
  if (!iframeUrl.includes('multimovies')) {
@@ -397,12 +398,9 @@ class MultiMovies extends MovieParser {
397
398
  const redirectResponse = await this.client.head(playerBaseUrl, {
398
399
  headers,
399
400
  });
400
-
401
401
  // Update base URL if redirect occurred
402
402
  if (redirectResponse) {
403
- playerBaseUrl =
404
- redirectResponse.request._redirectable._options.href.split('/').slice(0, 3).join('/') ||
405
- redirectResponse.request.res.responseURL.split('/').slice(0, 3).join('/');
403
+ playerBaseUrl = redirectResponse.request?.responseURL?.split('/').slice(0, 3).join('/');
406
404
  }
407
405
  const fileId = iframeUrl.split('/').pop();
408
406
 
@@ -412,17 +410,28 @@ class MultiMovies extends MovieParser {
412
410
 
413
411
  const streamRequestData = new FormData();
414
412
  streamRequestData.append('sid', fileId);
413
+ // console.log('redirectResponse', playerBaseUrl, streamRequestData);
414
+ let streamResponse;
415
+ try {
416
+ streamResponse = await this.client.post(`${playerBaseUrl}/embedhelper.php`, streamRequestData, {
417
+ headers,
418
+ });
419
+ } catch (_) {
420
+ // If the embedhelper.php endpoint fails, just return the direct embed URL
421
+ return {
422
+ servers: [{ name: 'streamwish', url: `${playerBaseUrl}/embed/${fileId}` }],
423
+ fileId: iframeUrl.split('/').pop() ?? '',
424
+ };
425
+ }
415
426
 
416
- const streamResponse = await this.client.post(`${playerBaseUrl}/embedhelper.php`, streamRequestData, {
417
- headers,
418
- });
427
+ // console.log('streamResponse', streamResponse.data);
419
428
 
420
429
  if (!streamResponse.data) {
421
430
  throw new Error('No stream data found');
422
431
  }
423
432
 
424
433
  const streamDetails = streamResponse.data;
425
- const mresultKeys = new Set(Object.keys(streamDetails.mresult));
434
+ const mresultKeys = new Set(Object.keys(JSON.parse(atob(streamDetails.mresult))));
426
435
  const siteUrlsKeys = new Set(Object.keys(streamDetails.siteUrls));
427
436
 
428
437
  // Find common keys
@@ -436,19 +445,19 @@ class MultiMovies extends MovieParser {
436
445
  streamDetails.siteFriendlyNames[site] === 'StreamHG'
437
446
  ? 'StreamWish'
438
447
  : streamDetails.siteFriendlyNames[site],
439
- url: streamDetails.siteUrls[site] + streamDetails.mresult[site],
448
+ url: streamDetails.siteUrls[site] + JSON.parse(atob(streamDetails.mresult))[site],
440
449
  };
441
450
  });
442
451
 
443
452
  return { servers, fileId };
444
453
  } else {
445
- //@Durgesh
446
454
  return {
447
455
  servers: [{ name: 'StreamWish', url: iframeUrl }],
448
456
  fileId: iframeUrl.split('/').pop() ?? '',
449
457
  };
450
458
  }
451
459
  } catch (err) {
460
+ console.log(err);
452
461
  throw new Error((err as Error).message);
453
462
  }
454
463
  }
@@ -30,7 +30,7 @@ import {
30
30
  convertDuration,
31
31
  substringAfter,
32
32
  substringBefore,
33
- compareTwoStrings,
33
+ calculateStringSimilarity,
34
34
  } from './utils';
35
35
  import {
36
36
  anilistSearchQuery,
@@ -88,7 +88,7 @@ export {
88
88
  AsianLoad,
89
89
  substringAfter,
90
90
  substringBefore,
91
- compareTwoStrings,
91
+ calculateStringSimilarity,
92
92
  VidMoly,
93
93
  getKKey,
94
94
  MegaUp,
@@ -1,3 +1,4 @@
1
+ import { compareTwoStrings } from 'string-similarity';
1
2
  // import sharp from 'sharp';
2
3
  import { load } from 'cheerio';
3
4
  // import * as blurhash from 'blurhash';
@@ -104,7 +105,7 @@ export function convertDuration(milliseconds: number) {
104
105
  return `PT${hours}H${minutes}M${seconds}S`;
105
106
  }
106
107
 
107
- export const compareTwoStrings = (first: string, second: string): number => {
108
+ export const calculateStringSimilarity = (first: string, second: string): number => {
108
109
  first = first.replace(/\s+/g, '');
109
110
  second = second.replace(/\s+/g, '');
110
111
 
@@ -176,3 +177,163 @@ export const getHashFromImage = (url: string) => {
176
177
  return 'hash';
177
178
  }
178
179
  };
180
+
181
+ // Function to find similar titles
182
+ export function findSimilarTitles(inputTitle: string, titles: any[]): any[] {
183
+ const results: (any & { similarity: number })[] = [];
184
+
185
+ titles?.forEach((titleObj: any) => {
186
+ const title = cleanTitle(
187
+ titleObj?.title
188
+ ?.toLowerCase()
189
+ ?.replace(/\([^\)]*\)/g, '')
190
+ .trim() || ''
191
+ );
192
+
193
+ // Calculate similarity score between inputTitle and title
194
+ const similarity = compareTwoStrings(cleanTitle(inputTitle?.toLowerCase() || ''), title);
195
+
196
+ if (similarity > 0.6) {
197
+ results.push({ ...titleObj, similarity });
198
+ }
199
+ });
200
+
201
+ const isSubAvailable = results.some((result) => result.episodes && result.episodes.sub > 0);
202
+
203
+ // If episodes.sub is available, sort the results
204
+ if (isSubAvailable) {
205
+ return results.sort((a, b) => {
206
+ // First sort by similarity in descending order
207
+ if (b.similarity !== a.similarity) {
208
+ return b.similarity - a.similarity;
209
+ }
210
+ // If similarity is the same, sort by episodes.sub in descending order
211
+ return (b.episodes?.sub || 0) - (a.episodes?.sub || 0);
212
+ });
213
+ }
214
+
215
+ // If episodes.sub is not available, return the original list
216
+ return results.sort((a, b) => b.similarity - a.similarity);
217
+ }
218
+
219
+ // Function to convert Roman numerals to Arabic numbers
220
+ function romanToArabic(roman: string): number {
221
+ const romanMap: Record<string, number> = {
222
+ i: 1,
223
+ v: 5,
224
+ x: 10,
225
+ l: 50,
226
+ c: 100,
227
+ d: 500,
228
+ m: 1000,
229
+ };
230
+
231
+ roman = roman.toLowerCase();
232
+ let result = 0;
233
+
234
+ for (let i = 0; i < roman.length; i++) {
235
+ const current = romanMap[roman[i]!]!;
236
+ const next = romanMap[roman[i + 1]!];
237
+
238
+ if (next && current < next) {
239
+ result += next - current;
240
+ i++;
241
+ } else {
242
+ result += current;
243
+ }
244
+ }
245
+
246
+ return result;
247
+ }
248
+
249
+ export function cleanTitle(title: string | undefined | null): string {
250
+ if (!title) return '';
251
+
252
+ return transformSpecificVariations(
253
+ removeSpecialChars(
254
+ title
255
+ .replaceAll(/[^A-Za-z0-9!@#$%^&*() ]/gim, ' ')
256
+ .replaceAll(/(th|rd|nd|st) (Season|season)/gim, '')
257
+ .replaceAll(/\([^\(]*\)$/gim, '')
258
+ .replaceAll('season', '')
259
+ .replaceAll(/\b(IX|IV|V?I{0,3})\b/gi, (match) => romanToArabic(match).toString())
260
+ .replaceAll(' ', ' ')
261
+ .replaceAll('"', '')
262
+ .trimEnd()
263
+ )
264
+ );
265
+ }
266
+
267
+ export function removeSpecialChars(title: string | undefined | null): string {
268
+ if (!title) return '';
269
+
270
+ return title
271
+ .replaceAll(/[^A-Za-z0-9!@#$%^&*()\-= ]/gim, ' ')
272
+ .replaceAll(/[^A-Za-z0-9\-= ]/gim, '')
273
+ .replaceAll(' ', ' ');
274
+ }
275
+
276
+ export function transformSpecificVariations(title: string | undefined | null): string {
277
+ if (!title) return '';
278
+
279
+ return title.replaceAll('yuu', 'yu').replaceAll(' ou', ' oh');
280
+ }
281
+
282
+ export function sanitizeTitle(title: string): string {
283
+ let resTitle = title.replace(/ *(\(dub\)|\(sub\)|\(uncensored\)|\(uncut\)|\(subbed\)|\(dubbed\))/i, '');
284
+ resTitle = resTitle.replace(/ *\([^)]+audio\)/i, '');
285
+ resTitle = resTitle.replace(/ BD( |$)/i, '');
286
+ resTitle = resTitle.replace(/\(TV\)/g, '');
287
+ resTitle = resTitle.trim();
288
+ resTitle = resTitle.substring(0, 99); // truncate
289
+ return resTitle;
290
+ }
291
+
292
+ export function stringSearch(string: string, pattern: string): number {
293
+ let count = 0;
294
+ string = string.toLowerCase();
295
+ pattern = pattern.toLowerCase();
296
+ string = string.replace(/[^a-zA-Z0-9 -]/g, '');
297
+ pattern = pattern.replace(/[^a-zA-Z0-9 -]/g, '');
298
+
299
+ for (let i = 0; i < string.length; i++) {
300
+ for (let j = 0; j < pattern.length; j++) {
301
+ if (pattern[j] !== string[i + j]) break;
302
+ if (j === pattern.length - 1) count++;
303
+ }
304
+ }
305
+ return count;
306
+ }
307
+
308
+ export function parseUrl(url: string): {
309
+ href: string;
310
+ origin: string;
311
+ pathname: string;
312
+ hostname: string;
313
+ search: string;
314
+ hash: string;
315
+ } {
316
+ // Simple URL parser for React Native
317
+ try {
318
+ const match = url.match(/^(https?:\/\/[^\/]+)(\/[^?#]*)?(\?[^#]*)?(#.*)?$/);
319
+ if (!match) throw new Error(`Invalid URL: ${url}`);
320
+
321
+ const origin = match[1] || '';
322
+ const pathname = match[2] || '/';
323
+ const search = match[3] || '';
324
+ const hash = match[4] || '';
325
+
326
+ return {
327
+ href: url,
328
+ origin,
329
+ pathname,
330
+ hostname: origin.replace(/^https?:\/\//, ''),
331
+ search,
332
+ hash,
333
+ };
334
+ } catch (e) {
335
+ console.error(`Error parsing URL: ${url}`, e);
336
+ // Return a minimal object with href to prevent crashes
337
+ return { href: url, origin: '', pathname: '', hostname: '', search: '', hash: '' };
338
+ }
339
+ }