```ts
export function flatten(items: readonly unknown[], depth = Infinity): unknown[] {
  // Check if input is null or undefined, if so return an empty array
  if (items === null || items === undefined) return [];

  // Create a new array to hold the flattened result
  const result: unknown[] = [];

  // Helper function to perform the recursive flattening
  function flattenHelper(item: unknown, currentDepth: number): void {
    // If the item is already an object or array, process it recursively
    if (Array.isArray(item) || isObject(item)) {
      for (const value of Array.isArray(item) ? item : Object.values(item)) {
        flattenHelper(value, currentDepth + 1);
      }
    } else {
      // If the depth allows and the item is not a string, add it to the result
      if (currentDepth < depth || typeof item !== 'string') {
        result.push(item);
      }
    }
  }

  // Start the recursive flattening from the input array
  flattenHelper(items, 0);

  return result;
}

// Function to check if an object is a regular JavaScript object (not a Set or Map)
function isObject(value: unknown): value is Record<string, unknown> {
  return typeof value === 'object' && value !== null && !Array.isArray(value);
}
```