export function limitString(text: string) {
  return `${text.length > 100 ? `${text.slice(0, 100)}...` : text}`;
}

export function getRandomNumber(range: number): number {
  return Math.floor(Math.random() * range) + 1;
}

export function formatCurrency(num: number): string {
  return Intl.NumberFormat("en-US", {
    style: "currency",
    currency: "USD",

    // These options can be used to round to whole numbers.
    trailingZeroDisplay: "stripIfInteger", // This is probably what most people
    // want. It will only stop printing
    // the fraction when the input
    // amount is a round number (int)
    // already. If that's not what you
    // need, have a look at the options
    // below.
    //minimumFractionDigits: 0, // This suffices for whole numbers, but will
    // print 2500.10 as $2,500.1
    //maximumFractionDigits: 0, // Causes 2500.99 to be printed as $2,501
  }).format(num);
}

export function createSlug(val: string) {
  return val
    .replace(/ /g, "-")
    .replace(/[^\w-/]+/g, "")
    .toLowerCase();
}
