MCPcopy Create free account
hub / github.com/dfinity/orbit / fromResourceToDisplayText

Function fromResourceToDisplayText

apps/wallet/src/mappers/permissions.mapper.ts:94–121  ·  view source on GitHub ↗
(resource: Resource, separator = '_')

Source from the content-addressed store, hash-verified

92 * @returns The text representation of the resource action.
93 */
94export 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};

Callers 1

Calls 1

keysMethod · 0.80

Tested by

no test coverage detected