(value: unknown)
| 173 | |
| 174 | /** Parses a JSON string safely, returning the original value if parsing fails. */ |
| 175 | export function parseJsonSafe<T = unknown>(value: unknown): T { |
| 176 | if (typeof value === 'string') { |
| 177 | /* v8 ignore next */ |
| 178 | try { |
| 179 | return JSON.parse(value); |
| 180 | } catch { |
| 181 | // ignore and return the value, as sometimes we get the parsed value, |
| 182 | // e.g. when it is a string value in JSON column |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | return value as T; |
| 187 | } |
| 188 | |
| 189 | /** Collection of general-purpose utility methods used throughout the ORM. */ |
| 190 | export class Utils { |
no outgoing calls
no test coverage detected