( layout: Layout, contextName: string = "Layout" )
| 476 | * @throws Error if layout is invalid |
| 477 | */ |
| 478 | export function validateLayout( |
| 479 | layout: Layout, |
| 480 | contextName: string = "Layout" |
| 481 | ): void { |
| 482 | const requiredProps = ["x", "y", "w", "h"] as const; |
| 483 | |
| 484 | if (!Array.isArray(layout)) { |
| 485 | throw new Error(`${contextName} must be an array!`); |
| 486 | } |
| 487 | |
| 488 | for (let i = 0; i < layout.length; i++) { |
| 489 | const item = layout[i]; |
| 490 | if (item === undefined) continue; |
| 491 | |
| 492 | for (const key of requiredProps) { |
| 493 | const value = item[key]; |
| 494 | if (typeof value !== "number" || Number.isNaN(value)) { |
| 495 | throw new Error( |
| 496 | `ReactGridLayout: ${contextName}[${i}].${key} must be a number! ` + |
| 497 | `Received: ${String(value)} (${typeof value})` |
| 498 | ); |
| 499 | } |
| 500 | } |
| 501 | |
| 502 | if (item.i !== undefined && typeof item.i !== "string") { |
| 503 | throw new Error( |
| 504 | `ReactGridLayout: ${contextName}[${i}].i must be a string! ` + |
| 505 | `Received: ${String(item.i)} (${typeof item.i})` |
| 506 | ); |
| 507 | } |
| 508 | } |
| 509 | } |
no outgoing calls
no test coverage detected
searching dependent graphs…