class-validator#IsString TypeScript Examples

The following examples show how to use class-validator#IsString. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: custom-validators.ts    From relate with GNU General Public License v3.0 6 votes vote down vote up
export function IsPluginConfig(validationOptions?: ValidationOptions) {
    return (object: any, propertyName: string) => {
        registerDecorator({
            name: 'isPluginConfig',
            target: object.constructor,
            propertyName: propertyName,
            options: validationOptions,
            validator: {
                validate(value: any, _args: ValidationArguments) {
                    if (isObjectLike(value)) {
                        return Object.entries(value).every(([_, v]) => {
                            if (isArray(v)) {
                                // eslint-disable-next-line @typescript-eslint/ban-ts-comment
                                // @ts-ignore
                                return Array.from(v).every(isString);
                            }

                            return isString(v) || isBoolean(v);
                        });
                    }

                    return false;
                },
                defaultMessage(args?: ValidationArguments) {
                    const expectedMsg = 'Expected "{ [key: string]: string | string[] | boolean }"';

                    if (!args) {
                        return expectedMsg;
                    }

                    const strValue = JSON.stringify(args.value);
                    return `${expectedMsg} on "${args.property}" but found "${strValue}" instead`;
                },
            },
        });
    };
}
Example #2
Source File: query-builder.ts    From typeorm-query-builder-wrapper with MIT License 6 votes vote down vote up
/**
   * Select one or multiple fields with each Alias field
   *
   * @param args Array of Array of field with alias, e.g: ['t1.id', 'id'], ...
   */
  public selectRaw(...args: Array<string | string[]>) {
    const expressionArgs = args.filter(
      arg => isString(arg) || (isArray(arg) && arg.length <= 2),
    );
    if (!expressionArgs.length) {
      throw new Error(`String expression is required for the selectRaw method`);
    }

    for (const arg of args) {
      if (args.indexOf(arg) === 0) {
        if (arg[1]) {
          this.qb.select(arg[0], arg[1]);
        } else {
          this.qb.select(arg[0]);
        }
      } else {
        if (arg[1]) {
          this.qb.addSelect(arg[0], arg[1]);
        } else {
          this.qb.addSelect(arg[0]);
        }
      }
    }

    return this;
  }
Example #3
Source File: classes.ts    From epicgames-freegames-node with MIT License 6 votes vote down vote up
/**
   * TZ name from this list: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List
   * @example America/Chicago
   * @default UTC
   * @env TZ
   */
  @IsOptional()
  @IsString()
  timezone = process.env.TZ || 'UTC';
Example #4
Source File: vulnerabilities.ts    From crossfeed with Creative Commons Zero v1.0 Universal 6 votes vote down vote up
@IsString()
  @IsIn([
    'title',
    'createdAt',
    'severity',
    'cvss',
    'state',
    'createdAt',
    'domain'
  ])
  @IsOptional()
  sort: string = 'createdAt';
Example #5
Source File: RenameTodo.ts    From remix-hexagonal-architecture with MIT License 5 votes vote down vote up
@IsString()
  todoId!: string;
Example #6
Source File: create-collection.dto.ts    From aqualink-app with MIT License 5 votes vote down vote up
@ApiProperty({ example: 'La NiƱa heatwave 20/21' })
  @IsNotEmpty()
  @IsString()
  name: string;
Example #7
Source File: users.ts    From crossfeed with Creative Commons Zero v1.0 Universal 5 votes vote down vote up
@IsString()
  firstName: string;
Example #8
Source File: ParametersValidator.ts    From affinidi-core-sdk with Apache License 2.0 5 votes vote down vote up
static validatePrimitive(schema: string, value: any) {
    let message: string
    let isValid: boolean = true

    switch (schema) {
      case did:
        isValid = matches(value, DID)
        message = `Parameter "${value}" is not a valid. Valid format: (${DID}).`
        break

      case didMethod:
        isValid = matches(value, DID_METHOD)
        message = `Parameter "${value}" is not a valid. Valid format: (${DID_METHOD}).`
        break

      case jwt:
        isValid = matches(value, JWT)
        message = `Parameter "${value}" is not a valid JWT. Valid format: (${JWT}).`
        break

      case array:
        isValid = isArray(value)
        message = `Parameter "${value}" should be an array.`
        break

      case number:
        isValid = isNumber(value)
        message = `Parameter "${value}" should be a number.`
        break

      case object:
        isValid = isObject(value)
        message = `Parameter "${value}" should be an object.`
        break

      case string:
        isValid = isString(value)
        message = `Parameter "${value}" should be a string.`
        break

      case boolean:
        isValid = isBoolean(value)
        message = `Parameter "${value}" should be a boolean.`
        break

      case isoString:
        isValid = isISO8601(value)
        message = `Parameter "${value}" is not a valid ISO 8601 date string.`
        break

      case confirmationCode:
        isValid = matches(value, COGNITO_CONFIRMATION_CODE)
        message = `Parameter "${value}" is not a valid confirmation code. Valid format: (${COGNITO_CONFIRMATION_CODE}).`
        break

      case password:
        isValid = matches(value, PASSWORD)
        message = `Parameter "${value}" is not a password. Valid format: (${PASSWORD}).`
        break
    }

    return { isValid, message }
  }
Example #9
Source File: create-announcement.dto.ts    From edu-server with MIT License 5 votes vote down vote up
/**
   * Creator of the announcement
   * @example 'John Doe'
   */
  @IsNotEmpty()
  @IsString()
  added_by: string;
Example #10
Source File: classes.ts    From epicgames-freegames-node with MIT License 5 votes vote down vote up
/**
   * Epic Games login password
   * @example abc1234
   * @env PASSWORD
   */
  @IsString()
  @MinLength(7)
  password: string;
Example #11
Source File: vulnerabilities.ts    From crossfeed with Creative Commons Zero v1.0 Universal 5 votes vote down vote up
@IsString()
  @IsOptional()
  @IsIn(['title'])
  groupBy?: 'title';