```typescript
/**
 * Flattens a nested array up to a specified depth level.
 *
 * @param items The input array with nested arrays.
 * @param depth The maximum depth level to flatten. Defaults to Infinity, which means every level is flattened.
 * @returns A new array with the nested arrays flattened up to the specified depth level.
 */
export function flatten(items: readonly unknown[], depth?: number): unknown[] {
    if (depth === undefined) {
        throw new Error('Depth must be a non-negative integer or Infinity');
    }

    const result = [];

    for (const item of items) {
        if (Array.isArray(item)) {
            if (depth > 0) {
                result.push(...flatten(item, depth - 1));
            } else {
                result.push(item);
            }
        } else {
            result.push(item);
        }
    }

    return result;
}
```