當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript url-parse類代碼示例

本文整理匯總了TypeScript中url-parse的典型用法代碼示例。如果您正苦於以下問題:TypeScript url-parse類的具體用法?TypeScript url-parse怎麽用?TypeScript url-parse使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了url-parse類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: parse

 function parse(url: string): IUrl {
   if (typeof document !== 'undefined') {
     let a = document.createElement('a');
     a.href = url;
     return a;
   }
   return urlparse(url);
 }
開發者ID:cameronoelsen,項目名稱:jupyterlab,代碼行數:8,代碼來源:url.ts

示例2: getQueryParam

export const getParamFromUrl = (
  url: string,
  paramName: string,
  defaultValue: string = ''
): string => {
  const parsedUrl = parseUrl(url) as any;
  return getQueryParam(parsedUrl.query, paramName, defaultValue);
};
開發者ID:linode,項目名稱:manager,代碼行數:8,代碼來源:queryParams.ts

示例3: default

export default (url: string): string => {
  const u = URL(url);
  const updatedHash = u.hash
    .split('#')
    .map(chunk =>
      chunk
        .split('&')
        .map(query => {
          const access_token = query.includes('access_token');
          return access_token ? `access_token=REDACTED` : query;
        })
        .join('&')
    )
    .join('#');

  return u.set('hash', updatedHash).toString();
};
開發者ID:displague,項目名稱:manager,代碼行數:17,代碼來源:redactAccessTokenFromUrl.ts

示例4: bakeGrapherUrls

export async function bakeGrapherUrls(urls: string[], opts: { silent?: boolean } = {}) {
    const currentExports = await getGrapherExportsByUrl()
    const slugToId = await mapSlugsToIds()
    const toBake = []

    // Check that we need to bake this url, and don't already have an export
    for (const url of urls) {
        const current = currentExports.get(url)
        if (!current) {
            toBake.push(url)
            continue
        }

        const slug = _.last(parseUrl(url).pathname.split('/'))
        if (!slug) {
            console.error(`Invalid chart url ${url}`)
            continue
        }

        const chartId = slugToId[slug]  
        const rows = await grapherDb.query(`SELECT charts.config->>"$.version" AS version FROM charts WHERE charts.id=?`, [chartId])
        if (!rows.length) {
            console.error(`Mysteriously missing chart by id ${chartId}`)
            continue
        }

        if (rows[0].version > current.version) {
            toBake.push(url)
        }
    }

    if (toBake.length > 0) {
        const args = [`${GRAPHER_DIR}/dist/src/bakeChartsToImages.js`]
        args.push(...toBake)
        args.push(`${BAKED_DIR}/exports`)
        const promise = exec(`cd ${GRAPHER_DIR} && node ${args.map(arg => JSON.stringify(arg)).join(" ")}`)
        if (!opts.silent)
            promise.childProcess.stdout.on('data', (data: any) => console.log(data.toString().trim()))
        await promise    
    }

}
開發者ID:OurWorldInData,項目名稱:owid-theme,代碼行數:42,代碼來源:grapherUtil.ts

示例5: bakeChartsToImages

export async function bakeGrapherUrls(urls: string[]) {
    const currentExports = await getGrapherExportsByUrl()
    const slugToId = await mapSlugsToIds()
    const toBake = []

    // Check that we need to bake this url, and don't already have an export
    for (const url of urls) {
        const current = currentExports.get(url)
        if (!current) {
            toBake.push(url)
            continue
        }

        const slug = _.last(parseUrl(url).pathname.split('/'))
        if (!slug) {
            log.warn(`Invalid chart url ${url}`)
            continue
        }

        const chartId = slugToId[slug]
        if (chartId === undefined) {
            log.warn(`Couldn't find chart with slug ${slug}`)
            continue
        }

        const rows = await db.query(`SELECT charts.config->>"$.version" AS version FROM charts WHERE charts.id=?`, [chartId])
        if (!rows.length) {
            log.warn(`Mysteriously missing chart by id ${chartId}`)
            continue
        }

        if (rows[0].version > current.version) {
            toBake.push(url)
        }
    }

    if (toBake.length > 0) {
        await bakeChartsToImages(toBake, `${BAKED_SITE_DIR}/exports`)
    }
}
開發者ID:OurWorldInData,項目名稱:owid-grapher,代碼行數:40,代碼來源:grapherUtil.ts

示例6: parseQueryParams

export const getParamsFromUrl = (url: string) => {
  const parsedUrl = parseUrl(url) as any;
  return parseQueryParams(parsedUrl.query);
};
開發者ID:linode,項目名稱:manager,代碼行數:4,代碼來源:queryParams.ts

示例7: isPrerendering

export function isPrerendering() {
  return parseUrl(window.location.href, true).query['prerendering'] === true.toString();
}
開發者ID:kevinphelps,項目名稱:kevinphelps.me,代碼行數:3,代碼來源:app.module.ts

示例8: grapherUrlToFilekey

export function grapherUrlToFilekey(grapherUrl: string) {
    const url = parseUrl(grapherUrl)
    const slug = _.last(url.pathname.split('/')) as string
    const queryStr = url.query as any
    return `${slug}${queryStr ? "-"+md5(queryStr) : ""}`
}
開發者ID:OurWorldInData,項目名稱:owid-grapher,代碼行數:6,代碼來源:grapherUtil.ts

示例9: parseUrl

 const linkedUrls = allLinksOnPage.filter(link => parseUrl(link).hostname === 'localhost').map(link => link.replace(host, ''));
開發者ID:kevinphelps,項目名稱:kevinphelps.me,代碼行數:1,代碼來源:prerender.ts

示例10: urlToSlug

export function urlToSlug(url: string): string {
    const urlobj = parseUrl(url)
    const slug = last(urlobj.pathname.split('/').filter(x => x)) as string
    return slug
}
開發者ID:OurWorldInData,項目名稱:owid-grapher,代碼行數:5,代碼來源:Util.ts


注:本文中的url-parse類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。