* This method automatically checks if the prop is function or getter and behaves accordingly. * * @param object - The object to look up the getter function in its prototype chain. * @param prop - The property name for which to find the getter function. * @returns The getter function found in the
( object: T, prop: string )
| 258 | * @returns The getter function found in the prototype chain or a fallback function. |
| 259 | */ |
| 260 | function lookupGetter<T extends Record<string, any>>( |
| 261 | object: T, |
| 262 | prop: string |
| 263 | ): ReturnType<typeof unapply<any>> | (() => null) { |
| 264 | while (object !== null) { |
| 265 | const desc = getOwnPropertyDescriptor(object, prop); |
| 266 | |
| 267 | if (desc) { |
| 268 | if (desc.get) { |
| 269 | return unapply(desc.get); |
| 270 | } |
| 271 | |
| 272 | if (typeof desc.value === 'function') { |
| 273 | return unapply(desc.value); |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | object = getPrototypeOf(object); |
| 278 | } |
| 279 | |
| 280 | function fallbackValue(): null { |
| 281 | return null; |
| 282 | } |
| 283 | |
| 284 | return fallbackValue; |
| 285 | } |
| 286 | |
| 287 | function isRegex(value: unknown): value is RegExp { |
| 288 | try { |
no test coverage detected
searching dependent graphs…