format import URL from 'url' ; import { GitRepoTemplate } from '../entiry' ; export function parse ( url ) { return URL . parse ( url ) ; } export function getProjectNameFromUrl ( url ) { const slash = url . lastIndexOf ( '/' ) ; if ( slash && slash >= 0 ) { url = url . substr ( slash + 1 ) ; } if ( url . endsWith ( '.git' ) ) { return url . substr ( 0 , url . length - 4 ) ; } return url ; } export function isUrlFormat ( url ) { return url . includes ( ':' ) || url . includes ( '/' ) ; } export function extractTemplateInfo ( url ) { let pathname = url . pathname || '' ; const pathArr = pathname . split ( '/' ) ; const ownerName = pathArr [ 1 ] ; const repoName = pathArr [ 3 ] ; return { host : url . host , ownerName , repoName , branch : '' , hasSubPath : false , subPath : '' , zipFile : '' , } ; } export default { extractTemplateInfo , getProjectNameFromUrl , isUrlFormat , parse , } ;