<commit_before>// ==========================================================================
// String utils
// ==========================================================================

import is from './is';

// Generate a random ID
export function generateId(prefix) {
  return `${prefix}-${Math.floor(Math.random() * 10000)}`;
}

// Format string
export function format(input, ...args) {
  if (is.empty(input)) {
    return input;
  }

  return input.toString().replace(/{(\d+)}/g, (match, i) => args[i].toString());
}

// Get percentage
export function getPercentage(current, max) {
  if (current === 0 || max === 0 || Number.isNaN(current) || Number.isNaN(max)) {
    return 0;
  }

  return ((current / max) * 100).toFixed(2);
}

// Replace all occurances of a string in a string
export const replaceAll = (input = '', find = '', replace = '') =>
  input.replace(new RegExp(find.toString().replace(/([.*+?^=!:${}()|[\]/\\])/g, '\\$1'), 'g'), replace.toString());

// Convert to title case
export const toTitleCase = (input = '') =>
  input.toString().replace(/\w\S*/g, (text) => text.charAt(0).toUpperCase() + text.slice(1).toLowerCase());

// Convert string to pascalCase
export function toPascalCase(input = '') {<commit_msg>chore: fix typo in comment<commit_after>// ==========================================================================
// String utils
// ==========================================================================

import is from './is';

// Generate a random ID
export function generateId(prefix) {
  return `${prefix}-${Math.floor(Math.random() * 10000)}`;
}

// Format string
export function format(input, ...args) {
  if (is.empty(input)) return input;

  return input.toString().replace(/{(\d+)}/g, (match, i) => args[i].toString());
}

// Get percentage
export function getPercentage(current, max) {
  if (current === 0 || max === 0 || Number.isNaN(current) || Number.isNaN(max)) {
    return 0;
  }

  return ((current / max) * 100).toFixed(2);
}

// Replace all occurrences of a string in a string
export const replaceAll = (input = '', find = '', replace = '') =>
  input.replace(new RegExp(find.toString().replace(/([.*+?^=!:${}()|[\]/\\])/g, '\\$1'), 'g'), replace.toString());

// Convert to title case
export const toTitleCase = (input = '') =>
  input.toString().replace(/\w\S*/g, (text) => text.charAt(0).toUpperCase() + text.slice(1).toLowerCase());

// Convert string to pascalCase
export function toPascalCase(input = '') {
{'fraction_non_alphanumeric': 0.3116410670978173, 'fraction_numerical': 0.012126111560226353, 'mean_word_length': 4.415754923413567, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3675951', 'n_tokens_mistral': 769, 'n_tokens_neox': 724, 'n_words': 184}