Skip to content

Commit a33eb7f

Browse files
feat: use official type for version in @IsUUID decorator (#1846)
1 parent b0d4a23 commit a33eb7f

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ isBoolean(value);
887887
| `@IsTaxId()` | Checks if the string is a valid tax ID. Default locale is `en-US`.
888888
| `@IsUrl(options?: IsURLOptions)` | Checks if the string is a URL. |
889889
| `@IsMagnetURI()` | Checks if the string is a [magnet uri format](https://en.wikipedia.org/wiki/Magnet_URI_scheme). |
890-
| `@IsUUID(version?: "3"\|"4"\|"5"\|"all")` | Checks if the string is a UUID (version 3, 4, 5 or all ). |
890+
| `@IsUUID(version?: UUIDVersion)` | Checks if the string is a UUID (version 3, 4, 5 or all ). |
891891
| `@IsFirebasePushId()` | Checks if the string is a [Firebase Push ID](https://firebase.googleblog.com/2015/02/the-2120-ways-to-ensure-unique_68.html) |
892892
| `@IsUppercase()` | Checks if the string is uppercase. |
893893
| `@Length(min: number, max?: number)` | Checks if the string's length falls in a range. |

src/decorator/string/IsUUID.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
import { ValidationOptions } from '../ValidationOptions';
22
import { buildMessage, ValidateBy } from '../common/ValidateBy';
33
import isUuidValidator from 'validator/lib/isUUID';
4-
5-
export type UUIDVersion = '3' | '4' | '5' | 'all' | 3 | 4 | 5;
4+
import type ValidatorJS from 'validator';
65

76
export const IS_UUID = 'isUuid';
87

98
/**
109
* Checks if the string is a UUID (version 3, 4 or 5).
1110
* If given value is not a string, then it returns false.
1211
*/
13-
export function isUUID(value: unknown, version?: UUIDVersion): boolean {
12+
export function isUUID(value: unknown, version?: ValidatorJS.UUIDVersion): boolean {
1413
return typeof value === 'string' && isUuidValidator(value, version);
1514
}
1615

1716
/**
1817
* Checks if the string is a UUID (version 3, 4 or 5).
1918
* If given value is not a string, then it returns false.
2019
*/
21-
export function IsUUID(version?: UUIDVersion, validationOptions?: ValidationOptions): PropertyDecorator {
20+
export function IsUUID(version?: ValidatorJS.UUIDVersion, validationOptions?: ValidationOptions): PropertyDecorator {
2221
return ValidateBy(
2322
{
2423
name: IS_UUID,

0 commit comments

Comments
 (0)