All files / validator/yupSource locale.js

58.33% Statements 7/12
0% Branches 0/6
0% Functions 0/1
58.33% Lines 7/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86    3x                                             3x                             3x                                   3x         3x       3x       3x                            
import printValue from './util/printValue'
 
export let mixed = {
  default: '${path} is invalid',
  required: '${path} is a required field',
  oneOf: '${path} must be one of the following values: ${values}',
  notOneOf: '${path} must not be one of the following values: ${values}',
  notType: ({ path, type, value, originalValue }) => {
    let isCast = originalValue != null && originalValue !== value
    let msg =
      `${path} must be a \`${type}\` type, ` +
      `but the final value was: \`${printValue(value, true)}\`` +
      (isCast
        ? ` (cast from the value \`${printValue(originalValue, true)}\`).`
        : '.')
 
    if (value === null) {
      msg += `\n If "null" is intended as an empty value be sure to mark the schema as \`.nullable()\``
    }
 
    return msg
  },
  defined: '${path} must be defined',
}
 
export let string = {
  length: '${path} must be exactly ${length} characters',
  min: '${path} must be at least ${min} characters',
  max: '${path} must be at most ${max} characters',
  matches: '${path} must match the following: "${regex}"',
  email: '${path} must be a valid email',
  url: '${path} must be a valid URL',
  uuid: '${path} must be a valid UUID',
  chineseIDCardNumber: '${path} must be a Chinese identity card number',
  chineseMobilePhoneNumber: '${path} must be a Chinese mobile phone number',
  trim: '${path} must be a trimmed string',
  lowercase: '${path} must be a lowercase string',
  uppercase: '${path} must be a upper case string',
}
 
export let number = {
  min: '${path} must be greater than or equal to ${min}',
  max: '${path} must be less than or equal to ${max}',
  lessThan: '${path} must be less than ${less}',
  moreThan: '${path} must be greater than ${more}',
  notEqual: '${path} must be not equal to ${notEqual}',
  positive: '${path} must be a positive number',
  negative: '${path} must be a negative number',
  integer: '${path} must be an integer',
  id: '${path} must be a positive integer',
  positiveInteger: '${path} must be a positive integer',
  negativeInteger: '${path} must be a negative integer',
  nonPositive: '${path} must be a non-positive number',
  nonNegative: '${path} must be a non-negative number',
  nonPositiveInteger: '${path} must be a non-positive integer',
  nonNegativeInteger: '${path} must be a non-negative integer',
}
 
export let date = {
  min: '${path} field must be later than ${min}',
  max: '${path} field must be at earlier than ${max}',
}
 
export let boolean = {
  isValue: '${path} field must be ${value}',
}
 
export let object = {
  noUnknown: '${path} field has unspecified keys: ${unknown}',
}
 
export let array = {
  min: '${path} field must have at least ${min} items',
  max: '${path} field must have less than or equal to ${max} items',
}
 
export default Object.assign(Object.create(null), {
  mixed,
  string,
  number,
  date,
  object,
  array,
  boolean,
})