Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use official type for version in @IsUUID decorator #1846

Merged
merged 1 commit into from
Dec 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand Down
7 changes: 3 additions & 4 deletions src/decorator/string/IsUUID.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
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';

/**
* 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);
}

/**
* 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,
Expand Down