本文整理汇总了TypeScript中uuid/v1.v1函数的典型用法代码示例。如果您正苦于以下问题:TypeScript v1函数的具体用法?TypeScript v1怎么用?TypeScript v1使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了v1函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: replaceTemplateObjectNames
/**
* Modifies variables names of tagged template literals (`"_templateObject"`)
* from a given string so that they're all unique.
*
* This is needed to workaround a potential naming collision when individually
* transpiled scripts are bundled. See #950.
*/
function replaceTemplateObjectNames(js: string): string {
// Breakdown of regular expression to match "_templateObject" variables
//
// Pattern | Meaning
// -------------------------------------------------------------------
// ( | Group1
// _templateObject | Match "_templateObject"
// \d* | Match 0 or more digits
// \b | Match word boundary
// ) | End Group1
const searchValueRegex = /(_templateObject\d*\b)/g;
// The replacement pattern appends an underscore and UUID to the matches:
//
// Pattern | Meaning
// -------------------------------------------------------------------
// $1 | Insert matching Group1 (from above)
// _ | Insert "_"
// ${uniqueId} | Insert previously generated UUID
const uniqueId = uuid().replace(/-/g, '');
const replaceValue = `$1_${uniqueId}`;
// Example output:
// _templateObject -> _templateObject_200817b1154811e887be8b38cea68555
// _templateObject2 -> _templateObject2_5e44de8015d111e89b203116b5c54903
return js.replace(searchValueRegex, replaceValue);
}
示例2: create
export function create(req: express.Request, res: express.Response) {
const image: IImage = {
id: uuid(),
image: req.body.image
};
redisClient.set(image.id, image.image, function (err: any, reply: any) {
if (err) {
return errorHandler.handleError(res, err);
}
res.json({ id: image.id });
});
}