本文整理汇总了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;
}
});
}
示例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);
});
}
示例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();
});
}
示例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,
}));
};
示例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);
}
});
}