(obj, byProperty, ...values)
| 658 | * @returns {Omit<T, P>} object with merged byProperty |
| 659 | */ |
| 660 | const resolveByProperty = (obj, byProperty, ...values) => { |
| 661 | if (typeof obj !== "object" || obj === null || !(byProperty in obj)) { |
| 662 | return obj; |
| 663 | } |
| 664 | const { [byProperty]: _byValue, ..._remaining } = obj; |
| 665 | const remaining = /** @type {T} */ (_remaining); |
| 666 | const byValue = |
| 667 | /** @type {Record<string, T> | ((...args: V[]) => T)} */ |
| 668 | (_byValue); |
| 669 | if (typeof byValue === "object") { |
| 670 | const key = /** @type {string} */ (values[0]); |
| 671 | if (key in byValue) { |
| 672 | return cachedCleverMerge(remaining, byValue[key]); |
| 673 | } else if ("default" in byValue) { |
| 674 | return cachedCleverMerge(remaining, byValue.default); |
| 675 | } |
| 676 | return remaining; |
| 677 | } else if (typeof byValue === "function") { |
| 678 | // eslint-disable-next-line prefer-spread |
| 679 | const result = byValue.apply(null, values); |
| 680 | return cachedCleverMerge( |
| 681 | remaining, |
| 682 | resolveByProperty(result, byProperty, ...values) |
| 683 | ); |
| 684 | } |
| 685 | return obj; |
| 686 | }; |
| 687 | |
| 688 | module.exports.DELETE = DELETE; |
| 689 | module.exports.cachedCleverMerge = cachedCleverMerge; |
no test coverage detected