(obj: any, path: string)
| 136 | } |
| 137 | |
| 138 | export const customGet = (obj: any, path: string) => { |
| 139 | if (path.includes('[-1]')) { |
| 140 | const parts = path.split('.') |
| 141 | let result = obj |
| 142 | |
| 143 | for (let part of parts) { |
| 144 | if (part.includes('[') && part.includes(']')) { |
| 145 | const [name, indexPart] = part.split('[') |
| 146 | const index = parseInt(indexPart.replace(']', '')) |
| 147 | |
| 148 | result = result[name] |
| 149 | if (Array.isArray(result)) { |
| 150 | if (index < 0) { |
| 151 | result = result[result.length + index] |
| 152 | } else { |
| 153 | result = result[index] |
| 154 | } |
| 155 | } else { |
| 156 | return undefined |
| 157 | } |
| 158 | } else { |
| 159 | result = get(result, part) |
| 160 | } |
| 161 | |
| 162 | if (result === undefined) { |
| 163 | return undefined |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | return result |
| 168 | } else { |
| 169 | return get(obj, path) |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | export const convertStructuredSchemaToZod = (schema: string | object): ICommonObject => { |
| 174 | try { |
no test coverage detected