From 4cf00c9a0d223f1806f778630fffea15b7bb78e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20Ol=C3=A1h?= Date: Fri, 9 Dec 2022 21:30:49 +0000 Subject: [PATCH] feat: use official type for version in `@IsUUID` decorator --- README.md | 2 +- src/decorator/string/IsUUID.ts | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 9f39d39a73..b1d76bc84d 100644 --- a/README.md +++ b/README.md @@ -887,7 +887,7 @@ isBoolean(value); | `@IsTaxId()` | Checks if the string is a valid tax ID. Default locale is `en-US`. | `@IsUrl(options?: IsURLOptions)` | Checks if the string is a URL. | | `@IsMagnetURI()` | Checks if the string is a [magnet uri format](https://en.wikipedia.org/wiki/Magnet_URI_scheme). | -| `@IsUUID(version?: "3"\|"4"\|"5"\|"all")` | Checks if the string is a UUID (version 3, 4, 5 or all ). | +| `@IsUUID(version?: UUIDVersion)` | Checks if the string is a UUID (version 3, 4, 5 or all ). | | `@IsFirebasePushId()` | Checks if the string is a [Firebase Push ID](https://firebase.googleblog.com/2015/02/the-2120-ways-to-ensure-unique_68.html) | | `@IsUppercase()` | Checks if the string is uppercase. | | `@Length(min: number, max?: number)` | Checks if the string's length falls in a range. | diff --git a/src/decorator/string/IsUUID.ts b/src/decorator/string/IsUUID.ts index a767b8f924..fd483fede7 100644 --- a/src/decorator/string/IsUUID.ts +++ b/src/decorator/string/IsUUID.ts @@ -1,8 +1,7 @@ import { ValidationOptions } from '../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isUuidValidator from 'validator/lib/isUUID'; - -export type UUIDVersion = '3' | '4' | '5' | 'all' | 3 | 4 | 5; +import type ValidatorJS from 'validator'; export const IS_UUID = 'isUuid'; @@ -10,7 +9,7 @@ export const IS_UUID = 'isUuid'; * Checks if the string is a UUID (version 3, 4 or 5). * If given value is not a string, then it returns false. */ -export function isUUID(value: unknown, version?: UUIDVersion): boolean { +export function isUUID(value: unknown, version?: ValidatorJS.UUIDVersion): boolean { return typeof value === 'string' && isUuidValidator(value, version); } @@ -18,7 +17,7 @@ export function isUUID(value: unknown, version?: UUIDVersion): boolean { * Checks if the string is a UUID (version 3, 4 or 5). * If given value is not a string, then it returns false. */ -export function IsUUID(version?: UUIDVersion, validationOptions?: ValidationOptions): PropertyDecorator { +export function IsUUID(version?: ValidatorJS.UUIDVersion, validationOptions?: ValidationOptions): PropertyDecorator { return ValidateBy( { name: IS_UUID,