(url: string)
| 17 | const localRegex = /^local:\/\/([^/]+)\/(anime|manga)\/([^/]+)(\/|$)/; |
| 18 | |
| 19 | export function urlToSlug(url: string): slugObject { |
| 20 | const obj: slugObject = { |
| 21 | url, |
| 22 | }; |
| 23 | |
| 24 | const malMatch = url.match(malRegex); |
| 25 | if (malMatch) { |
| 26 | obj.path = { |
| 27 | type: malMatch[1] as 'anime' | 'manga', |
| 28 | slug: malMatch[2], |
| 29 | }; |
| 30 | return obj; |
| 31 | } |
| 32 | |
| 33 | const anilistMatch = url.match(anilistRegex); |
| 34 | if (anilistMatch) { |
| 35 | obj.path = { |
| 36 | type: anilistMatch[1] as 'anime' | 'manga', |
| 37 | slug: `a:${anilistMatch[2]}`, |
| 38 | }; |
| 39 | return obj; |
| 40 | } |
| 41 | |
| 42 | const kitsuMatch = url.match(kitsuRegex); |
| 43 | if (kitsuMatch) { |
| 44 | obj.path = { |
| 45 | type: kitsuMatch[1] as 'anime' | 'manga', |
| 46 | slug: `k:${kitsuMatch[2]}`, |
| 47 | }; |
| 48 | return obj; |
| 49 | } |
| 50 | |
| 51 | const simklMatch = url.match(simklRegex); |
| 52 | if (simklMatch) { |
| 53 | obj.path = { |
| 54 | type: simklMatch[1] as 'anime' | 'manga', |
| 55 | slug: `s:${simklMatch[2]}`, |
| 56 | }; |
| 57 | return obj; |
| 58 | } |
| 59 | |
| 60 | const shikiMatch = url.match(shikiRegex); |
| 61 | if (shikiMatch) { |
| 62 | obj.path = { |
| 63 | type: shikiMatch[1].toLowerCase() === 'animes' ? 'anime' : 'manga', |
| 64 | slug: `shi:${shikiMatch[2]}`, |
| 65 | }; |
| 66 | return obj; |
| 67 | } |
| 68 | |
| 69 | const mangabakaMatch = url.match(mangabakaRegex); |
| 70 | if (mangabakaMatch) { |
| 71 | obj.path = { |
| 72 | type: 'manga', |
| 73 | slug: `baka:${mangabakaMatch[1]}`, |
| 74 | }; |
| 75 | return obj; |
| 76 | } |
no outgoing calls
no test coverage detected