@gameroom/cli
Version:
A command line tool for Gameroom
20 lines (18 loc) • 424 B
JavaScript
const { existsSync } = require('fs'),
{ extname } = require('path')
module.exports = (path) => {
let i = 0
while (existsSync(path)) {
// get extension
const ext = extname(path)
// remove extension
path = path.replace(ext, '')
// remove number
if (i) path = path.replace(`_${i}`, '')
// increment number
i++
// add number and ext
path = `${path}_${i}${ext}`
}
return path
}