(url: string)
| 6 | }; |
| 7 | |
| 8 | export default function getBundleDataFromURL(url: string): BundleData { |
| 9 | let name: string; |
| 10 | let type: string; |
| 11 | let platform: string | undefined; |
| 12 | let path: string | undefined; |
| 13 | let file: string; |
| 14 | |
| 15 | if (url.startsWith('http')) { |
| 16 | const [, baseUrl, filename] = /^(https?:\/\/.+\/)(.+)$/.exec(url) || [ |
| 17 | '', |
| 18 | undefined, |
| 19 | undefined, |
| 20 | ]; |
| 21 | if (!baseUrl || !filename) { |
| 22 | throw new Error(`${url} is not a valid bundle URL`); |
| 23 | } |
| 24 | |
| 25 | path = baseUrl; |
| 26 | platform = (filename.match(/platform=([a-zA-Z]*)/) || ['', undefined])[1]; |
| 27 | file = (filename.match(/^([^?]+)/) || ['', ''])[1]; |
| 28 | } else { |
| 29 | const [, filePath, filename] = /(.*\/)?([^/]+)$/.exec(url) || [ |
| 30 | '', |
| 31 | '', |
| 32 | undefined, |
| 33 | ]; |
| 34 | if (!filename) { |
| 35 | throw new Error(`${url} is not a valid bundle URL`); |
| 36 | } |
| 37 | |
| 38 | file = filename; |
| 39 | path = filePath; |
| 40 | } |
| 41 | |
| 42 | const segments = file.split('.'); |
| 43 | if (segments.length > 2) { |
| 44 | name = segments.slice(0, segments.length - 2).join('.'); |
| 45 | platform = segments[segments.length - 2]; |
| 46 | type = segments[segments.length - 1]; |
| 47 | } else { |
| 48 | [name, type] = segments; |
| 49 | } |
| 50 | |
| 51 | return { |
| 52 | name, |
| 53 | type, |
| 54 | platform, |
| 55 | path: path || '', |
| 56 | }; |
| 57 | } |
no outgoing calls
no test coverage detected