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


TypeScript then-request.default函數代碼示例

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


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

示例1: readMessage

export default function readMessage(url: string): Promise<Message> {
  return request('GET', url, {
    retry: true,
    retryDelay: (err, res, attemptNo) => 500 * Math.pow(2, attemptNo),
  })
    .getBody('utf8')
    .then(function(body) {
      try {
        const dom = html(body);

        const header = {
          subject: dom
            .select(['html', 'body', 'h1'])
            .first()
            .textContent()
            .trim(),
          from: {
            name: dom
              .select(['html', 'body', 'b'])
              .first()
              .textContent()
              .trim(),
            email: dom
              .select(['html', 'body', 'a'])
              .first()
              .textContent()
              .trim()
              .replace(' at ', '@'),
          },
          reply:
            dom
              .select(['html', 'body', 'a'])
              .first()
              .attr('href') || '',
          date: new Date(
            dom
              .select(['html', 'body', 'i'])
              .first()
              .textContent()
              .trim(),
          ),
        };

        return {
          url: url,
          header: header,
          body: dom
            .select(['html', 'body', 'p', 'pre'])
            .first()
            .textContent()
            .trim(),
        };
      } catch (ex) {
        ex.message += '\n\n\n' + body;
        throw ex;
      }
    });
}
開發者ID:esdiscuss,項目名稱:pipermail,代碼行數:58,代碼來源:read-message.ts

示例2: readMonth

export default function readMonth(url: string): Promise<string[]> {
  url = url.replace(/\/$/, '').replace(/\/date\.html$/, '');
  return request('GET', url + '/date.html', {
    retry: true,
    retryDelay: (err, res, attemptNo) => 500 * Math.pow(2, attemptNo),
  })
    .getBody('utf8')
    .then(body => {
      const urls = new Set<string>();
      const pattern = /href=\"(\d+\.html)\"/gi;
      let match;
      while ((match = pattern.exec(body))) {
        urls.add(url + '/' + match[1]);
      }
      return Array.from(urls);
    });
}
開發者ID:esdiscuss,項目名稱:pipermail,代碼行數:17,代碼來源:read-month.ts

示例3: readIndex

export default function readIndex(
  url: string,
  options: Options = {},
): Promise<string[]> {
  url = url.replace(/\/$/, '');
  return request('GET', url, {
    retry: true,
    retryDelay: (err, res, attemptNo) => 500 * Math.pow(2, attemptNo),
  })
    .getBody('utf8')
    .then(body => {
      const pattern =
        options.archiveUrlRegex || /\d\d\d\d\-[a-z]+\.txt(?:\.gz)?/gi;
      let match;
      const urls = [];
      while ((match = pattern.exec(body))) {
        urls.push(url + '/' + match[0].replace(/\.txt(?:\.gz)?/, ''));
      }
      return urls.reverse();
    });
}
開發者ID:esdiscuss,項目名稱:pipermail,代碼行數:21,代碼來源:read-index.ts

示例4: request

 return (req: Req): Promise<Res> => {
   // Note how even though we return a promise, the resulting rpc client will be synchronous
   const {form, ...o} = req.o || {form: undefined};
   const opts: Options = o;
   if (form) {
     const fd = new FormData();
     form.forEach(entry => {
       fd.append(entry.key, entry.value, entry.fileName);
     });
     opts.form = fd;
   }
   return request(req.m, req.u, opts).then(response => ({
     s: response.statusCode,
     h: response.headers,
     b: response.body,
     u: response.url,
   }));
 };
開發者ID:ForbesLindesay,項目名稱:sync-request,代碼行數:18,代碼來源:worker.ts

示例5: poll

function poll() {
  request('GET', url).done(res => {
    if (res.statusCode === 503 && Date.now() < timeout) {
      if (Date.now() > slow) {
        console.log('status: ' + res.statusCode);
        console.log((res.body as any).toString('utf8'));
        slow = Date.now() + 1 * 60 * 1000;
      }
      return poll();
    }
    if (res.statusCode !== 200) {
      console.log('status: ' + res.statusCode);
      console.log((res.body as any).toString('utf8'));
      process.exit(1);
    } else if (server) {
      process.exit(0);
    }
  });
}
開發者ID:esdiscuss,項目名稱:bot,代碼行數:19,代碼來源:test.ts


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