How to use the class-transformer.Exclude function in class-transformer

To help you get started, we’ve selected a few class-transformer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github goparrot / geocoder / src / util / world-country / world-country-name.ts View on Github external
import { Exclude, Expose } from 'class-transformer';
import { IsOptional, IsString, MinLength } from 'class-validator';

@Exclude()
export class WorldCountryName {
    @IsString()
    @IsOptional()
    @MinLength(1)
    @Expose()
    common: string;
    @IsString()
    @IsOptional()
    @MinLength(1)
    @Expose()
    official: string;
}
github Kibibit / achievibit / src / config / achievibit-config.model.ts View on Github external
import { Exclude, Expose, Transform } from 'class-transformer';
import { IsBoolean, IsIn, IsNumber, IsOptional, IsString, IsUrl, Matches } from 'class-validator';
import { trim } from 'lodash';
import { v1 as uuidv1 } from 'uuid';

export const NODE_ENVIRONMENT_OPTIONS = [ 'development', 'production', 'test' ];
export const SMEE_IO_REGEX = /^https:\/\/(?:www\.)?smee\.io\/[a-zA-Z0-9_-]+\/?/;
export const ENDPONT_PATH_REGEX = /^([\w]+)?(\/[\w-]+)*$/;

@Exclude()
export class AchievibitConfig {
  @Expose()
  @IsString()
  @IsIn(NODE_ENVIRONMENT_OPTIONS)
  nodeEnv = 'development';

  @Expose()
  @IsNumber()
  port = 10101;

  @Expose()
  @IsOptional()
  @IsString()
  @IsUrl({ protocols: [ 'mongodb', 'mongodb+srv' ], require_tld: false }, {
    message: '$property should be a valid mongodb URL'
  })
github goparrot / geocoder / src / model / suggestion.ts View on Github external
import { classToPlain, ClassTransformOptions, Exclude, Expose } from 'class-transformer';
import { SuggestionInterface } from '../interface';

@Exclude()
export class Suggestion implements SuggestionInterface {
    @Expose()
    formattedAddress: string;

    @Expose()
    placeId: string;

    @Expose()
    provider: string;

    @Expose({ groups: ['raw', 'all'] })
    raw?: ProviderRawEntryType;

    toObject(options?: ClassTransformOptions): SuggestionInterface {
        return classToPlain>(this, options) as SuggestionInterface;
    }
github jiayisheji / jianshu / libs / api-interfaces / src / lib / client / auth.dao.ts View on Github external
* 登录密码
   */
  password: string;
  /**
   * 手机号码
   */
  mobile: string;
  /**
   * 手机验证码
   */
  code: string;
}

export interface Token { expiresIn: number; accessToken: string; tokenType: string; }

@Exclude()
export class UserInfo {
  @Expose() public id: string;
  @Expose() public nickname: string;
  @Expose() public avatar: string;
}

export interface LoginDao {
  user: UserInfo;
  token: Token;
}
github goparrot / geocoder / src / util / world-country-state / world-country-state.ts View on Github external
import { Exclude, Expose, Transform } from 'class-transformer';
import { IsOptional, IsString, MaxLength, MinLength } from 'class-validator';
import { WorldCountryStateInterface } from './world-country-state.interface';

@Exclude()
export class WorldCountryState implements WorldCountryStateInterface {
    @IsString()
    @MinLength(2)
    @MaxLength(2)
    @Transform((v: string) =>
        v
            .toString()
            .trim()
            .toUpperCase(),
    )
    @Expose()
    countryCode: string;

    @IsOptional()
    @IsString()
    @MinLength(2)
github goparrot / geocoder / src / model / location.ts View on Github external
import { classToPlain, ClassTransformOptions, Exclude, Expose } from 'class-transformer';
import { LocationInterface } from '../interface';

@Exclude()
export class Location implements LocationInterface {
    @Expose()
    provider: string;

    /**
     * @example 1200 E 89th St, Chicago, IL 60619, USA
     * @example 1158 E 89th St, Chicago, Illinois 60619, US
     */
    @Expose({ name: 'formattedAddress', toClassOnly: true })
    formattedAddress?: string;

    @Expose()
    latitude: number;

    @Expose()
    longitude: number;
github goparrot / geocoder / src / util / world-country-state / world-country-state-query.ts View on Github external
import { Exclude, Expose, Transform } from 'class-transformer';
import { IsOptional, IsString, MaxLength, MinLength } from 'class-validator';
import { WorldCountryStateQueryInterface } from './world-country-state-query.interface';

@Exclude()
export class WorldCountryStateQuery implements WorldCountryStateQueryInterface {
    @IsString()
    @MinLength(2)
    @MaxLength(2)
    @Transform((v: string) => v.trim())
    @Expose()
    countryCode: string;

    @IsOptional()
    @IsString()
    @MinLength(2)
    @MaxLength(2)
    @Transform((v: string) =>
        v
            ? v
                  .toString()
github solenya-group / solenya / src / util.ts View on Github external
export function transient (target: Object, propertyKey: string) {
    Reflect.metadata ("transient", true)(target, propertyKey)
    Exclude()(target, propertyKey)
}
github Kibibit / achievibit / src / config / config.service.ts View on Github external
parseValues: true,
    transform: transformToLowerCase
  })
  .file({ file: configFilePath });

let smee: SmeeClient;
let events: any;
let configService: ConfigService;

/**
 * This is a **Forced Singleton**.
 * This means that even if you try to create
 * another ConfigService, you'll always get the
 * first one.
 */
@Exclude()
export class ConfigService extends AchievibitConfig {
  private readonly logger: Logger = new Logger('ConfigService');

  private readonly mode: string = environment;

  get smee(): SmeeClient {
    return smee;
  }

  get events(): any {
    return events;
  }

  get packageDetails(): PackageDetailsDto {
    return packageDetails;
  }
github goparrot / geocoder / src / util / world-country / world-country-query.ts View on Github external
import { Exclude, Expose, Transform } from 'class-transformer';
import { IsInt, IsNumberString, IsOptional, IsString, MaxLength, MinLength } from 'class-validator';
import { WorldCountryQueryInterface } from './world-country-query.interface';

@Exclude()
export class WorldCountryQuery implements WorldCountryQueryInterface {
    @IsString()
    @IsOptional()
    @MinLength(1)
    @Transform((v: string) => (v ? v.trim() : undefined))
    @Expose()
    name?: string;

    @IsOptional()
    @IsString()
    @MinLength(2)
    @MaxLength(2)
    @Transform((v: string) =>
        v
            ? v
                  .toString()