<commit_before>/* @flow */

import Type from './Type';

import type Validation, {IdentifierPath} from '../Validation';

export default class ObjectTypeIndexer<K: string | number, V> extends Type {
  typeName: string = 'ObjectTypeIndexer';
  id: string;
  key: Type<K>;
  value: Type<V>;

  collectErrors (validation: Validation<any>, path: IdentifierPath, key: any, value: any): boolean {
    let hasErrors = this.key.collectErrors(validation, path.concat('[[Key]]'), key);
    if (this.value.collectErrors(validation, path.concat(key), value)) {
      hasErrors = true;
    }
    return hasErrors;
  }

  accepts (value: any): boolean {
    return this.value.accepts(value);
  }

  acceptsKey (key: any): boolean {
    return this.key.accepts(key);
  }

  acceptsValue (value: any): boolean {
    return this.value.accepts(value);
  }

  acceptsType (input: Type<any>): boolean {<commit_msg>special case numbers in indexer keys<commit_after>/* @flow */

import Type from './Type';

import type Validation, {IdentifierPath} from '../Validation';

export default class ObjectTypeIndexer<K: string | number, V> extends Type {
  typeName: string = 'ObjectTypeIndexer';
  id: string;
  key: Type<K>;
  value: Type<V>;

  collectErrors (validation: Validation<any>, path: IdentifierPath, key: any, value: any): boolean {
    // special case number types
    if (this.key.typeName === 'NumberType' || this.key.typeName === 'NumericLiteralType') {
      key = +key;
    }
    let hasErrors = this.key.collectErrors(validation, path.concat('[[Key]]'), key);
    if (this.value.collectErrors(validation, path.concat(key), value)) {
      hasErrors = true;
    }
    return hasErrors;
  }

  accepts (value: any): boolean {
    return this.value.accepts(value);
  }

  acceptsKey (key: any): boolean {
    // special case number types
    if (this.key.typeName === 'NumberType' || this.key.typeName === 'NumericLiteralType') {
      key = +key;
    }
    return this.key.accepts(key);
  }

  acceptsValue (value: any): boolean {
    return this.value.accepts(value);
  }

  acceptsType (input: Type<any>): boolean {
{'fraction_non_alphanumeric': 0.14726840855106887, 'fraction_numerical': 0.0, 'mean_word_length': 3.7219730941704037, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '6982136', 'n_tokens_mistral': 663, 'n_tokens_neox': 656, 'n_words': 177}