UNPKG

@nestjs/common

Version:

Nest - modern, fast, powerful node.js web framework (@common)

18 lines (17 loc) 735 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const exceptions_1 = require("../exceptions"); const uuid = { 3: /^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i, 4: /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i, 5: /^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i, all: /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i, }; function isUUID(str, version = 'all') { if (typeof str !== 'string') { throw new exceptions_1.BadRequestException('The value passed as UUID is not a string'); } const pattern = uuid[version]; return pattern && pattern.test(str); } exports.isUUID = isUUID;