(a, b, usedNames)
| 49 | * @returns {string} the common part and a single char for the difference |
| 50 | */ |
| 51 | const getName = (a, b, usedNames) => { |
| 52 | const l = Math.min(a.length, b.length); |
| 53 | let i = 0; |
| 54 | while (i < l) { |
| 55 | if (a.charCodeAt(i) !== b.charCodeAt(i)) { |
| 56 | i++; |
| 57 | break; |
| 58 | } |
| 59 | i++; |
| 60 | } |
| 61 | while (i < l) { |
| 62 | const name = a.slice(0, i); |
| 63 | const lowerName = name.toLowerCase(); |
| 64 | if (!usedNames.has(lowerName)) { |
| 65 | usedNames.add(lowerName); |
| 66 | return name; |
| 67 | } |
| 68 | i++; |
| 69 | } |
| 70 | // names always contain a hash, so this is always unique |
| 71 | // we don't need to check usedNames nor add it |
| 72 | return a; |
| 73 | }; |
| 74 | |
| 75 | /** @typedef {Record<string, number>} Sizes */ |
| 76 |
no test coverage detected