mirror of
https://github.com/nestjs/nest.git
synced 2026-02-21 23:11:44 +00:00
Use every util defined at `shared.utils.ts` from `@nestjs/common`, when possible. Only spec files aren't touched.
18 lines
654 B
TypeScript
18 lines
654 B
TypeScript
import { BadRequestException } from '../exceptions';
|
|
import { isString } from './shared.utils';
|
|
|
|
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,
|
|
};
|
|
|
|
export function isUUID(str: any, version = 'all') {
|
|
if (!isString(str)) {
|
|
throw new BadRequestException('The value passed as UUID is not a string');
|
|
}
|
|
const pattern = uuid[version];
|
|
return pattern && pattern.test(str);
|
|
}
|