本文整理匯總了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
});
}
});