当前位置: 首页>>代码示例>>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;未经允许,请勿转载。