How to use the yup.boolean function in yup

To help you get started, we’ve selected a few yup 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 DefinitelyTyped / DefinitelyTyped / types / yup / yup-tests.ts View on Github external
numSchema.lessThan(5, () => 'lt');
numSchema.moreThan(5);
numSchema.moreThan(5, 'mt');
numSchema.moreThan(5, () => 'mt');
numSchema.integer();
numSchema.integer('int');
numSchema.integer(() => 'int');
numSchema.truncate();
numSchema.round('floor');
numSchema
    .validate(5, { strict: true })
    .then(value => value)
    .catch(err => err);

// Boolean Schema
const boolSchema = yup.boolean();
boolSchema.isValid(true); // => true

// Date Schema
const dateSchema = yup.date();
dateSchema.isValid(new Date()); // => true
dateSchema.min(new Date());
dateSchema.min('2017-11-12');
dateSchema.min(new Date(), 'message');
dateSchema.min('2017-11-12', 'message');
dateSchema.min('2017-11-12', () => 'message');
dateSchema.max(new Date());
dateSchema.max('2017-11-12');
dateSchema.max(new Date(), 'message');
dateSchema.max('2017-11-12', 'message');
dateSchema.max('2017-11-12', () => 'message');
github linode / manager / packages / linode-js-sdk / src / linodes / linodes.schema.ts View on Github external
comments: string(),
  memory_limit: number(),
  run_level: mixed().oneOf(['default', 'single', 'binbash']),
  virt_mode: mixed().oneOf(['paravirt', 'fullvirt']),
  helpers,
  root_device: string()
});

export const CreateLinodeDiskSchema = object({
  size: number().required('Disk size is required.'),
  label: string()
    .required('A disk label is required.')
    .min(1, 'Label must be between 1 and 48 characters.')
    .max(48, 'Label must be between 1 and 48 characters.'),
  filesystem: mixed().oneOf(['raw', 'swap', 'ext3', 'ext4', 'initrd']),
  read_only: boolean(),
  image: string(),
  authorized_keys: array().of(string()),
  authorized_users: array().of(string()),
  root_pass: string().when('image', {
    is: value => Boolean(value),
    then: string()
      .required(
        'You must provide a root password when deploying from an image.'
      )
      .concat(rootPasswordValidation),
    // .test('is-strong-password', 'Please choose a stronger password.', (value: string) => return zxcvbn(value).score > 3),
    otherwise: string().notRequired()
  }),
  stackscript_id: number(),
  stackscript_data
});
github Azure / AIPlatform / end-to-end-solutions / Luna / src / Luna.UI / isv_client / src / routes / Offers / formUtils / planFormUtils.tsx View on Github external
clientId: yup.string(),
          })).max(10, 'Only 10 users may be used.'),
        otherwise: yup.array().notRequired()
      }),
    customMeterDimensions: yup.array().of(
      yup.object().uniqueProperty('meterName', 'No duplicate Meters')
        .shape({
          meterName: yup.mixed().when('isDeleted', {
            is: (val) => {
              return !!val === false
            },
            then: yup.string().required('Meter is required'),
            otherwise: yup.mixed().notRequired()
          }),
          planName: yup.string(),
          monthlyUnlimited: yup.boolean(),
          annualUnlimited: yup.boolean(),
          monthlyQuantityIncludedInBase: yup.number().test('validNumber', 'Not a valid integer', (val): boolean => {
            if (val === null || val === undefined || val === '') {
              return true;
            } else {
              return yup.number().integer().isValidSync(val);
            }
          }).min(0, "Value must be an int greater or equal to 0")
            .required("Included in Base is a required field"),
          annualQuantityIncludedInBase: yup.number(),
          clientId: yup.string(),
        })),
    privatePlan: yup.boolean(),
    isNew: yup.boolean(),
    status: yup.string(),
    createdTime: yup.string(),
