(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
object: { [key: string]: any },
// Default Node.js REPL depth
depth: number = 3,
// 100kB, as 200kB is max payload size, so half sounds reasonable
maxSize: number = 100 * 1024,
)
| 63 | |
| 64 | /** JSDoc */ |
| 65 | export function normalizeToSize<T>( |
| 66 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 67 | object: { [key: string]: any }, |
| 68 | // Default Node.js REPL depth |
| 69 | depth: number = 3, |
| 70 | // 100kB, as 200kB is max payload size, so half sounds reasonable |
| 71 | maxSize: number = 100 * 1024, |
| 72 | ): T { |
| 73 | const normalized = normalize(object, depth); |
| 74 | |
| 75 | if (jsonSize(normalized) > maxSize) { |
| 76 | return normalizeToSize(object, depth - 1, maxSize); |
| 77 | } |
| 78 | |
| 79 | return normalized as T; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Visits a node to perform normalization on it |
no test coverage detected