```typescript
/**
 * Returns a new array with nested arrays flattened up to depth levels,
 * defaulting to every level. A string is a value, never something to iterate into,
 * no matter how deep it appears. A depth of 0 returns a copy of the input unchanged.
 *
 * @param items The input array containing nested arrays
 * @param depth The maximum recursion depth, or Infinity for any level
 */
export function flatten(items: readonly unknown[], depth?: number): unknown[] {
    if (depth === undefined) {
        throw new Error('Invalid argument: "depth" must be a non-negative integer');
    } else if (depth < 0) {
        throw new Error('Invalid argument: "depth" must be a non-negative integer');
    }

    const result = [];
    for (const item of items) {
        if (Array.isArray(item)) {
            if (depth === 0 || depth > 1) {
                // Recursively flatten the array
                result.push(...flatten(item, Math.max(0, depth - 1)));
            }
        } else if (typeof item !== 'string') {
            // If the value is not a string or an array, add it to the result
            result.push(item);
        }
    }

    return result;
}
```