-
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #449 from live-codes/import-from-playgrounds
Import from playgrounds
- Loading branch information
Showing
27 changed files
with
289 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
export const getValidUrl = /* @__PURE__ */ (url: string) => { | ||
try { | ||
return url.startsWith('https://') ? new URL(url) : new URL('https://' + url); | ||
} catch (error) { | ||
return; | ||
} | ||
}; | ||
|
||
export const hostPatterns = { | ||
github: /^(?:(?:http|https):\/\/)?github\.com\/(?:.*)/g, | ||
githubGist: /^(?:(?:http|https):\/\/)?gist\.github\.com(?:\/\S*)?\/(\w+)/g, | ||
gitlab: /^(?:(?:http|https):\/\/)?gitlab\.com\/(?:.*)/g, | ||
codepen: /^(?:(?:http|https):\/\/)?codepen\.io\/(\w+)\/pen\/(\w+)/g, | ||
jsbin: /^(?:(?:(?:http|https):\/\/)?(?:\w+.)?)?jsbin\.com\/((\w)+(\/\d+)?)(?:.*)/g, | ||
typescriptPlayground: /^(?:(?:http|https):\/\/)?(?:www\.)?typescriptlang\.org\/play(?:.*)/g, | ||
vuePlayground: /^(?:(?:http|https):\/\/)?play\.vuejs\.org(?:.*)/g, | ||
sveltePlayground: /^(?:(?:http|https):\/\/)?svelte\.dev\/repl\/(?:.*)/g, | ||
}; | ||
|
||
export const isCompressedCode = (url: string) => url.startsWith('code/'); | ||
|
||
export const isCodepen = (url: string, pattern = new RegExp(hostPatterns.codepen)) => | ||
pattern.test(url); | ||
|
||
export const isDom = (url: string) => url.startsWith('dom/'); | ||
|
||
export const isGithubUrl = (url: string, pattern = new RegExp(hostPatterns.github)) => { | ||
if (!pattern.test(url)) return; | ||
try { | ||
const urlObj = getValidUrl(url); | ||
if (!urlObj) return; | ||
const pathSplit = urlObj.pathname.split('/'); | ||
return pathSplit[3] === 'blob'; | ||
} catch (error) { | ||
return; | ||
} | ||
}; | ||
|
||
export const isGithub = (url: string) => isGithubDir(url) || isGithubUrl(url); | ||
|
||
export const isGithubDir = (url: string, pattern = new RegExp(hostPatterns.github)) => { | ||
if (!pattern.test(url)) return; | ||
try { | ||
const urlObj = getValidUrl(url); | ||
if (!urlObj) return; | ||
const pathSplit = urlObj.pathname.split('/'); | ||
return pathSplit[3] === 'tree' || pathSplit.length === 3; | ||
} catch (error) { | ||
return; | ||
} | ||
}; | ||
|
||
export const isGithubGist = (url: string, pattern = new RegExp(hostPatterns.githubGist)) => | ||
pattern.test(url); | ||
|
||
export const isGitlabUrl = (url: string, pattern = new RegExp(hostPatterns.gitlab)) => { | ||
if (!pattern.test(url)) return; | ||
try { | ||
const urlObj = getValidUrl(url); | ||
if (!urlObj) return; | ||
const pathSplit = urlObj.pathname.split('/'); | ||
return pathSplit[4] === 'blob'; | ||
} catch (error) { | ||
return; | ||
} | ||
}; | ||
|
||
export const isGitlabDir = (url: string, pattern = new RegExp(hostPatterns.gitlab)) => { | ||
if (!pattern.test(url)) return; | ||
try { | ||
const urlObj = getValidUrl(url); | ||
if (!urlObj) return; | ||
const pathSplit = urlObj.pathname.split('/'); | ||
return pathSplit[4] === 'tree' || pathSplit.length === 3; | ||
} catch (error) { | ||
return; | ||
} | ||
}; | ||
|
||
export const isGitlabSnippet = (url: string, pattern = new RegExp(hostPatterns.gitlab)) => { | ||
if (!pattern.test(url)) return; | ||
const urlObj = getValidUrl(url); | ||
if (!urlObj) return; | ||
const pathSplit = urlObj.pathname.split('/'); | ||
return pathSplit[pathSplit.length - 2] === 'snippets'; | ||
}; | ||
|
||
export const isJsbin = (url: string, pattern = new RegExp(hostPatterns.jsbin)) => pattern.test(url); | ||
|
||
export const isProjectId = (url: string) => url.startsWith('id/'); | ||
|
||
export const isTypescriptPlayground = ( | ||
url: string, | ||
pattern = new RegExp(hostPatterns.typescriptPlayground), | ||
) => pattern.test(url); | ||
|
||
export const isVuePlayground = (url: string, pattern = new RegExp(hostPatterns.vuePlayground)) => | ||
pattern.test(url); | ||
|
||
export const isSveltePlayground = ( | ||
url: string, | ||
pattern = new RegExp(hostPatterns.sveltePlayground), | ||
) => pattern.test(url); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export { importFromCodepen } from './codepen'; | ||
export { importFromDom } from './dom'; | ||
export { importFromGithub } from './github'; | ||
export { importFromGithubDir } from './github-dir'; | ||
export { importFromGithubGist } from './github-gist'; | ||
export { importFromGitlab } from './gitlab'; | ||
export { importFromGitlabDir } from './gitlab-dir'; | ||
export { importFromGitlabSnippet } from './gitlab-snippet'; | ||
export { importFromJsbin } from './jsbin'; | ||
export { importSveltePlayground } from './svelte-playground'; | ||
export { importTypescriptPlayground } from './typescript-playground'; | ||
export { importVuePlayground } from './vue-playground'; | ||
export { importFromUrl } from './url'; |
Oops, something went wrong.