| 1 | export const nameGenerator = ( |
| 2 | basename: string, |
| 3 | possibleOptions: Record<string, boolean>, |
| 4 | ) => { |
| 5 | const dotIndex = basename.lastIndexOf("."); |
| 6 | const filename = dotIndex === -1 ? basename : basename.substring(0, dotIndex); |
| 7 | const extension = dotIndex === -1 ? "" : basename.substring(dotIndex + 1); |
| 8 | |
| 9 | const selectedOptions = Object.keys(possibleOptions) |
| 10 | .filter((opt) => possibleOptions[opt]) |
| 11 | .map((opt) => opt.toLowerCase()) |
| 12 | .sort((a, b) => a.localeCompare(b, undefined, { sensitivity: "base" })); |
| 13 | |
| 14 | if (selectedOptions.length > 0) { |
| 15 | const suffix = ["-with", ...selectedOptions].join("-"); |
| 16 | return extension |
| 17 | ? `${filename}${suffix}.${extension}` |
| 18 | : `${filename}${suffix}`; |
| 19 | } |
| 20 | return basename; |
| 21 | }; |