(resource: Resource, separator = '_')
| 92 | * @returns The text representation of the resource action. |
| 93 | */ |
| 94 | export const fromResourceToDisplayText = (resource: Resource, separator = '_'): string => { |
| 95 | const keys = Object.keys(resource); |
| 96 | if (keys.length === 0) { |
| 97 | return ''; |
| 98 | } |
| 99 | |
| 100 | let displayText = ''; |
| 101 | |
| 102 | for (const key of keys) { |
| 103 | displayText += displayText.length ? separator + key : key; |
| 104 | const resourceKey = key as keyof Resource; |
| 105 | |
| 106 | // also check if resource is an object and not null |
| 107 | if ( |
| 108 | typeof resource[resourceKey] === 'object' && |
| 109 | resource[resourceKey] !== null && |
| 110 | !Array.isArray(resource[resourceKey]) |
| 111 | ) { |
| 112 | const actionValue = fromResourceToDisplayText(resource[resourceKey]); |
| 113 | |
| 114 | if (actionValue?.length) { |
| 115 | displayText += separator + actionValue; |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | return displayText.toLowerCase(); |
| 121 | }; |
no test coverage detected