本文整理汇总了TypeScript中@toba/tools.is.value方法的典型用法代码示例。如果您正苦于以下问题:TypeScript is.value方法的具体用法?TypeScript is.value怎么用?TypeScript is.value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@toba/tools.is
的用法示例。
在下文中一共展示了is.value方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: internalError
/**
* Render status `500` page.
*/
function internalError(res: Response, err?: Error): void {
if (is.value(err)) {
log.error(err);
}
res.statusCode = HttpStatus.InternalError;
res.render(Page.InternalError, { title: 'Oops', config });
}
示例2:
].forEach(async p => {
if (is.value(p) && !p.isAuthenticated) {
const url = await p.authorizationURL();
res.redirect(url);
return;
}
});
示例3: source
/**
* Retrieve, parse and display a map source.
*/
async function source(req: Request, res: Response) {
const key: string = req.params[RouteParam.MapSource];
if (!is.text(key)) {
return view.notFound(req, res);
}
const geo = await loadSource(key.replace('.json', ''));
if (!is.value<MapSource>(geo)) {
return view.notFound(req, res);
}
const geoText = JSON.stringify(geo);
try {
compress.gzip(Buffer.from(geoText), (err: Error, buffer: Buffer) => {
if (is.value(err)) {
view.internalError(res, err);
} else {
res.setHeader(Header.Content.Encoding, Encoding.GZip);
res.setHeader(Header.CacheControl, 'max-age=86400, public'); // seconds
res.setHeader(Header.Content.Type, addCharSet(MimeType.JSON));
res.setHeader(
Header.Content.Disposition,
`attachment; filename=${key}`
);
res.write(buffer);
res.end();
}
});
} catch (err) {
view.internalError(res, err);
}
}
示例4: withID
/**
* Render post with matching provider (e.g. Flickr) ID. Redirect to normal URL.
*/
function withID(req: Request, res: Response) {
const post = blog.postWithID(req.params[RouteParam.PostID]);
if (is.value(post)) {
res.redirect(HttpStatus.PermanentRedirect, '/' + post.key);
} else {
view.notFound(req, res);
}
}
示例5: normalizeTag
export function normalizeTag(slug: string): string {
if (is.value(slug)) {
slug = slug.toLowerCase();
} else {
return null;
}
return is.defined(config.photoTagChanges, slug)
? config.photoTagChanges[slug]
: slug;
}
示例6:
.then(post => {
if (is.value(post)) {
res.redirect(
HttpStatus.PermanentRedirect,
`/${post.key}#${photoID}`
);
} else {
view.notFound(req, res);
}
})
示例7: trackJSON
/**
* Compressed GeoJSON of post photos and possible track.
*/
async function trackJSON(req: Request, res: Response) {
const slug = req.params[RouteParam.PostKey];
const post = blog.postWithKey(slug);
if (is.value(post)) {
view.sendJSON(res, `${slug}/${mapPath}`, post.geoJSON.bind(post));
} else {
view.notFound(req, res);
}
}
示例8: search
/**
* Google search results page rendered directly without the `view.send` cache
* pipeline.
*/
function search(req: Request, res: Response) {
const term: string = req.query['q'];
if (is.value(term)) {
res.render(Page.Search, {
title: `Search for â${term}â`
});
} else {
view.notFound(req, res);
}
}
示例9: reject
compress.gzip(Buffer.from(text), (err: Error, buffer: Buffer) => {
if (is.value(err)) {
reject(err);
log.error(err, { slug: key });
} else {
resolve({
buffer,
eTag: key + '_' + new Date().getTime().toString(),
type
});
}
});