( map: Map<string, string>, unmakePathString: (str: string) => ReadonlyArray<string>, makePathString: (chunk: ReadonlyArray<string>) => string )
| 654 | } |
| 655 | |
| 656 | const splitIndexInKeys = ( |
| 657 | map: Map<string, string>, |
| 658 | unmakePathString: (str: string) => ReadonlyArray<string>, |
| 659 | makePathString: (chunk: ReadonlyArray<string>) => string |
| 660 | ): Map<string, string> => { |
| 661 | const newMap: Map<string, string> = new Map() |
| 662 | for (const [pathString, value] of map) { |
| 663 | const keyWithIndex = pipe( |
| 664 | unmakePathString(pathString), |
| 665 | Arr.flatMap((key) => |
| 666 | Option.match(splitIndexFrom(key), { |
| 667 | onNone: () => Arr.of(key), |
| 668 | onSome: ([key, index]) => Arr.make(key, `[${index}]`) |
| 669 | }) |
| 670 | ) |
| 671 | ) |
| 672 | newMap.set(makePathString(keyWithIndex), value) |
| 673 | } |
| 674 | return newMap |
| 675 | } |
| 676 | |
| 677 | const splitIndexFrom = (key: string): Option.Option<[string, number]> => { |
| 678 | const match = key.match(STR_INDEX_REGEX) |
no test coverage detected
searching dependent graphs…