<commit_before>import { Faker } from '../faker';
import data from '../../data/commerce.json';

function buildCategories(faker, num) {
  const categories = [];
  while (categories.length < num) {
    const category = faker.Random.element(data.departments);
    if (categories.indexOf(category) < 0) {
      categories.push(category);
    }
  }
  return categories;
}

function mergeCategories(categories) {
  const separator = ' & ';
  const commaSeparated = categories.slice(0, -1).join(', ');
  const lastCategory = categories.slice(-1);
  return [commaSeparated, lastCategory].join(separator);
}

export class Commerce {
  private faker: Faker;

  constructor(faker: Faker) {
    this.faker = faker;
  }

  color() {
    return this.faker.Color.colorName();
  }

  department(max = 3, fixedAmount = false) {
    const num = fixedAmount ? max : this.faker.Number.between(1, max);
    const categories = buildCategories(this.faker, num);
    return num > 1 ? mergeCategories(categories) : categories[0];
  }

  productName() {
    return [
      this.faker.Random.element(data.productNames.adjective),
      this.faker.Random.element(data.productNames.material),
      this.faker.Random.element(data.productNames.product),
    ].join(' ');
  }

  price(range = { min: 0.0, max: 100.0 }) {
    const n = this.faker.Number.between(range.min, range.max);
    return (Math.floor(n * 100) / 100.0).toFixed(2);
  }

  promotionCode(digits = 6) {
    return [
      this.faker.Random.element(data.promotionCodes.adjective),
      this.faker.Random.element(data.promotionCodes.noun),
      this.faker.Number.number(digits),
    ].join('');
  }
}
<commit_msg>Updated the Commerce faker.<commit_after>import { Faker } from '../faker';
import data from '../../data/commerce.json';

function buildCategories(faker, num) {
  const categories = [];
  while (categories.length < num) {
    const category = faker.Random.element(data.departments);
    if (categories.indexOf(category) < 0) {
      categories.push(category);
    }
  }
  return categories;
}

function mergeCategories(categories) {
  const separator = ' & ';
  const commaSeparated = categories.slice(0, -1).join(', ');
  const lastCategory = categories.slice(-1);
  return [commaSeparated, lastCategory].join(separator);
}

export class Commerce {
  private faker: Faker;

  constructor(faker: Faker) {
    this.faker = faker;
  }

  color(): string {
    return this.faker.Color.colorName();
  }

  department(max: number = 3, fixedAmount: boolean = false): string {
    const num = fixedAmount ? max : this.faker.Number.between(1, max);
    const categories = buildCategories(this.faker, num);
    return num > 1 ? mergeCategories(categories) : categories[0];
  }

  productName(): string {
    return [
      this.faker.Random.element(data.productNames.adjective),
      this.faker.Random.element(data.productNames.material),
      this.faker.Random.element(data.productNames.product),
    ].join(' ');
  }

  price(range = { min: 0.0, max: 100.0 }): string {
    const n = this.faker.Number.between(range.min, range.max);
    return (Math.floor(n * 100) / 100.0).toFixed(2);
  }

  promotionCode(digits: number = 6): string {
    return [
      this.faker.Random.element(data.promotionCodes.adjective),
      this.faker.Random.element(data.promotionCodes.noun),
      this.faker.Number.number(digits),
    ].join('');
  }
}

{'fraction_non_alphanumeric': 0.150636282923942, 'fraction_numerical': 0.01361349511689849, 'mean_word_length': 3.4415243101182655, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '1267544', 'n_tokens_mistral': 1149, 'n_tokens_neox': 1094, 'n_words': 205}