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

    const result = [];

    for (const item of items) {
        if ('length' in item && item.length > 0) { // Array
            if (!depth || depth === 0) {
                result.push(item);
            } else if (typeof item[0] !== 'string') {
                result.push(...flatten(item, Math.max(0, depth - 1)));
            }
        } else if ('size' in item && Number.isInteger(item.size)) { // Map
            for (const [key, value] of Object.entries(item)) {
                if (!depth || depth === 0) {
                    result.push([key, value]);
                } else if (typeof value !== 'string') {
                    result.push(...flatten(Array.from(value.values()), Math.max(0, depth - 1)));
                }
            }
        } else { // Object
            for (const [key, value] of Object.entries(item)) {
                if (!depth || depth === 0) {
                    result.push([key, value]);
                } else if (typeof value !== 'string') {
                    result.push(...flatten(Object.values(value), Math.max(0, depth - 1)));
                }
            }
        }
    }

    return result;
}
```