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


TypeScript url.standardize函數代碼示例

本文整理匯總了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;未經允許,請勿轉載。