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

TypeScript popsicle.request函数代码示例

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

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



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

示例1: analyze

function analyze(indexes: number[], reals: number[]): Promise<{ spam: boolean; confidence: number; }> {
	return popsicle
		.request(createGetUrl("/words/vector", "ids", indexes))
		.use(popsicle.plugins.parse("json"))
		.then(response => {
			let result: Vector = null;

			reals.forEach(index => {
				let vector = new Vector(response.body.words[index].vector);

				if (result === null) {
					result = vector;
				} else {
					result.add(vector);
				}
			});

			return popsicle
				.request(createGetUrl("/spam/detect", "vector", result.toArray()))
				.use(popsicle.plugins.parse("json"))
				.then(response2 => {
					return response2.body;
				});
		});
}
开发者ID:codealphago,项目名称:word2vec-spam-filter,代码行数:25,代码来源:index.ts


示例2: makeRequest

export async function makeRequest (url: string): Promise<Response> {
  const req = request({
    url,
    headers: {
      'User-Agent': 'Scrappy-LinkExpanding 1.0 (+https://github.com/blakeembrey/node-scrappy)'
    },
    use: [],
    transport: createTransport({ type: 'stream', jar: jar() })
  })

  return req.then((res) => {
    // Abort wrapper to ignore streaming errors from aborting (e.g. unzipping).
    function abort () {
      res.body.on('error', () => undefined)
      req.abort()
    }

    return {
      stream: res.body,
      headers: res.headers,
      status: res.status,
      abort: abort,
      url: res.url
    }
  })
}
开发者ID:blakeembrey,项目名称:node-scrappy,代码行数:26,代码来源:support.ts


示例3: createGetUrl

	report: message => {
		return popsicle.request({
			url: createGetUrl("/spam/report"),
			method: "POST",
			body: {
				message
			}
		});
	},
开发者ID:codealphago,项目名称:word2vec-spam-filter,代码行数:9,代码来源:index.ts


示例4: scrapeUrl

export function scrapeUrl (url: string): Promise<Result> {
  const req = request({
    url,
    method: 'get',
    use: [
      plugins.unzip(),
      plugins.headers()
    ],
    options: {
      // Some websites require the use of cookies for their log-in page, so
      // you don't get stuck in an infinite loop (looking at you, NYTimes.com).
      jar: jar()
    }
  })

  return req.then(response => {
    return scrapeStream(url, response.headers, response.body, () => req.abort())
  })
}
开发者ID:abdulhannanali,项目名称:node-scrappy,代码行数:19,代码来源:scrape.ts


示例5: Vector

		.then(response => {
			let result: Vector = null;

			reals.forEach(index => {
				let vector = new Vector(response.body.words[index].vector);

				if (result === null) {
					result = vector;
				} else {
					result.add(vector);
				}
			});

			return popsicle
				.request(createGetUrl("/spam/detect", "vector", result.toArray()))
				.use(popsicle.plugins.parse("json"))
				.then(response2 => {
					return response2.body;
				});
		});
开发者ID:codealphago,项目名称:word2vec-spam-filter,代码行数:20,代码来源:index.ts


示例6: require

import * as view from "./page";

const popsicle = require("popsicle");
const shuffle = require("shuffle-array");
const baseUrl = "http://localhost:5000";

const dictionary = {} as { [word: string]: number };
let dictionarySize;
popsicle.request(createGetUrl("/words/list")).then(res => {
	res.body.split("\n").forEach((word, index) => dictionary[word] = index);
	dictionarySize = Object.keys(dictionary).length;
	console.log(`words loaded (count of ${ dictionarySize })`);
});

const main = document.getElementById("main");
view.render(main, {
	report: message => {
		return popsicle.request({
			url: createGetUrl("/spam/report"),
			method: "POST",
			body: {
				message
			}
		});
	},
	check: message => {
		// go to lower case
		message = message.toLowerCase();

		// split message into words
		const words = normalize(message).split(/\s+/);
开发者ID:codealphago,项目名称:word2vec-spam-filter,代码行数:31,代码来源:index.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript portfinder.getPort函数代码示例发布时间:2022-05-25
下一篇:
TypeScript popper.js.default类代码示例发布时间: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