⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,14 @@ export async function downloadToBlob(options: Omit<DownloadOptions, 'outputPath'
*
* const projectId = parseUrl('https://stackblitz.com/edit/nuxt-starter-k7spa3r4')
* // => 'nuxt-starter-k7spa3r4'
*
* // Also works with tilde URLs
* const projectId2 = parseUrl('https://stackblitz.com/~/edit/nuxt-starter-k7spa3r4')
* // => 'nuxt-starter-k7spa3r4'
* ```
*/
export function parseUrl(url: string): string {
const match = url.match(/stackblitz\.com\/edit\/([^/?#]+)/)
const match = url.match(/stackblitz\.com\/(?:~\/)?edit\/([^/?#]+)/)

if (!match || !match[1]) {
throw new Error(`Invalid StackBlitz URL: ${url}`)
Expand Down
5 changes: 5 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ describe('parseUrl', () => {
expect(projectId).toBe('nuxt-starter-k7spa3r4')
})

it('handles URLs with tilde', () => {
const projectId = parseUrl('https://stackblitz.com/~/edit/nuxt-starter-k7spa3r4')
expect(projectId).toBe('nuxt-starter-k7spa3r4')
})

it('throws error for invalid URL format', () => {
expect(() => parseUrl('https://example.com/invalid')).toThrow('Invalid StackBlitz URL')
})
Expand Down