(obj: Record<string, any>, rawPath: string, value?: any)
| 625 | * ``` |
| 626 | */ |
| 627 | export function getPlus(obj: Record<string, any>, rawPath: string, value?: any) { |
| 628 | const path = regex.test(rawPath) ? rawPath.substring(2, rawPath.length - 2) : rawPath; |
| 629 | const namePath = path.split('.'); |
| 630 | if (namePath.some((p) => p.includes('#'))) { |
| 631 | const idx = namePath.findIndex((p) => p.includes('#')); |
| 632 | const firstPath = namePath.slice(0, idx); |
| 633 | const [idxPath, idxHandler] = namePath[idx].split('#'); |
| 634 | const restPath = namePath.slice(idx + 1); |
| 635 | const rest = get(obj, firstPath); |
| 636 | const target = rest[idxPath][idxHandler]((item: any) => item.value === value); |
| 637 | return get(target, restPath); |
| 638 | } |
| 639 | |
| 640 | return get(obj, path); |
| 641 | } |
| 642 | |
| 643 | /** |
| 644 | * Convert nested object to form's name path |
no test coverage detected