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

feature: @isBigInt #1255

Open
SamuelScheit opened this issue Aug 22, 2021 · 1 comment · May be fixed by #2506
Open

feature: @isBigInt #1255

SamuelScheit opened this issue Aug 22, 2021 · 1 comment · May be fixed by #2506
Labels
flag: needs discussion Issues which needs discussion before implementation. type: feature Issues related to new features.

Comments

@SamuelScheit
Copy link

SamuelScheit commented Aug 22, 2021

Additionally to IsInt add a @IsBigInt decorator

@SamuelScheit SamuelScheit added flag: needs discussion Issues which needs discussion before implementation. type: feature Issues related to new features. labels Aug 22, 2021
@ales-albert-kilbergr
Copy link

ales-albert-kilbergr commented Jul 16, 2024

Hi. I would also benefit from the @isBigInt decorator.

The IsBigint decorator would check only if a given value is a type of a bigint, the same way as the IsInt decorator only checks if the value is an integer.

Here is an example of an implementation I'm currently using in my projects:

import {
  buildMessage,
  ValidateBy,
  ValidationOptions
  } from 'class-validator';

export const IS_BIGINT = 'isBigInt';

/**
 * Checks if the value is a bigint.
 */
export function isBigInt(val: unknown): val is Number {
  return typeof value === 'bigint';
}

/**
 * Checks if the value is a bigintt
 */
export function IsBigInt(validationOptions?: ValidationOptions): PropertyDecorator {
  return ValidateBy(
    {
      name: IS_BIGINT,
      validator: {
        validate: (value, args): boolean => isBigInt(value),
        defaultMessage: buildMessage(
          (eachPrefix) => eachPrefix + '$property must be a bigint',
          validationOptions
        ),
      },
    },
    validationOptions
  );
}

I'm ready to create a PR with the implementation.

@ales-albert-kilbergr ales-albert-kilbergr linked a pull request Jul 16, 2024 that will close this issue
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flag: needs discussion Issues which needs discussion before implementation. type: feature Issues related to new features.
Development

Successfully merging a pull request may close this issue.

2 participants