mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2026-10-27 02:27:18 +00:00
progress
This commit is contained in:
1 parent
ec448b72e2
commit
7651d859c4
9 files changed
+325
-341
No files matched your search
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* The name of a new file: the default name (translated), followed by a number when other files
|
||||
* already have a default name (the name alone counts as number 1): "New file", "New file 2",
|
||||
* "New file 3"...
|
||||
*/
|
||||
export function defaultFileName(defaultName: string, existingNames: string[]): string {
|
||||
let highest = 0;
|
||||
for (const name of existingNames) {
|
||||
if (name === defaultName) {
|
||||
highest = Math.max(highest, 1);
|
||||
} else if (name.startsWith(`${defaultName} `)) {
|
||||
const suffix = name.slice(defaultName.length + 1);
|
||||
if (/^[1-9][0-9]*$/.test(suffix)) {
|
||||
highest = Math.max(highest, parseInt(suffix));
|
||||
}
|
||||
}
|
||||
}
|
||||
return highest === 0 ? defaultName : `${defaultName} ${highest + 1}`;
|
||||
}
|
||||
Reference in new issue
Block a user