<commit_before>import {Container, inject} from 'aurelia-dependency-injection';
import {ArrayCollectionStrategy} from './array-collection-strategy';
import {MapCollectionStrategy} from './map-collection-strategy';
import {NumberStrategy} from './number-strategy';

@inject(Container)
export class CollectionStrategyLocator {
  constructor(container) {
    this.container = container;
  }

  getStrategy(items) {
    let strategy;
    if (items instanceof Array) {
      strategy = this.container.get(ArrayCollectionStrategy);
    } else if (items instanceof Map) {
      strategy = this.container.get(MapCollectionStrategy);
    } else if ((typeof items === 'number')) {
      strategy = this.container.get(NumberStrategy);
    } else {
      throw new Error('Object in "repeat" must be of type Array, Map or Number');
    }

    return strategy;
  }
}<commit_msg>feat(collection-strategy-locator): add strategies<commit_after>import {Container, inject} from 'aurelia-dependency-injection';
import {ArrayCollectionStrategy} from './array-collection-strategy';
import {MapCollectionStrategy} from './map-collection-strategy';
import {NumberStrategy} from './number-strategy';

@inject(Container)
export class CollectionStrategyLocator {
  constructor(container) {
    this.container = container;
    this.strategies = [];
    this.matchers = [];

    this.addStrategy(ArrayCollectionStrategy, items => items instanceof Array);
    this.addStrategy(MapCollectionStrategy, items => items instanceof Map);
    this.addStrategy(NumberStrategy, items => typeof items === 'number');
  }

  addStrategy(collectionStrategy: Function, matcher: (items: any) => boolean) {
    this.strategies.push(collectionStrategy);
    this.matchers.push(matcher);
  }

  getStrategy(items: any): CollectionStrategy {
    let matchers = this.matchers;

    for (let i = 0, ii = matchers.length; i < ii; ++i) {
      if (matchers[i](items)) {
        return this.container.get(this.strategies[i]);
      }
    }

    throw new Error('Object in "repeat" must have a valid collection strategy.');
  }
}
{'fraction_non_alphanumeric': 0.12542209358417752, 'fraction_numerical': 0.000482392667631452, 'mean_word_length': 4.290816326530612, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 7, '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': '650963', 'n_tokens_mistral': 578, 'n_tokens_neox': 568, 'n_words': 144}