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

TypeScript then-request.default函数代码示例

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

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript thenify.withCallback函数代码示例发布时间:2022-05-25
下一篇:
TypeScript then-mongo.Collection类代码示例发布时间: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