github EQuimper / airbnb-meet-hoteltonight-tutorial / server / src / modules / place / controller.ts View on Github external
description: Yup.string(),
    bedroom: Yup.number(),
    bathroom: Yup.number(),
    location: Yup.object().shape({
      address: Yup.string(),
      lat: Yup.number(),
      lng: Yup.number(),
    }),
    price: Yup.number(),
    haveInternet: Yup.boolean(),
    haveAirCond: Yup.boolean(),
    petsAllowed: Yup.boolean(),
    photos: Yup.array().of(Yup.string()),
    haveHeating: Yup.boolean(),
    haveTv: Yup.boolean(),
    isActive: Yup.boolean(),
    maxGuest: Yup.number(),
  });

  try {
    await schema.validate(info);

    const place = await PlaceModel.findById(placeId);

    if (place) {
      if (place.owner.toString() === ownerId.toString()) {
        (Object.keys(info) as (keyof PlaceInfo)[]).forEach(key => {
          place[key] = info[key];
        });

        return place.save();
      }
github lookfirst / mui-rff / example / index.tsx View on Github external
best: string[];
	employed: boolean;
	date: Date;
	hello: string;
	cities: string;
	gender: string;
	birthday: Date;
	break: Date;
	hidden: string;
}

const schema = Yup.object().shape({
	best: Yup.array()
		.min(1)
		.required(),
	employed: Yup.boolean().required(),
	date: Yup.date().required(),
	hello: Yup.string().required(),
	cities: Yup.string().required(),
	gender: Yup.string().required(),
	birthday: Yup.date().required(),
	break: Yup.date().required(),
	hidden: Yup.string().required(),
});

/**
 * Uses the optional helper makeValidate function to format the error messages
 * into something usable by final form.
 */
const validate = makeValidate(schema);

/**
github TheThingsNetwork / lorawan-stack / pkg / webui / console / components / device-import-form / index.js View on Github external
fileImport: 'File Import',
  file: 'File',
  formatInfo: 'Format Information',
  createDevices: 'Create Devices',
  selectAFile: 'Please select a template file',
  fileInfoPlaceholder: 'Please select a template format',
  claimAuthCode: 'Set claim authentication code',
  targetedComponents: 'Targeted Components',
})

const validationSchema = Yup.object({
  format_id: Yup.string().required(sharedMessages.validateRequired),
  data: Yup.string().required(m.selectAFile),
  set_claim_auth_code: Yup.boolean(),
  components: Yup.object({
    is: Yup.boolean().required(),
    as: Yup.boolean(),
    js: Yup.boolean(),
    ns: Yup.boolean(),
  }).required(sharedMessages.validateRequired),
})

export default class DeviceBulkCreateForm extends Component {
  static propTypes = {
    components: PropTypes.components.isRequired,
    initialValues: PropTypes.shape({
      format_id: PropTypes.string,
      data: PropTypes.string,
      set_claim_auth_code: PropTypes.bool,
    }).isRequired,
    onSubmit: PropTypes.func.isRequired,
  }
github linode / manager / packages / linode-js-sdk / src / nodebalancers / nodebalancers.schema.ts View on Github external
.typeError('Weight must be a number.')
    .min(1, `Weight must be between 1 and 255.`)
    .max(255, `Weight must be between 1 and 255.`),

  mode: mixed().oneOf(['accept', 'reject', 'backup', 'drain'])
});

export const createNodeBalancerConfigSchema = object({
  algorithm: mixed().oneOf(['roundrobin', 'leastconn', 'source']),
  check_attempts: number(),
  check_body: string().when('check', {
    is: check => check === 'http_body',
    then: string().required()
  }),
  check_interval: number().typeError('Check interval must be a number.'),
  check_passive: boolean(),
  check_path: string()
    .matches(/\/.*/)
    .when('check', {
      is: check => check === 'http',
      then: string().required()
    })
    .when('check', {
      is: check => check === 'http_body',
      then: string().required()
    }),
  check_timeout: number()
    .typeError('Timeout must be a number.')
    .integer(),
  check: mixed().oneOf(['none', 'connection', 'http', 'http_body']),
  cipher_suite: mixed().oneOf(['recommended', 'legacy']),
  port: number()
github instamed / healthcare-payments-blockchain / packages / financial-cc / src / financial.model.ts View on Github external
@Validate(yup.lazy(() => Period.schema()))
   public period?: FlatConvectorModel;

}

export class PatientCommunication extends BackboneElement {
   @Default('fhir.datatypes.Patient.PatientCommunication')
   @ReadOnly()
   public readonly type: string;

   @Required()
   @Validate(yup.lazy(() => CodeableConcept.schema()))
   public language: FlatConvectorModel;

   @Validate(yup.boolean())
   public preferred?: boolean;

}

export class PatientLink extends BackboneElement {
   @Default('fhir.datatypes.Patient.PatientLink')
   @ReadOnly()
   public readonly type: string;

   @Required()
   @Validate(yup.lazy(() => Reference.schema()))
   public other: FlatConvectorModel; //Patient|RelatedPerson

   @Required()
   @Validate(yup.string())
   public type_: string;
github linode / manager / packages / linode-js-sdk / src / account / account.schema.ts View on Github external
.max(9999, 'Expiration year must be four digits.'),
  expiry_month: number()
    .required('Expiration month is required.')
    .min(1, 'Expiration month must be a number from 1 to 12.')
    .max(12, 'Expiration month must be a number from 1 to 12.')
});

export const CreateUserSchema = object({
  username: string()
    .required('Username is required.')
    .min(3, 'Username must be between 3 and 32 characters.')
    .max(32, 'Username must be between 3 and 32 characters.'),
  email: string()
    .required('Email address is required.')
    .email('Must be a valid email address.'),
  restricted: boolean().required(
    'You must indicate if this user should have restricted access.'
  )
});

export const UpdateUserSchema = object({
  username: string()
    .min(3, 'Username must be between 3 and 32 characters.')
    .max(32, 'Username must be between 3 and 32 characters.'),
  email: string().email('Must be a valid email address.'),
  restricted: boolean()
});

const GrantSchema = object({
  id: number().required('ID is required.'),
  permissions: mixed().oneOf(
    [null, 'read_only', 'read_write'],
github TheThingsNetwork / lorawan-stack / pkg / webui / console / components / device-import-form / index.js View on Github external
createDevices: 'Create Devices',
  selectAFile: 'Please select a template file',
  fileInfoPlaceholder: 'Please select a template format',
  claimAuthCode: 'Set claim authentication code',
  targetedComponents: 'Targeted Components',
})

const validationSchema = Yup.object({
  format_id: Yup.string().required(sharedMessages.validateRequired),
  data: Yup.string().required(m.selectAFile),
  set_claim_auth_code: Yup.boolean(),
  components: Yup.object({
    is: Yup.boolean().required(),
    as: Yup.boolean(),
    js: Yup.boolean(),
    ns: Yup.boolean(),
  }).required(sharedMessages.validateRequired),
})

export default class DeviceBulkCreateForm extends Component {
  static propTypes = {
    components: PropTypes.components.isRequired,
    initialValues: PropTypes.shape({
      format_id: PropTypes.string,
      data: PropTypes.string,
      set_claim_auth_code: PropTypes.bool,
    }).isRequired,
    onSubmit: PropTypes.func.isRequired,
  }

  state = {
    allowedFileExtensions: undefined,