(value, propName)
| 11 | * - Functions: shown as reference |
| 12 | */ |
| 13 | export function formatPropValue(value, propName) { |
| 14 | if (value === undefined || value === null) { |
| 15 | return null; |
| 16 | } |
| 17 | |
| 18 | const type = typeof value; |
| 19 | |
| 20 | if (type === 'string') { |
| 21 | return `"${value}"`; |
| 22 | } |
| 23 | |
| 24 | if (type === 'number') { |
| 25 | return `{${value}}`; |
| 26 | } |
| 27 | |
| 28 | if (type === 'boolean') { |
| 29 | return value ? '' : `{${value}}`; // true props can be just the prop name |
| 30 | } |
| 31 | |
| 32 | if (type === 'function') { |
| 33 | // Check if it's a named function |
| 34 | if (value.name && value.name !== 'anonymous') { |
| 35 | return `{${value.name}}`; |
| 36 | } |
| 37 | return `{handle${propName.charAt(0).toUpperCase() + propName.slice(1)}}`; |
| 38 | } |
| 39 | |
| 40 | if (Array.isArray(value)) { |
| 41 | return `{${JSON.stringify(value)}}`; |
| 42 | } |
| 43 | |
| 44 | if (type === 'object') { |
| 45 | return `{${JSON.stringify(value)}}`; |
| 46 | } |
| 47 | |
| 48 | return `{${value}}`; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Generates JSX props string from a props object. |
no outgoing calls
no test coverage detected