• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript url.standardize函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中spica/url.standardize函数的典型用法代码示例。如果您正苦于以下问题:TypeScript standardize函数的具体用法?TypeScript standardize怎么用?TypeScript standardize使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了standardize函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: evaluate

 function evaluate(): AtomicPromise<Either<Error, HTMLScriptElement>> {
   if (script.matches('[type="module"][src]')) {
     return AtomicPromise.resolve(import(script.src))
       .catch((reason: Error) =>
         reason.message.startsWith('Failed to load ') && script.matches('[src][async]')
           ? retry(script).catch(() => AtomicPromise.reject(reason))
           : AtomicPromise.reject(reason))
       .then(
         () => (
           void script.dispatchEvent(new Event('load')),
           Right(script)),
         reason => (
           void script.dispatchEvent(new Event('error')),
           Left(new FatalError(reason instanceof Error ? reason.message : reason + ''))));
   }
   else {
     try {
       if (new URL(standardize(window.location.href)).path !== new URL(standardize(window.location.href)).path) throw new FatalError('Expired.');
       if (skip.has(new URL(standardize(window.location.href)).reference)) throw new FatalError('Expired.');
       void (0, eval)(code);
       script.hasAttribute('src') && void script.dispatchEvent(new Event('load'));
       return AtomicPromise.resolve(Right(script));
     }
     catch (reason) {
       script.hasAttribute('src') && void script.dispatchEvent(new Event('error'));
       return AtomicPromise.resolve(Left(new FatalError(reason instanceof Error ? reason.message : reason + '')));
     }
   }
 }
开发者ID:falsandtru,项目名称:pjax-api,代码行数:29,代码来源:script.ts


示例2: it

 it('extend', () => {
   assert.deepStrictEqual(
     JSON.stringify(scope(new Config({ scope: { '/': { fetch: { wait: 100 } } } }), {
       orig: new URL(standardize('/')).pathname,
       dest: new URL(standardize('/')).pathname
     }).extract()),
     JSON.stringify(new Config({ fetch: { wait: 100 }, scope: { '/': { fetch: { wait: 100 } } } })));
 });
开发者ID:falsandtru,项目名称:pjax-api,代码行数:8,代码来源:scope.test.ts


示例3: retry

function retry(script: HTMLScriptElement): AtomicPromise<undefined> {
  if (new URL(standardize(script.src)).origin === new URL(standardize(window.location.href)).origin) return AtomicPromise.reject(new Error());
  script = html('script', Object.values(script.attributes).reduce((o, { name, value }) => (o[name] = value, o), {}), [...script.childNodes]);
  return new AtomicPromise((resolve, reject) => (
    void script.addEventListener('load', () => void resolve()),
    void script.addEventListener('error', reject),
    void document.body.appendChild(script),
    void script.remove()));
}
开发者ID:falsandtru,项目名称:pjax-api,代码行数:9,代码来源:script.ts


示例4: URL

 .fmap(xhr => {
   const responseURL: URL<StandardURL> = new URL(standardize(xhr.responseURL));
   assert(responseURL.origin === new URL(window.location.origin).origin);
   if (method === 'GET') {
     const cc = new Map<string, string>(
       xhr.getResponseHeader('Cache-Control')
         ? xhr.getResponseHeader('Cache-Control')!.trim().split(/\s*,\s*/)
             .filter(v => v.length > 0)
             .map(v => v.split('=').concat('') as [string, string])
         : []);
     for (const path of new Set([requestURL.path, responseURL.path])) {
       if (xhr.getResponseHeader('ETag') && !cc.has('no-store')) {
         void caches.set(path, {
           etag: xhr.getResponseHeader('ETag')!,
           expiry: cc.has('max-age') && !cc.has('no-cache')
             ? Date.now() + +cc.get('max-age')! * 1000 || 0
             : 0,
           xhr,
         });
       }
       else {
         void caches.delete(path);
       }
     }
   }
   return (overriddenDisplayURL: URL<StandardURL>, overriddenRequestURL: URL<StandardURL>) =>
     new FetchResponse(
       responseURL.path === overriddenRequestURL.path
         ? overriddenDisplayURL
         : overriddenRequestURL.path === requestURL.path || !key
             ? responseURL
             : overriddenDisplayURL,
       xhr);
 })
开发者ID:falsandtru,项目名称:pjax-api,代码行数:34,代码来源:xhr.ts


示例5: it

 it('submit post', () => {
   const req = new RouterEventRequest(html('form', { method: 'POST', action: './send' }, [
     html('input', { name: 'test', type: 'text', value: 'abc' })
   ]));
   assert(req.url.reference === standardize('./send'));
   assert(req.method === RouterEventMethod.POST);
   assert(req.body instanceof FormData);
 });
开发者ID:falsandtru,项目名称:pjax-api,代码行数:8,代码来源:router.test.ts


示例6: return

 return (url: string) => {
   const { path, pathname } = new URL(standardize(url));
   return Sequence.from(Object.keys(config).filter(([c]) => c === '/').sort().reverse())
     .filter(flip(compare)(pathname))
     .map(pattern => config[pattern])
     .take(1)
     .extract()
     .pop()!
     .call(config, path);
 };
开发者ID:falsandtru,项目名称:pjax-api,代码行数:10,代码来源:router.ts


示例7: it

 it('dir', () => {
   assert(!compare('/abc', new URL(standardize('/')).pathname));
   assert(compare('/abc', new URL(standardize('/abc')).pathname));
   assert(compare('/abc', new URL(standardize('/abc/')).pathname));
   assert(!compare('/abc/', new URL(standardize('/abc')).pathname));
   assert(compare('/abc/', new URL(standardize('/abc/')).pathname));
   assert(!compare('/abc', new URL(standardize('/ab')).pathname));
   assert(!compare('/ab', new URL(standardize('/abc')).pathname));
 });
开发者ID:falsandtru,项目名称:pjax-api,代码行数:9,代码来源:router.test.ts



注:本文中的spica/url.standardize函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript spinner.LoadSpinner类代码示例发布时间:2022-05-25
下一篇:
TypeScript tuple.tuple函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap