code cleanup

This commit is contained in:
olcxja 2026-09-26 10:13:50 +02:00
commit e8cd664965
8 changed files with 362 additions and 406 deletions

15
src/fsutil.js Normal file
View file

@ -0,0 +1,15 @@
'use strict'
const fs = require('fs')
const path = require('path')
// Returns a non-existing path in `base` named `name` (or `name (2)`, `name (3)`...).
function dedupeDir(base, name) {
const candidate = path.join(base, name)
if (!fs.existsSync(candidate)) return candidate
let n = 2
while (fs.existsSync(path.join(base, `${name} (${n})`))) n++
return path.join(base, `${name} (${n})`)
}
module.exports = { dedupeDir }