<commit_before><!-- version -->
# 7.2.2 API Reference
<!-- versionstop -->

<img src="https://raw.github.com/hapijs/joi/master/images/validation.png" align="right" />

<!-- toc -->

- [Joi](#joi)
  - [`validate(value, schema, [options], [callback])`](#validatevalue-schema-options-callback)
  - [`compile(schema)`](#compileschema)
  - [`assert(value, schema, [message])`](#assertvalue-schema-message)
  - [`attempt(value, schema, [message])`](#attemptvalue-schema-message)
  - [`isRef(ref)`](#isrefref)
  - [`any`](#any)
    - [`any.allow(value)`](#anyallowvalue)
    - [`any.valid(value)` - aliases: `only`, `equal`](#anyvalidvalue---aliases-only-equal)
    - [`any.invalid(value)` - aliases: `disallow`, `not`](#anyinvalidvalue---aliases-disallow-not)
    - [`any.required()`](#anyrequired)
    - [`any.optional()`](#anyoptional)
    - [`any.forbidden()`](#anyforbidden)
    - [`any.strip()`](#anystrip)
    - [`any.description(desc)`](#anydescriptiondesc)
    - [`any.notes(notes)`](#anynotesnotes)
    - [`any.tags(tags)`](#anytagstags)
    - [`any.meta(meta)`](#anymetameta)
    - [`any.example(value)`](#anyexamplevalue)
    - [`any.unit(name)`](#anyunitname)
    - [`any.options(options)`](#anyoptionsoptions)
    - [`any.strict(isStrict)`](#anystrictisstrict)
    - [`any.default([value, [description]])`](#anydefaultvalue-description)
    - [`any.concat(schema)`](#anyconcatschema)
    - [`any.when(ref, options)`](#anywhenref-options)
    - [`any.label(name)`](#anylabelname)
    - [`any.raw(isRaw)`](#anyrawisraw)
    - [`any.empty(schema)`](#anyemptyschema)
  - [`array`](#array)
    - [`array.sparse(enabled)`](#arraysparseenabled)
    - [`array.single(enabled)`](#arraysingleenabled)
    - [`array.items(type)`](#arrayitemstype)
    - [`array.ordered(type)`](#arrayorderedtype)
    - [`array.min(limit)`](#arrayminlimit)
    - [`array.max(limit)`](#arraymaxlimit)
    - [`array.length(limit)`](#arraylengthlimit)
    - [`array.unique()`](#arrayunique)
  - [`boolean`](#boolean)
  - [`binary`](#binary)
    - [`binary.encoding(encoding)`](#binaryencodingencoding)
    - [`binary.min(limit)`](#binaryminlimit)
    - [`binary.max(limit)`](#binarymaxlimit)
    - [`binary.length(limit)`](#binarylengthlimit)
  - [`date`](#date)
    - [`date.min(date)`](#datemindate)
    - [`date.max(date)`](#datemaxdate)
    - [`date.format(format)`](#dateformatformat)
    - [`date.iso()`](#dateiso)
    - [`date.timestamp([type])`](#datetimestamptype)
  - [`func`](#func)
    - [`func.arity(n)`](#funcarityn)
    - [`func.minArity(n)`](#funcminarityn)
    - [`func.maxArity(n)`](#funcmaxarityn)
  - [`number`](#number)
    - [`number.min(limit)`](#numberminlimit)
    - [`number.max(limit)`](#numbermaxlimit)
    - [`number.greater(limit)`](#numbergreaterlimit)
    - [`number.less(limit)`](#numberlesslimit)
    - [`number.integer()`](#numberinteger)
    - [`number.precision(limit)`](#numberprecisionlimit)
    - [`number.multiple(base)`](#numbermultiplebase)
    - [`number.positive()`](#numberpositive)
    - [`number.negative()`](#numbernegative)
  - [`object`](#object)
    - [`object.keys([schema])`](#objectkeysschema)
      - [`{} notation`](#-notation)
      - [`Joi.object([schema]) notation`](#joiobjectschema-notation)
      - [`Joi.object().keys([schema]) notation`](#joiobjectkeysschema-notation)
    - [`object.min(limit)`](#objectminlimit)
    - [`object.max(limit)`](#objectmaxlimit)
    - [`object.length(limit)`](#objectlengthlimit)
    - [`object.pattern(regex, schema)`](#objectpatternregex-schema)
    - [`object.and(peers)`](#objectandpeers)
    - [`object.nand(peers)`](#objectnandpeers)
    - [`object.or(peers)`](#objectorpeers)
    - [`object.xor(peers)`](#objectxorpeers)
    - [`object.with(key, peers)`](#objectwithkey-peers)
    - [`object.without(key, peers)`](#objectwithoutkey-peers)
    - [`object.rename(from, to, [options])`](#objectrenamefrom-to-options)
    - [`object.assert(ref, schema, [message])`](#objectassertref-schema-message)
    - [`object.unknown([allow])`](#objectunknownallow)
    - [`object.type(constructor, [name])`](#objecttypeconstructor-name)
    - [`object.requiredKeys(children)`](#objectrequiredkeyschildren)
    - [`object.optionalKeys(children)`](#objectoptionalkeyschildren)
  - [`string`](#string)
    - [`string.insensitive()`](#stringinsensitive)
    - [`string.min(limit, [encoding])`](#stringminlimit-encoding)
    - [`string.max(limit, [encoding])`](#stringmaxlimit-encoding)
    - [`string.creditCard()`](#stringcreditcard)
    - [`string.length(limit, [encoding])`](#stringlengthlimit-encoding)
    - [`string.regex(pattern, [name])`](#stringregexpattern-name)
    - [`string.replace(pattern, replacement)`](#stringreplacepattern-replacement)
    - [`string.alphanum()`](#stringalphanum)
    - [`string.token()`](#stringtoken)
    - [`string.email([options])`](#stringemailoptions)
    - [`string.ip([options])`](#stringipoptions)
    - [`string.uri([options])`](#stringurioptions)
    - [`string.guid()`](#stringguid)
    - [`string.hex()`](#stringhex)
    - [`string.hostname()`](#stringhostname)
    - [`string.lowercase()`](#stringlowercase)
    - [`string.uppercase()`](#stringuppercase)
    - [`string.trim()`](#stringtrim)
    - [`string.isoDate()`](#stringisodate)
  - [`alternatives`](#alternatives)
    - [`alternatives.try(schemas)`](#alternativestryschemas)
    - [`alternatives.when(ref, options)`](#alternativeswhenref-options)
  - [`ref(key, [options])`](#refkey-options)
- [Errors](#errors)

<!-- tocstop -->

## Joi

### `validate(value, schema, [options], [callback])`

Validates a value using the given schema and options where:
- `value` - the value being validated.
- `schema` - the validation schema. Can be a **joi** type object or a plain object where every key is assigned a **joi** type object.
- `options` - an optional object with the following optional keys:
  - `abortEarly` - when `true`, stops validation on the first error, otherwise returns all the errors found. Defaults to `true`.
  - `convert` - when `true`, attempts to cast values to the required types (e.g. a string to a number). Defaults to `true`.
  - `allowUnknown` - when `true`, allows object to contain unknown keys which are ignored. Defaults to `false`.
  - `skipFunctions` - when `true`, ignores unknown keys with a function value. Defaults to `false`.
  - `stripUnknown` - when `true`, unknown keys are deleted (only when value is an object or an array). Defaults to `false`.
  - `language` - overrides individual error messages, when `'label'` is set, it overrides the key name in the error message. Defaults to no override (`{}`).
  - `presence` - sets the default presence requirements. Supported modes: `'optional'`, `'required'`, and `'forbidden'`.
    Defaults to `'optional'`.
  - `context` - provides an external data set to be used in [references](#refkey-options). Can only be set as an external option to
    `validate()` and not using `any.options()`.
  - `noDefaults` - when `true`, do not apply default values. Defaults to `false`.
- `callback` - the optional synchronous callback method using the signature `function(err, value)` where:
  - `err` - if validation failed, the [error](#errors) reason, otherwise `null`.
  - `value` - the validated value with any type conversions and other modifiers applied (the input is left unchanged). `value` can be
    incomplete if validation failed and `abortEarly` is `true`. If callback is not provided, then returns an object with [error](#errors)
    and value properties.

```javascript
const schema = {<commit_msg>Clarify language behavior<commit_after><!-- version -->
# 7.2.2 API Reference
<!-- versionstop -->

<img src="https://raw.github.com/hapijs/joi/master/images/validation.png" align="right" />

<!-- toc -->

- [Joi](#joi)
  - [`validate(value, schema, [options], [callback])`](#validatevalue-schema-options-callback)
  - [`compile(schema)`](#compileschema)
  - [`assert(value, schema, [message])`](#assertvalue-schema-message)
  - [`attempt(value, schema, [message])`](#attemptvalue-schema-message)
  - [`isRef(ref)`](#isrefref)
  - [`any`](#any)
    - [`any.allow(value)`](#anyallowvalue)
    - [`any.valid(value)` - aliases: `only`, `equal`](#anyvalidvalue---aliases-only-equal)
    - [`any.invalid(value)` - aliases: `disallow`, `not`](#anyinvalidvalue---aliases-disallow-not)
    - [`any.required()`](#anyrequired)
    - [`any.optional()`](#anyoptional)
    - [`any.forbidden()`](#anyforbidden)
    - [`any.strip()`](#anystrip)
    - [`any.description(desc)`](#anydescriptiondesc)
    - [`any.notes(notes)`](#anynotesnotes)
    - [`any.tags(tags)`](#anytagstags)
    - [`any.meta(meta)`](#anymetameta)
    - [`any.example(value)`](#anyexamplevalue)
    - [`any.unit(name)`](#anyunitname)
    - [`any.options(options)`](#anyoptionsoptions)
    - [`any.strict(isStrict)`](#anystrictisstrict)
    - [`any.default([value, [description]])`](#anydefaultvalue-description)
    - [`any.concat(schema)`](#anyconcatschema)
    - [`any.when(ref, options)`](#anywhenref-options)
    - [`any.label(name)`](#anylabelname)
    - [`any.raw(isRaw)`](#anyrawisraw)
    - [`any.empty(schema)`](#anyemptyschema)
  - [`array`](#array)
    - [`array.sparse(enabled)`](#arraysparseenabled)
    - [`array.single(enabled)`](#arraysingleenabled)
    - [`array.items(type)`](#arrayitemstype)
    - [`array.ordered(type)`](#arrayorderedtype)
    - [`array.min(limit)`](#arrayminlimit)
    - [`array.max(limit)`](#arraymaxlimit)
    - [`array.length(limit)`](#arraylengthlimit)
    - [`array.unique()`](#arrayunique)
  - [`boolean`](#boolean)
  - [`binary`](#binary)
    - [`binary.encoding(encoding)`](#binaryencodingencoding)
    - [`binary.min(limit)`](#binaryminlimit)
    - [`binary.max(limit)`](#binarymaxlimit)
    - [`binary.length(limit)`](#binarylengthlimit)
  - [`date`](#date)
    - [`date.min(date)`](#datemindate)
    - [`date.max(date)`](#datemaxdate)
    - [`date.format(format)`](#dateformatformat)
    - [`date.iso()`](#dateiso)
    - [`date.timestamp([type])`](#datetimestamptype)
  - [`func`](#func)
    - [`func.arity(n)`](#funcarityn)
    - [`func.minArity(n)`](#funcminarityn)
    - [`func.maxArity(n)`](#funcmaxarityn)
  - [`number`](#number)
    - [`number.min(limit)`](#numberminlimit)
    - [`number.max(limit)`](#numbermaxlimit)
    - [`number.greater(limit)`](#numbergreaterlimit)
    - [`number.less(limit)`](#numberlesslimit)
    - [`number.integer()`](#numberinteger)
    - [`number.precision(limit)`](#numberprecisionlimit)
    - [`number.multiple(base)`](#numbermultiplebase)
    - [`number.positive()`](#numberpositive)
    - [`number.negative()`](#numbernegative)
  - [`object`](#object)
    - [`object.keys([schema])`](#objectkeysschema)
      - [`{} notation`](#-notation)
      - [`Joi.object([schema]) notation`](#joiobjectschema-notation)
      - [`Joi.object().keys([schema]) notation`](#joiobjectkeysschema-notation)
    - [`object.min(limit)`](#objectminlimit)
    - [`object.max(limit)`](#objectmaxlimit)
    - [`object.length(limit)`](#objectlengthlimit)
    - [`object.pattern(regex, schema)`](#objectpatternregex-schema)
    - [`object.and(peers)`](#objectandpeers)
    - [`object.nand(peers)`](#objectnandpeers)
    - [`object.or(peers)`](#objectorpeers)
    - [`object.xor(peers)`](#objectxorpeers)
    - [`object.with(key, peers)`](#objectwithkey-peers)
    - [`object.without(key, peers)`](#objectwithoutkey-peers)
    - [`object.rename(from, to, [options])`](#objectrenamefrom-to-options)
    - [`object.assert(ref, schema, [message])`](#objectassertref-schema-message)
    - [`object.unknown([allow])`](#objectunknownallow)
    - [`object.type(constructor, [name])`](#objecttypeconstructor-name)
    - [`object.requiredKeys(children)`](#objectrequiredkeyschildren)
    - [`object.optionalKeys(children)`](#objectoptionalkeyschildren)
  - [`string`](#string)
    - [`string.insensitive()`](#stringinsensitive)
    - [`string.min(limit, [encoding])`](#stringminlimit-encoding)
    - [`string.max(limit, [encoding])`](#stringmaxlimit-encoding)
    - [`string.creditCard()`](#stringcreditcard)
    - [`string.length(limit, [encoding])`](#stringlengthlimit-encoding)
    - [`string.regex(pattern, [name])`](#stringregexpattern-name)
    - [`string.replace(pattern, replacement)`](#stringreplacepattern-replacement)
    - [`string.alphanum()`](#stringalphanum)
    - [`string.token()`](#stringtoken)
    - [`string.email([options])`](#stringemailoptions)
    - [`string.ip([options])`](#stringipoptions)
    - [`string.uri([options])`](#stringurioptions)
    - [`string.guid()`](#stringguid)
    - [`string.hex()`](#stringhex)
    - [`string.hostname()`](#stringhostname)
    - [`string.lowercase()`](#stringlowercase)
    - [`string.uppercase()`](#stringuppercase)
    - [`string.trim()`](#stringtrim)
    - [`string.isoDate()`](#stringisodate)
  - [`alternatives`](#alternatives)
    - [`alternatives.try(schemas)`](#alternativestryschemas)
    - [`alternatives.when(ref, options)`](#alternativeswhenref-options)
  - [`ref(key, [options])`](#refkey-options)
- [Errors](#errors)

<!-- tocstop -->

## Joi

### `validate(value, schema, [options], [callback])`

Validates a value using the given schema and options where:
- `value` - the value being validated.
- `schema` - the validation schema. Can be a **joi** type object or a plain object where every key is assigned a **joi** type object.
- `options` - an optional object with the following optional keys:
  - `abortEarly` - when `true`, stops validation on the first error, otherwise returns all the errors found. Defaults to `true`.
  - `convert` - when `true`, attempts to cast values to the required types (e.g. a string to a number). Defaults to `true`.
  - `allowUnknown` - when `true`, allows object to contain unknown keys which are ignored. Defaults to `false`.
  - `skipFunctions` - when `true`, ignores unknown keys with a function value. Defaults to `false`.
  - `stripUnknown` - when `true`, unknown keys are deleted (only when value is an object or an array). Defaults to `false`.
  - `language` - overrides individual error messages. Defaults to no override (`{}`). Messages apply the following rules :
    - variables are put between curly braces like `{{var}}`, if prefixed by a `!` like `{{!var}}`, it will be html escaped
    - strings are always preceeded by the key name, unless a `{{key}}` is found elsewhere or if the string is prefixed by a `!!`
    - when `'label'` is set, it overrides the key name in the error message
    - to better understand the structure of the language, it's advised to have a look at the existing messages you want to override [here](lib/language.js)
  - `presence` - sets the default presence requirements. Supported modes: `'optional'`, `'required'`, and `'forbidden'`.
    Defaults to `'optional'`.
  - `context` - provides an external data set to be used in [references](#refkey-options). Can only be set as an external option to
    `validate()` and not using `any.options()`.
  - `noDefaults` - when `true`, do not apply default values. Defaults to `false`.
- `callback` - the optional synchronous callback method using the signature `function(err, value)` where:
  - `err` - if validation failed, the [error](#errors) reason, otherwise `null`.
  - `value` - the validated value with any type conversions and other modifiers applied (the input is left unchanged). `value` can be
    incomplete if validation failed and `abortEarly` is `true`. If callback is not provided, then returns an object with [error](#errors)
    and value properties.

```javascript
const schema = {
{'fraction_non_alphanumeric': 0.20286779835390947, 'fraction_numerical': 0.00038580246913580245, 'mean_word_length': 4.517204682511529, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2022748', 'n_tokens_mistral': 5242, 'n_tokens_neox': 4932, 'n_words': 927}