本文整理汇总了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);
}
示例2: getQueryParam
export const getParamFromUrl = (
url: string,
paramName: string,
defaultValue: string = ''
): string => {
const parsedUrl = parseUrl(url) as any;
return getQueryParam(parsedUrl.query, paramName, defaultValue);
};
示例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();
};
示例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
}
}
示例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`)
}
}
示例6: parseQueryParams
export const getParamsFromUrl = (url: string) => {
const parsedUrl = parseUrl(url) as any;
return parseQueryParams(parsedUrl.query);
};
示例7: isPrerendering
export function isPrerendering() {
return parseUrl(window.location.href, true).query['prerendering'] === true.toString();
}
示例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) : ""}`
}
示例9: parseUrl
const linkedUrls = allLinksOnPage.filter(link => parseUrl(link).hostname === 'localhost').map(link => link.replace(host, ''));
示例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
}