<commit_before>/*
 * @adonisjs/core
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

import { RequestConstructorContract } from '@adonisjs/request'
import { FileValidationOptions, MultipartFileContract } from '@adonisjs/bodyparser'

export function requestBindings (Request: RequestConstructorContract) {
  Request.macro('file', function getFile (key: string, options: FileValidationOptions) {
    const file = this._files[key]
    if (!file) {
      return null
    }

    if (options) {
      if (file instanceof Array) {
        (file as MultipartFileContract[]).forEach((one) => one.setValidationOptions(options))
      } else {
        (file as MultipartFileContract).setValidationOptions(options)
      }
    }

    return file
  })
}<commit_msg>style(core): add docblock<commit_after>/*
 * @adonisjs/core
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

import { RequestConstructorContract } from '@adonisjs/request'
import { FileValidationOptions, MultipartFileContract } from '@adonisjs/bodyparser'

/**
 * Adds `file` macro the request object to read uploaded files
 */
export function requestBindings (Request: RequestConstructorContract) {
  Request.macro('file', function getFile (key: string, options: FileValidationOptions) {
    const file = this._files[key]
    if (!file) {
      return null
    }

    if (options) {
      if (file instanceof Array) {
        (file as MultipartFileContract[]).forEach((one) => one.setValidationOptions(options))
      } else {
        (file as MultipartFileContract).setValidationOptions(options)
      }
    }

    return file
  })
}
{'fraction_non_alphanumeric': 0.10976282404853833, 'fraction_numerical': 0.0, 'mean_word_length': 3.7239583333333335, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, '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': '509176', 'n_tokens_mistral': 511, 'n_tokens_neox': 502, 'n_words': 148}