```ts
/**
 * Flattens an array up to a specified depth, defaulting to every level.
 * A string is considered a value, not something to iterate into.
 * A depth of 0 returns a copy of the input unchanged.
 * The input must not be mutated.
 * @param items - The array to flatten.
 * @param depth - The maximum depth to flatten. Default is Infinity.
 * @returns A new flattened array.
 */
export function flatten(items: readonly unknown[], depth?: number): unknown[] {
  if (depth === undefined) depth = Infinity;
  if (!Number.isInteger(depth) || depth < 0) throw new Error('Depth must be a non-negative integer or Infinity');

  return items.reduce((acc, item) => {
    if (Array.isArray(item) && depth > 0) {
      acc.push(...flatten(item, depth - 1));
    } else if (typeof item !== 'string') {
      acc.push(item);
    }
    return acc;
  }, [] as unknown[]);
}
```