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