API Reference

Returns the provided array with a minimum and/or maximum length limit enforced. If the minimum length is larger than the length of the array, the fill will be added to the array as many times as necessary to reach the minimum limit. If a fill is provided, it must match the type of the array provided. If no fill is provided, undefined will be added. For min and max limits, you can pass false or 0 for a limit parameter to bypass.

function clampArray<T>(
  arr: T[],
  min: number | false,
  max: number | false,
  fill?: T
): T[]

// Example:

clampArray([1, 2, 3, 4, 5], 0, 3) //=> [1, 2, 3]

clampArray([1, 2, 3], 5, false, "x") //=> [1, 2, 3, "x", "x"]