(entities: { keyRaw: string }[])
| 622 | * @param entities |
| 623 | */ |
| 624 | export const fixEntityListCasesInplace = (entities: { keyRaw: string }[]) => { |
| 625 | entities.sort((a, b) => a.keyRaw.length - b.keyRaw.length); |
| 626 | // console.log(JSON.stringify(entities,null,2)); |
| 627 | |
| 628 | const caseMapping: Record<string, string> = { "": "" }; |
| 629 | for (const e of entities) { |
| 630 | // console.log(`looking for: ${JSON.stringify(e, null, 2)}`); |
| 631 | |
| 632 | let parentFolder = getParentFolder(e.keyRaw); |
| 633 | if (parentFolder === "/") { |
| 634 | parentFolder = ""; |
| 635 | } |
| 636 | const parentFolderLower = parentFolder.toLocaleLowerCase(); |
| 637 | const segs = e.keyRaw.split("/"); |
| 638 | if (e.keyRaw.endsWith("/")) { |
| 639 | // folder |
| 640 | if (caseMapping.hasOwnProperty(parentFolderLower)) { |
| 641 | const newKeyRaw = `${caseMapping[parentFolderLower]}${segs |
| 642 | .slice(-2) |
| 643 | .join("/")}`; |
| 644 | caseMapping[newKeyRaw.toLocaleLowerCase()] = newKeyRaw; |
| 645 | e.keyRaw = newKeyRaw; |
| 646 | // console.log(JSON.stringify(caseMapping,null,2)); |
| 647 | } else { |
| 648 | throw Error(`${parentFolder} doesn't have cases record??`); |
| 649 | } |
| 650 | } else { |
| 651 | // file |
| 652 | if (caseMapping.hasOwnProperty(parentFolderLower)) { |
| 653 | const newKeyRaw = `${caseMapping[parentFolderLower]}${segs |
| 654 | .slice(-1) |
| 655 | .join("/")}`; |
| 656 | e.keyRaw = newKeyRaw; |
| 657 | } else { |
| 658 | throw Error(`${parentFolder} doesn't have cases record??`); |
| 659 | } |
| 660 | } |
| 661 | } |
| 662 | |
| 663 | return entities; |
| 664 | }; |
| 665 | |
| 666 | /** |
| 667 | * https://stackoverflow.com/questions/1248302/how-to-get-the-size-of-a-javascript-object |
nothing calls this directly
no test coverage detected