language.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. 'use strict';
  2. // Load modules
  3. // Declare internals
  4. const internals = {};
  5. exports.errors = {
  6. root: 'value',
  7. key: '"{{!key}}" ',
  8. messages: {
  9. wrapArrays: true
  10. },
  11. any: {
  12. unknown: 'is not allowed',
  13. invalid: 'contains an invalid value',
  14. empty: 'is not allowed to be empty',
  15. required: 'is required',
  16. allowOnly: 'must be one of {{valids}}',
  17. default: 'threw an error when running default method'
  18. },
  19. alternatives: {
  20. base: 'not matching any of the allowed alternatives'
  21. },
  22. array: {
  23. base: 'must be an array',
  24. includes: 'at position {{pos}} does not match any of the allowed types',
  25. includesSingle: 'single value of "{{!key}}" does not match any of the allowed types',
  26. includesOne: 'at position {{pos}} fails because {{reason}}',
  27. includesOneSingle: 'single value of "{{!key}}" fails because {{reason}}',
  28. includesRequiredUnknowns: 'does not contain {{unknownMisses}} required value(s)',
  29. includesRequiredKnowns: 'does not contain {{knownMisses}}',
  30. includesRequiredBoth: 'does not contain {{knownMisses}} and {{unknownMisses}} other required value(s)',
  31. excludes: 'at position {{pos}} contains an excluded value',
  32. excludesSingle: 'single value of "{{!key}}" contains an excluded value',
  33. min: 'must contain at least {{limit}} items',
  34. max: 'must contain less than or equal to {{limit}} items',
  35. length: 'must contain {{limit}} items',
  36. ordered: 'at position {{pos}} fails because {{reason}}',
  37. orderedLength: 'at position {{pos}} fails because array must contain at most {{limit}} items',
  38. sparse: 'must not be a sparse array',
  39. unique: 'position {{pos}} contains a duplicate value'
  40. },
  41. boolean: {
  42. base: 'must be a boolean'
  43. },
  44. binary: {
  45. base: 'must be a buffer or a string',
  46. min: 'must be at least {{limit}} bytes',
  47. max: 'must be less than or equal to {{limit}} bytes',
  48. length: 'must be {{limit}} bytes'
  49. },
  50. date: {
  51. base: 'must be a number of milliseconds or valid date string',
  52. format: 'must be a string with one of the following formats {{format}}',
  53. strict: 'must be a valid date',
  54. min: 'must be larger than or equal to "{{limit}}"',
  55. max: 'must be less than or equal to "{{limit}}"',
  56. isoDate: 'must be a valid ISO 8601 date',
  57. timestamp: {
  58. javascript: 'must be a valid timestamp or number of milliseconds',
  59. unix: 'must be a valid timestamp or number of seconds'
  60. },
  61. ref: 'references "{{ref}}" which is not a date'
  62. },
  63. function: {
  64. base: 'must be a Function',
  65. arity: 'must have an arity of {{n}}',
  66. minArity: 'must have an arity greater or equal to {{n}}',
  67. maxArity: 'must have an arity lesser or equal to {{n}}',
  68. ref: 'must be a Joi reference'
  69. },
  70. lazy: {
  71. base: '!!schema error: lazy schema must be set',
  72. schema: '!!schema error: lazy schema function must return a schema'
  73. },
  74. object: {
  75. base: 'must be an object',
  76. child: '!!child "{{!child}}" fails because {{reason}}',
  77. min: 'must have at least {{limit}} children',
  78. max: 'must have less than or equal to {{limit}} children',
  79. length: 'must have {{limit}} children',
  80. allowUnknown: '!!"{{!child}}" is not allowed',
  81. with: 'missing required peer "{{peer}}"',
  82. without: 'conflict with forbidden peer "{{peer}}"',
  83. missing: 'must contain at least one of {{peers}}',
  84. xor: 'contains a conflict between exclusive peers {{peers}}',
  85. or: 'must contain at least one of {{peers}}',
  86. and: 'contains {{present}} without its required peers {{missing}}',
  87. nand: '!!"{{main}}" must not exist simultaneously with {{peers}}',
  88. assert: '!!"{{ref}}" validation failed because "{{ref}}" failed to {{message}}',
  89. rename: {
  90. multiple: 'cannot rename child "{{from}}" because multiple renames are disabled and another key was already renamed to "{{to}}"',
  91. override: 'cannot rename child "{{from}}" because override is disabled and target "{{to}}" exists'
  92. },
  93. type: 'must be an instance of "{{type}}"',
  94. schema: 'must be a Joi instance'
  95. },
  96. number: {
  97. base: 'must be a number',
  98. min: 'must be larger than or equal to {{limit}}',
  99. max: 'must be less than or equal to {{limit}}',
  100. less: 'must be less than {{limit}}',
  101. greater: 'must be greater than {{limit}}',
  102. float: 'must be a float or double',
  103. integer: 'must be an integer',
  104. negative: 'must be a negative number',
  105. positive: 'must be a positive number',
  106. precision: 'must have no more than {{limit}} decimal places',
  107. ref: 'references "{{ref}}" which is not a number',
  108. multiple: 'must be a multiple of {{multiple}}'
  109. },
  110. string: {
  111. base: 'must be a string',
  112. min: 'length must be at least {{limit}} characters long',
  113. max: 'length must be less than or equal to {{limit}} characters long',
  114. length: 'length must be {{limit}} characters long',
  115. alphanum: 'must only contain alpha-numeric characters',
  116. token: 'must only contain alpha-numeric and underscore characters',
  117. regex: {
  118. base: 'with value "{{!value}}" fails to match the required pattern: {{pattern}}',
  119. name: 'with value "{{!value}}" fails to match the {{name}} pattern'
  120. },
  121. email: 'must be a valid email',
  122. uri: 'must be a valid uri',
  123. uriCustomScheme: 'must be a valid uri with a scheme matching the {{scheme}} pattern',
  124. isoDate: 'must be a valid ISO 8601 date',
  125. guid: 'must be a valid GUID',
  126. hex: 'must only contain hexadecimal characters',
  127. hostname: 'must be a valid hostname',
  128. lowercase: 'must only contain lowercase characters',
  129. uppercase: 'must only contain uppercase characters',
  130. trim: 'must not have leading or trailing whitespace',
  131. creditCard: 'must be a credit card',
  132. ref: 'references "{{ref}}" which is not a number',
  133. ip: 'must be a valid ip address with a {{cidr}} CIDR',
  134. ipVersion: 'must be a valid ip address of one of the following versions {{version}} with a {{cidr}} CIDR'
  135. }
  136. };